rowvia 0.3.3 → 0.3.5

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.
Files changed (45) hide show
  1. package/dist/fields.css +1 -1
  2. package/dist/fields.es.js +1167 -1104
  3. package/dist/fields.umd.cjs +1 -1
  4. package/dist/rowvia.css +1 -1
  5. package/dist/rowvia.es.js +5834 -4698
  6. package/dist/rowvia.umd.cjs +71 -55
  7. package/dist/types/components/scrollbars.d.ts +11 -3
  8. package/dist/types/components/table-cell-content.d.ts +9 -0
  9. package/dist/types/components/table-groups.d.ts +32 -0
  10. package/dist/types/components/table-headers.d.ts +11 -0
  11. package/dist/types/components/table-inline-editor.d.ts +13 -0
  12. package/dist/types/components/table-popup.d.ts +3 -0
  13. package/dist/types/components/table-presentation.d.ts +14 -0
  14. package/dist/types/components/table-text-editor.d.ts +29 -0
  15. package/dist/types/conditions/index.d.ts +12 -0
  16. package/dist/types/contracts/work-item.d.ts +1 -1
  17. package/dist/types/fields/internal/anchored-popup.d.ts +23 -0
  18. package/dist/types/fields/popup.d.ts +7 -9
  19. package/dist/types/fields/types.d.ts +3 -0
  20. package/dist/types/index.d.ts +1 -0
  21. package/dist/types/vue/DualPanePicker.d.ts +211 -0
  22. package/dist/types/vue/controls.d.ts +3961 -0
  23. package/dist/types/vue/index.d.ts +6 -0
  24. package/dist/types/vue/registry.d.ts +10 -0
  25. package/dist/types/vue-conditions/ConditionGroup.d.ts +120 -0
  26. package/dist/types/vue-conditions/ConditionRow.d.ts +94 -0
  27. package/dist/types/vue-conditions/ConditionValue.d.ts +56 -0
  28. package/dist/types/vue-conditions/controls.d.ts +12 -0
  29. package/dist/types/vue-conditions/index.d.ts +6 -0
  30. package/dist/types/work-items/index.d.ts +13 -1
  31. package/dist/types/work-items/tool-field-picker.d.ts +14 -0
  32. package/dist/types/work-items/tool-filter.d.ts +14 -0
  33. package/dist/types/work-items/tool-icons.d.ts +1 -0
  34. package/dist/types/work-items/tool-panel.d.ts +17 -0
  35. package/dist/types/work-items/tool-state.d.ts +21 -0
  36. package/dist/types/work-items/toolbar.d.ts +10 -2
  37. package/dist/types/work-items/views/rule-panels.d.ts +2 -0
  38. package/dist/types/work-items/workflow-detail-types.d.ts +20 -0
  39. package/dist/types/work-items/workflow-field-popups.d.ts +4 -0
  40. package/dist/types/work-items/workflow-legend.d.ts +16 -0
  41. package/dist/types/work-items/workflow-presentation.d.ts +3 -0
  42. package/dist/vue.css +1 -0
  43. package/dist/vue.es.js +631 -0
  44. package/dist/vue.umd.cjs +1 -0
  45. package/package.json +27 -7
@@ -1 +1 @@
1
- (function(V,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(V=typeof globalThis<"u"?globalThis:V||self,G(V.RowviaFields={}))})(this,function(V){"use strict";var Pt=Object.defineProperty;var $t=(V,G,re)=>G in V?Pt(V,G,{enumerable:!0,configurable:!0,writable:!0,value:re}):V[G]=re;var _=(V,G,re)=>$t(V,typeof G!="symbol"?G+"":G,re);class G{constructor(){_(this,"cleanups",new Set);_(this,"stopped",!1)}get destroyed(){return this.stopped}add(e){return this.stopped?e():this.cleanups.add(e),()=>{this.cleanups.delete(e)&&e()}}listen(e,n,i,o){return e.addEventListener(n,i,o),this.add(()=>e.removeEventListener(n,i,o))}timeout(e,n){if(this.stopped)return 0;const i=window.setTimeout(()=>{o(),this.stopped||e()},n),o=this.add(()=>window.clearTimeout(i));return i}interval(e,n){if(this.stopped)return 0;const i=window.setInterval(()=>{this.stopped||e()},n);return this.add(()=>window.clearInterval(i)),i}destroy(){if(this.stopped)return;this.stopped=!0;const e=[...this.cleanups].reverse();this.cleanups.clear();let n;for(const i of e)try{i()}catch(o){n??(n=o)}if(n!==void 0)throw n}}function re(t,e,n={},i=[]){const o=new G,a=new Set,s=p=>[...a].some(b=>b.contains(p)),c=new Set,u=new WeakMap,f=p=>{const b=p.target;if(!(b!=null&&b.closest))return;const h=b.closest('button,input,select,textarea,a,[data-action],[contenteditable],[role="button"],[role="tab"],[data-node-id],[data-rowid],[data-viewport],canvas');if(!h||!s(h))return;const E={};for(let m=h;m&&s(m);m=m.parentElement)for(const[L,R]of Object.entries(m.dataset))R!==void 0&&!(L in E)&&(E[L]=R);const M=h;u.has(p)||(u.set(p,{component:e,type:p.type,action:E.action??E.control,value:"value"in h?M.value:void 0,checked:M.type==="checkbox"||M.type==="radio"?M.checked:void 0,data:E,originalEvent:p}),queueMicrotask(()=>y(p)))},y=p=>{var E;const b=u.get(p);if(!b||o.destroyed)return;u.delete(p),(E=n.onInteraction)==null||E.call(n,b);for(const M of[...c])M(b);const h=t.ownerDocument.defaultView.CustomEvent;t.dispatchEvent(new h("rowvia:interaction",{detail:b,bubbles:!0}))},T=p=>{if(o.destroyed||a.has(p))return()=>{};a.add(p);const b=[];for(const h of["click","dblclick","contextmenu","input","change","submit","keydown","pointerdown","pointerup","wheel"])b.push(o.listen(p,h,f,{capture:!0,passive:!0}));return()=>{a.delete(p),b.forEach(h=>h())}};for(const p of[t,...i])T(p);return{addRoot:T,onInteraction(p){return o.destroyed?()=>{}:(c.add(p),()=>{c.delete(p)})},destroy(){o.destroy(),c.clear(),a.clear()}}}const le=new Map;function ve(t,e){if(!t)return!1;const n=e?[e]:[],i=new Set;for(let o=0;o<Math.max(1,n.length);o++)for(const[a,s]of le)if(!(i.has(a)||e&&!n[o].contains(s))){if(a.element.contains(t))return!0;i.add(a),n.push(a.element)}return!1}function Pe(t){for(const[e,n]of[...le])(!t||t.contains(n))&&e.close()}function de(t){const{anchor:e,content:n,width:i="anchor",gap:o=4,onDismiss:a}=t,s=e.ownerDocument,c=s.defaultView||window,u=t.anchorMode==="element"?e:e.closest(".fc-focus-body")||e,f=s.createElement("div");f.className="rowvia-field-scope rowvia-field-popup-layer";const y=s.createElement("div");y.className="rowvia-field-popup",y.append(n),f.append(y),(e.closest("dialog[open]")||s.body||s.documentElement).append(f);let T=!1;const p=()=>{if(T||!f.isConnected)return;const m=u.getBoundingClientRect(),L=s.documentElement.clientWidth||c.innerWidth,R=s.documentElement.clientHeight||c.innerHeight,F=i==="anchor"?m.width+2:i==="auto"?y.getBoundingClientRect().width:i;y.style.width=i==="auto"?"max-content":F+"px";const A=y.getBoundingClientRect().height;let C=m.bottom+o;const N=m.top-o-A;C+A>R-8&&N>=8&&(C=N),C=Math.max(8,Math.min(C,Math.max(8,R-A-8)));const x=Math.max(8,Math.min(t.align==="end"?m.right-F:m.left,Math.max(8,L-F-8)));f.style.top=Math.round(C)+"px",f.style.left=Math.round(x)+"px"},b=()=>{T||(T=!0,Pe(f),le.delete(M),s.removeEventListener("pointerdown",h,!0),s.removeEventListener("keydown",E,!0),c.removeEventListener("resize",p),c.removeEventListener("scroll",p,!0),f.remove(),a==null||a())},h=m=>{const L=m.target;L&&(f.contains(L)||u.contains(L)||e.contains(L)||ve(L,f))||b()},E=m=>{if(m.key!=="Escape"||[...le.keys()][le.size-1]!==M)return;if(m.preventDefault(),m.stopPropagation(),b(),t.onEscape){t.onEscape();return}const L=s.defaultView.CustomEvent;e.dispatchEvent(new L("fc-collapse",{bubbles:!0,detail:{reason:"escape"}}))},M={element:f,reposition:p,close:b};return le.set(M,e),s.addEventListener("pointerdown",h,!0),s.addEventListener("keydown",E,!0),c.addEventListener("resize",p),c.addEventListener("scroll",p,!0),p(),M}const ke=new WeakMap;function bt(t,e){let n=ke.get(t);if(!n){const o=new Set,a=s=>{for(const c of[...o])o.has(c)&&!c.contains(s.target,s)&&c.leave(s)};t.addEventListener("pointerdown",a,!0),t.addEventListener("focusin",a,!0),n={boundaries:o,stop:()=>{t.removeEventListener("pointerdown",a,!0),t.removeEventListener("focusin",a,!0)}},ke.set(t,n)}n.boundaries.add(e);const i=n;return()=>{!i.boundaries.delete(e)||i.boundaries.size||(i.stop(),ke.delete(t))}}class J{constructor(e){_(this,"root");_(this,"destroying",!1);_(this,"feedback");_(this,"options");_(this,"value");_(this,"committedValue");_(this,"state");_(this,"view");_(this,"viewLife",new G);_(this,"life",new G);_(this,"listeners",new Set);_(this,"interactions");_(this,"interactionListeners",new Set);_(this,"mounted",!1);_(this,"handled",new WeakSet);this.options={...e},this.value=e.value,this.committedValue=e.value,this.state=e.readonly||e.canEdit===!1?"display":e.state??"display"}get element(){if(this.root)return this.root;const e=document.createElement("div");return e.className="rowvia-field",e.tabIndex=0,e.setAttribute("aria-label",this.options.field.label),this.root=e,e}bindRoot(){this.life.listen(this.element,"pointerenter",()=>{this.state==="display"&&this.setState("hover","user")}),this.life.listen(this.element,"pointerleave",()=>{this.state==="hover"&&this.setState("display","user")}),this.life.listen(this.element,"click",e=>{e.target.closest("button,a,input,textarea,select,[contenteditable]")||this.edit("user")}),this.life.listen(this.element,"keydown",e=>{const n=e.key;n==="Escape"&&this.state==="editing"?(e.preventDefault(),this.cancel("user")):(n==="Enter"||n===" ")&&this.state!=="editing"&&e.target===this.element&&(e.preventDefault(),this.edit("user"))}),this.life.listen(this.element,"fc-collapse",e=>{var n;((n=e.detail)==null?void 0:n.reason)==="escape"?this.cancel("user"):this.commit("user")}),this.life.listen(this.element,"focusout",()=>{queueMicrotask(()=>{var n,i;if(this.life.destroyed||!this.element.isConnected||this.state!=="editing")return;const e=this.element.ownerDocument.activeElement;this.element.contains(e)||(i=(n=this.view)==null?void 0:n.content)!=null&&i.contains(e)||ve(e,this.element)||this.commit("user")})})}renderHover(e){return this.renderDisplay(e)}beforeInput(e){return e}beforeCommit(e){return!0}beforeCancel(e){return!0}beforeStateChange(e){return!0}validateValue(e){}isReadonly(){return!!this.options.readonly||this.options.canEdit===!1||this.options.field.editable===!1}onOutput(e){}get snapshot(){return{key:this.options.field.key,value:this.read(),committedValue:this.committedValue,state:this.state,readonly:this.isReadonly()}}mount(e){if(this.life.destroyed)throw new Error("Cannot mount a destroyed field");return this.mounted||(this.mounted=!0,this.bindRoot(),this.draw()),e==null||e.append(this.element),this}read(){var e;return this.state==="editing"&&((e=this.view)!=null&&e.read)?this.view.read():this.value}on(e){return this.life.destroyed?()=>{}:(this.listeners.add(e),()=>{this.listeners.delete(e)})}onInteraction(e){return this.life.destroyed?()=>{}:(this.interactionListeners.add(e),()=>{this.interactionListeners.delete(e)})}input(e,n="api",i){var c;if(this.life.destroyed||this.snapshot.readonly)return;const o=this.value,a=this.snapshot,s=this.beforeInput(e);this.value=(c=this.options.hooks)!=null&&c.beforeInput?this.options.hooks.beforeInput(s,a):s,(n==="api"||!Object.is(e,this.value))&&this.draw(),this.emit("input",n,{previousValue:o,originalEvent:i})}setValue(e){if(this.life.destroyed)return;const n=this.read();this.value=e,this.committedValue=e,this.draw(),this.emit("change","api",{previousValue:n})}update(e){this.life.destroyed||(this.value=this.read(),this.options={...this.options,...e},"value"in e&&(this.value=this.committedValue=e.value),e.state&&(this.state=e.state),this.isReadonly()&&(this.state="display"),this.draw())}validate(){var i,o,a,s;const e=this.read(),n=e==null||e===""||Array.isArray(e)&&e.length===0;return(this.options.field.required&&n?"此项必填":void 0)||this.validateValue(e)||((o=(i=this.view)==null?void 0:i.validate)==null?void 0:o.call(i))||((s=(a=this.options.hooks)==null?void 0:a.validate)==null?void 0:s.call(a,e))}commit(e="api"){var o,a;if(this.life.destroyed||this.snapshot.readonly)return!1;const n=this.validate();if(this.showValidation(n),n)return this.emit("invalid",e,{message:n}),!1;const i=this.event("commit",e,{previousValue:this.committedValue});return!this.beforeCommit(i)||((a=(o=this.options.hooks)==null?void 0:o.beforeCommit)==null?void 0:a.call(o,i))===!1?!1:(this.value=this.read(),this.committedValue=this.value,this.element.removeAttribute("aria-invalid"),this.emit("commit",e,{previousValue:i.previousValue}),this.setState("display",e),!0)}cancel(e="api"){var o,a,s,c;if(this.life.destroyed)return;const n=this.event("cancel",e);if(!this.beforeCancel(n)||((a=(o=this.options.hooks)==null?void 0:o.beforeCancel)==null?void 0:a.call(o,n))===!1)return;const i=this.event("state",e,{previousState:this.state,state:"display",value:this.committedValue});this.state!=="display"&&(!this.beforeStateChange(i)||((c=(s=this.options.hooks)==null?void 0:s.beforeStateChange)==null?void 0:c.call(s,i))===!1)||(this.value=this.committedValue,this.disposeView(),this.state="display",this.draw(),this.emit("cancel",e),i.previousState!=="display"&&this.publish(i))}edit(e="api"){var n,i;this.life.destroyed||(this.setState("editing",e),this.state==="editing"&&((i=(n=this.view)==null?void 0:n.focus)==null||i.call(n)))}setState(e,n="api"){var a,s,c,u;if(this.life.destroyed||e===this.state||e==="editing"&&this.snapshot.readonly)return;const i=this.event("state",n,{previousState:this.state});if(i.state=e,!this.beforeStateChange(i)||((s=(a=this.options.hooks)==null?void 0:a.beforeStateChange)==null?void 0:s.call(a,i))===!1)return;const o=this.state!=="editing"&&e!=="editing"&&!((c=this.options.renderers)!=null&&c.display)&&!((u=this.options.renderers)!=null&&u.hover)&&this.renderHover===J.prototype.renderHover;this.value=this.read(),this.state=e,o&&this.view?this.element.dataset.state=e:this.draw(),this.publish(i)}action(e,n){var o,a;if(this.life.destroyed)return;const i={type:e,value:n};(a=(o=this.options).onAction)==null||a.call(o,i),this.emit("action","api",{action:i})}destroy(){var e,n;if(!(this.life.destroyed||this.destroying)){this.destroying=!0,this.value=this.read();try{this.emit("destroy","api")}finally{try{this.disposeView()}finally{(e=this.interactions)==null||e.destroy(),this.life.destroy(),this.listeners.clear(),this.interactionListeners.clear(),(n=this.root)==null||n.remove()}}}}createEditor(){if(this.life.destroyed)throw new Error("Cannot edit a destroyed field");this.disposeView(),this.state="editing";const e=this.renderEditing(this.context());return this.view=e,this.watch(e),{...e,read:()=>this.read(),validate:()=>this.validate(),onInteraction:n=>this.onInteraction(n),destroy:()=>this.destroy()}}render(){if(this.life.destroyed)throw new Error("Cannot render a destroyed field");return this.disposeView(),this.view=this.renderDisplay(this.context()),{...this.view,destroy:()=>this.destroy()}}context(){return{...this.options,readonly:this.isReadonly(),value:this.value,onAction:e=>this.action(e.type,e.value)}}showValidation(e){var n;if(this.mounted){if(!e){this.element.removeAttribute("aria-invalid"),(n=this.feedback)==null||n.remove();return}this.feedback??(this.feedback=this.element.ownerDocument.createElement("div")),this.feedback.className="fc-error",this.feedback.setAttribute("role","status"),this.feedback.textContent=e,this.element.setAttribute("aria-invalid","true"),this.element.append(this.feedback)}}draw(){var y,T,p,b,h,E,M;if(!this.mounted||this.life.destroyed)return;const e=this.element.ownerDocument.activeElement,n=this.state==="editing"&&!!e&&(!!((y=this.view)!=null&&y.element.contains(e))||!!((p=(T=this.view)==null?void 0:T.content)!=null&&p.contains(e))),i=e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?{start:e.selectionStart,end:e.selectionEnd}:void 0;this.disposeView(),this.isReadonly()&&(this.state="display");const o=this.snapshot,a=this.options.content,s=typeof a=="function"?a(o):a??{kind:"text",text:this.value==null?"":String(this.value)},c=this.context(),u=()=>this.state==="editing"?this.renderEditing(c):a?Ee(s):this.state==="hover"?this.renderHover(c):this.renderDisplay(c),f={...o,element:this.element,field:this.options.field,content:s,renderDefault:u,input:m=>this.input(m),commit:()=>this.commit(),cancel:()=>this.cancel(),edit:()=>this.edit(),action:(m,L)=>this.action(m,L)};if(this.view=((h=(b=this.options.renderers)==null?void 0:b[this.state])==null?void 0:h.call(b,f))??u(),this.element.setAttribute("aria-label",this.options.field.label),this.element.dataset.state=this.state,this.element.dataset.readonly=String(o.readonly),this.element.replaceChildren(this.view.element),this.element.removeAttribute("aria-invalid"),this.watch(this.view),n){(M=(E=this.view).focus)==null||M.call(E);const m=this.element.ownerDocument.activeElement;if((i==null?void 0:i.start)!=null&&i.end!=null&&(m instanceof HTMLInputElement||m instanceof HTMLTextAreaElement))try{m.setSelectionRange(i.start,i.end)}catch{}}}watch(e){if(this.mounted&&this.state==="editing"){const i=()=>[this.element,e.content,this.options.focusBoundary].filter(o=>!!o);this.viewLife.add(bt(this.element.ownerDocument,{contains:(o,a)=>i().some(s=>a.composedPath().includes(s)||!!o&&s.contains(o)||ve(o,s)),leave:()=>{this.element.isConnected&&this.commit("user")}}))}this.interactions??(this.interactions=re(this.mounted?this.element:e.element,`field:${this.options.field.key}`,{onInteraction:i=>{var o,a;(a=(o=this.options).onInteraction)==null||a.call(o,i);for(const s of this.interactionListeners)s(i)}}));const n=[...new Set([e.element,e.content].filter(i=>!!i))];for(const i of n)this.viewLife.add(this.interactions.addRoot(i));for(const i of e.inputRoot?[e.inputRoot]:n)for(const o of["input","change"])this.viewLife.listen(i,o,a=>{var s;this.handled.has(a)||(this.handled.add(a),this.input(((s=e.read)==null?void 0:s.call(e))??this.value,"user",a),o==="change"&&this.emit("change","user",{originalEvent:a}))})}disposeView(){var n;this.viewLife.destroy(),this.viewLife=new G;const e=this.view;this.view=void 0,(n=e==null?void 0:e.destroy)==null||n.call(e)}event(e,n,i={}){return{...this.snapshot,type:e,source:n,...i}}emit(e,n,i={}){this.publish(this.event(e,n,i))}publish(e){var o,a,s;this.onOutput(e),(a=(o=this.options).onEvent)==null||a.call(o,e);for(const c of[...this.listeners])c(e);const n=this.mounted?this.element:(s=this.view)==null?void 0:s.element;if(!n)return;const i=n.ownerDocument.defaultView.CustomEvent;n.dispatchEvent(new i(`field:${e.type}`,{detail:e,bubbles:!0}))}}function Ee(t){if(t.kind==="node")return{element:t.node,destroy:t.destroy};const e=document.createElement("div");if(e.className=t.className??"",t.kind==="text")return e.textContent=t.text,{element:e};const n=t.children.map(Ee);return e.append(...n.map(i=>i.element)),{element:e,destroy:()=>n.forEach(i=>{var o;return(o=i.destroy)==null?void 0:o.call(i)})}}function r(t,e="",n){const i=document.createElement(t);return i.className=e,n!==void 0&&(i.textContent=n),i}function $e(t,e=312){t.rows=1,t.style.resize="none";const n=()=>{t.style.height="auto";const i=t.scrollHeight;i>0&&(t.style.height=Math.min(i,e)+"px"),t.style.overflowY=i>e?"auto":"hidden"};return t.addEventListener("input",n),t.addEventListener("focus",n),queueMicrotask(n),n}const Z=t=>t.choices??(t.options||[]).map(e=>({id:e,label:e})),Oe=["rgba(61, 188, 47, 0.2)","rgba(0, 184, 159, 0.2)","rgba(244, 118, 189, 0.2)","rgba(149, 155, 238, 0.2)","rgba(184, 143, 255, 0.2)"],Le=(t,e)=>{var n,i;return((n=Z(t).find(o=>o.id===e))==null?void 0:n.color)||((i=t.colors)==null?void 0:i[e])||Oe[Math.max(0,Z(t).findIndex(o=>o.id===e))%Oe.length]},qe=t=>(Array.isArray(t)?t:t==null||t===""?[]:[t]).map(String);function vt(t,e){var n;return((n=Z(t).find(i=>i.id===e))==null?void 0:n.label)||e}function Be(t,e="choice"){const n=r("div","fc-tags");for(const i of qe(t.value)){const o=vt(t.field,i),a=r(e==="relation"?"button":"span","fc-tag fc-tag--"+e);e==="choice"&&(a.style.backgroundColor=Le(t.field,i)),e==="person"&&a.append(r("span","fc-avatar",o.slice(0,1))),a.append(r("span","fc-tag-label",o)),a.tagName==="BUTTON"&&(a.type="button",a.onclick=s=>{var c;s.stopPropagation(),(c=t.onAction)==null||c.call(t,{type:"open",value:i})}),n.append(a)}return n.children.length||n.append(r("span","fc-empty","待填")),n}function Ae(t,e,n="choice"){var l;const i=r("div","fc-choice fc-choice--"+n);let o=qe(e.value).slice(0,t?void 0:1);const a=new Map(Z(e.field).map(d=>[d.id,d]));let s=Z(e.field);const c=t&&(e.field.maxSelections??0)>0?e.field.maxSelections:1/0,u=r("select","fc-select");u.hidden=!0,u.multiple=t,u.disabled=e.readonly,u.required=!!e.field.required,u.ariaLabel=e.field.label;const f=r("div","fc-choice-head"),y=r("div","fc-choice-selection"),T=r("span","fc-empty fc-choice-placeholder","待填"),p=r("input","fc-choice-search");p.placeholder="",p.autocomplete="off",p.ariaLabel="输入以搜索"+e.field.label,p.disabled=e.readonly;const b=()=>{p.size=Math.max(1,[...p.value].length+1)};b();const h=r("div","fc-option-list");h.setAttribute("role",n==="radio"?"radiogroup":"group"),h.ariaLabel=e.field.label;const E=r("div","fc-error fc-choice-feedback");E.setAttribute("role","status");const M=r("div","fc-picker-status");M.setAttribute("role","status");const m=r("button","fc-retry","重试");m.type="button",m.hidden=!0;let L,R=0,F=!1,A=!1;const C=n!=="radio"&&!!((l=e.services)!=null&&l.searchOptions),N=n!=="radio"&&e.layout!=="compact"&&!e.readonly;let x;const z=()=>{const d=x;x=void 0,d==null||d.close()},q=()=>{!N||F||x||e.readonly||(x=de({anchor:f,content:h,width:"anchor",onDismiss:()=>{x=void 0}}))},j=()=>{!N||!x||(z(),i.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))},B=()=>{var d;(d=e.onSelectedOptions)==null||d.call(e,o.map(w=>a.get(w)).filter(w=>!!w)),i.dispatchEvent(new Event("change",{bubbles:!0}))},O=()=>{var d;if(u.replaceChildren(),!t){const w=r("option");w.value="",u.append(w)}for(const w of new Set([...s.map(v=>v.id),...o])){const v=r("option","",((d=a.get(w))==null?void 0:d.label)||w);v.value=w,v.selected=o.includes(w),u.append(v)}t||(u.value=o[0]||"")},H=()=>{y.replaceChildren(),h.replaceChildren(),O(),!o.length&&!p.value&&y.append(T);for(const v of o){const k=a.get(v),P=r("span","fc-tag fc-tag--"+n);(n==="choice"||n==="radio")&&(P.style.backgroundColor=Le(e.field,v)),n==="person"&&P.append(r("span","fc-avatar",((k==null?void 0:k.label)||v).slice(0,1))),P.append(r("span","fc-tag-label",((k==null?void 0:k.label)||v)+(k!=null&&k.disabled?"(已停用)":"")));const K=r("span","fc-tag-slot"),W=r("button","fc-choice-remove","×");W.type="button",W.disabled=e.readonly,W.ariaLabel="移除"+((k==null?void 0:k.label)||v),W.onclick=Q=>{Q.stopPropagation(),o=o.filter(Y=>Y!==v),E.textContent="",H(),p.focus(),B()},K.append(W),P.append(K),y.append(P)}const d=p.value.trim().toLocaleLowerCase(),w=s.filter(v=>!v.disabled&&(C||(v.label+" "+v.id+" "+(v.description||"")).toLocaleLowerCase().includes(d)));for(const v of w){const k=r("button","fc-option");k.type="button",k.dataset.value=v.id,k.disabled=e.readonly||A;const P=o.includes(v.id);k.classList.toggle("selected",P),k.setAttribute(n==="radio"?"aria-checked":"aria-pressed",String(P)),n==="radio"&&k.setAttribute("role","radio");const K=r("span","fc-option-label"+(n==="choice"?" fc-tag":""),v.label);n==="choice"&&(K.style.backgroundColor=Le(e.field,v.id)),n==="person"&&k.append(r("span","fc-avatar",v.label.slice(0,1))),n==="relation"&&k.append(r("span","fc-relation-icon","↗"));const W=r("span","fc-option-copy");W.append(K),v.description&&W.append(r("small","fc-option-description",v.description)),k.append(W,r("span","fc-option-mark",P?"✓":"")),k.onclick=Q=>{if(Q.stopPropagation(),!e.readonly){if(!t)o=[v.id];else if(P)o=o.filter(Y=>Y!==v.id);else{const Y=v.exclusive?[]:o.filter(X=>{var oe;return!((oe=a.get(X))!=null&&oe.exclusive)});if(Y.length>=c){E.textContent="最多可选择 "+c+" 项";return}o=[...Y,v.id]}E.textContent="",t||(p.value="",b()),H(),h.querySelectorAll("button").forEach(Y=>{Y.dataset.value===v.id&&Y.focus()}),B(),!t&&N&&j()}},h.append(k)}!w.length&&!A&&h.append(r("p","fc-empty fc-choice-empty","暂无匹配选项"))},$=async()=>{L==null||L.abort();const d=++R;L=new AbortController,A=!0,m.hidden=!0,M.textContent="加载中…",i.setAttribute("aria-busy","true"),H();try{const w=await e.services.searchOptions(e.field,p.value.trim(),L.signal);if(F||d!==R)return;s=w,w.forEach(v=>a.set(v.id,v)),M.textContent=""}catch{if(F||d!==R)return;s=[],M.textContent="加载失败,请重试",m.hidden=!1}finally{!F&&d===R&&(A=!1,i.setAttribute("aria-busy","false"),H())}};p.oninput=()=>{b(),C?$():H()},p.onfocus=()=>q(),f.onclick=d=>{d.target.closest("button")||p.focus()},m.onclick=()=>void $();const U=d=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Home","End"].includes(d.key))return;const w=[...h.querySelectorAll("button:not(:disabled)")];if(!w.length)return;d.preventDefault();const v=w.indexOf(document.activeElement),k=d.key==="Home"?0:d.key==="End"?w.length-1:(v+(d.key==="ArrowUp"||d.key==="ArrowLeft"?-1:1)+w.length)%w.length;w[k].focus()};if(h.onkeydown=U,p.onkeydown=d=>{d.key==="ArrowDown"&&(q(),U(d))},u.onchange=()=>{o=[...u.selectedOptions].map(d=>d.value).filter(Boolean),H()},f.append(y),n!=="radio"&&f.append(p),N){const d=r("span","fc-field-chevron");d.setAttribute("aria-hidden","true"),f.append(d),i.append(u,f,M,m,E)}else i.append(u,f,M,h,m,E);return H(),C&&!e.readonly&&$(),{element:i,content:N?h:void 0,read:()=>t?[...o]:o[0]||"",validate:()=>e.field.required&&!o.length?"请选择一个选项":o.length>c?"最多可选择 "+c+" 项":void 0,focus:()=>{var d;if(n==="radio"){(d=h.querySelector("button"))==null||d.focus();return}p.focus(),q()},deactivate:()=>{p.value="",b(),z()},destroy:()=>{F=!0,++R,L==null||L.abort(),z()}}}const gt=new Set("P DIV BR STRONG B EM I U S STRIKE UL OL LI BLOCKQUOTE H1 H2 H3 H4 H5 SPAN FONT A IMG PRE CODE HR TABLE THEAD TBODY TR TH TD INPUT".split(" ")),je=t=>/^(https?:\/\/|mailto:)/i.test(t.trim());function he(t){const e=document.createElement("template");e.innerHTML=String(t??"");const n=i=>{for(const o of[...i.childNodes]){if(o.nodeType!==1)continue;const a=o;if(["SCRIPT","STYLE","IFRAME","OBJECT","SVG","MATH"].includes(a.tagName)){a.remove();continue}if(n(a),!gt.has(a.tagName)){a.replaceWith(...a.childNodes);continue}if(a.tagName==="INPUT"&&a.getAttribute("type")!=="checkbox"){a.remove();continue}const s=a.getAttribute("href")||"",c=a.getAttribute("src")||"",u=a.getAttribute("alt")||"",f=a.getAttribute("data-person-id"),y=a.hasAttribute("checked"),T=a.getAttribute("data-task")==="true",p=["color","background-color","text-align","margin-left","font-weight","font-style","text-decoration-line"].map(h=>[h,a.style.getPropertyValue(h)]),b=a.tagName==="FONT"?a.getAttribute("color"):null;for(const h of[...a.attributes])a.removeAttribute(h.name);for(const[h,E]of p)(h==="color"||h==="background-color"?/^(#[a-f\d]{3,8}|rgba?\([\d.,%\s]+\)|[a-z]+)$/i.test(E):h==="text-align"?/^(left|center|right|justify)$/.test(E):h==="margin-left"?/^\d{1,3}px$/.test(E):/^(bold|normal|italic|underline|line-through|[1-9]00)$/.test(E))&&a.style.setProperty(h,E);if(b&&/^(#[a-f\d]{3,8}|[a-z]+)$/i.test(b)&&(a.style.color=b),a.tagName==="A"&&je(s)&&(a.setAttribute("href",s.trim()),a.setAttribute("target","_blank"),a.setAttribute("rel","noopener noreferrer")),a.tagName==="IMG"){if(!/^https?:\/\//i.test(c.trim())){a.remove();continue}a.setAttribute("src",c.trim()),a.setAttribute("alt",u),a.setAttribute("loading","lazy"),a.setAttribute("referrerpolicy","no-referrer")}a.tagName==="SPAN"&&f&&(a.setAttribute("data-person-id",f),a.setAttribute("contenteditable","false")),a.tagName==="INPUT"&&(a.setAttribute("type","checkbox"),a.setAttribute("contenteditable","false"),y&&a.setAttribute("checked","")),T&&a.tagName==="LI"&&a.setAttribute("data-task","true")}};return n(e.content),e.innerHTML}const Ce={undo:'<path d="M9 5 4 10l5 5M4 10h10a6 6 0 0 1 0 12"/>',redo:'<path d="m15 5 5 5-5 5m5-5H10a6 6 0 0 0 0 12"/>',expand:'<path d="M14 3h7v7m0-7-7 7M10 21H3v-7m0 7 7-7"/>',collapse:'<path d="M21 3l-7 7m0-7v7h7M3 21l7-7m-7 0h7v7"/>',paint:'<path d="M3 3h14v7H3zM17 6h4v8h-9v7"/>',quote:'<path d="M4 12h5v7H2v-7l5-7m10 7h5v7h-7v-7l5-7"/>',table:'<rect x="3" y="3" width="18" height="18" rx="1"/><path d="M3 9h18M3 15h18M9 3v18M15 3v18"/>',link:'<path d="m10 14 4-4m-7 7-1 1a4 4 0 0 1-6-6l5-5a4 4 0 0 1 6 0m2 10 5-5a4 4 0 0 0-6-6l-1 1"/>',task:'<rect x="3" y="3" width="18" height="18" rx="1"/><path d="m7 12 3 3 7-7"/>',indent:'<path d="M10 5h11M10 12h11M10 19h11M2 8l4 4-4 4"/>',line:'<path d="M3 12h18M3 5h3m3 0h3m3 0h3M3 19h3m3 0h3m3 0h3"/>'};function yt(t){const e=r("div",`fc-rich${t.layout==="compact"?" fc-rich-compact":""}`),n=r("div","fc-rich-toolbar");n.setAttribute("role","toolbar"),n.ariaLabel="文本格式";const i=r("div","fc-rich-tools");n.append(i);const o=r("div","fc-rich-content");o.contentEditable=String(!t.readonly),o.setAttribute("role","textbox"),o.setAttribute("aria-multiline","true"),o.ariaLabel=t.field.label,o.tabIndex=t.readonly?-1:0,o.innerHTML=he(t.value);const a=r("div","fc-rich-menu");a.hidden=!0;let s=null,c=!1,u=[o.innerHTML],f=0,y=!1,T=null,p,b;const h=()=>{const l=window.getSelection();l!=null&&l.rangeCount&&o.contains(l.anchorNode)&&o.contains(l.focusNode)&&(s=l.getRangeAt(0).cloneRange())},E=()=>{o.focus();const l=window.getSelection();if(!l)return;const d=s&&o.contains(s.commonAncestorContainer)?s:document.createRange();d!==s&&(d.selectNodeContents(o),d.collapse(!1)),l.removeAllRanges(),l.addRange(d),s=d},M=()=>{var d;const l=b;b=void 0,l==null||l.close(),(d=p==null?void 0:p.destroy)==null||d.call(p),p=void 0,a.hidden=!0,a.replaceChildren()},m=new Map,L=()=>{var l;m.get("撤销").disabled=t.readonly||f===0,m.get("重做").disabled=t.readonly||f===u.length-1;for(const[d,w]of[["加粗","bold"],["斜体","italic"],["下划线","underline"],["删除线","strikeThrough"],["有序列表","insertOrderedList"],["无序列表","insertUnorderedList"]]){const v=m.get(d);if(!v)continue;const k=!!((l=document.queryCommandState)!=null&&l.call(document,w));v.classList.toggle("active",k),v.setAttribute("aria-pressed",String(k))}},R=()=>{y||(o.innerHTML!==u[f]&&(u=u.slice(0,f+1),u.push(o.innerHTML),u.length>100&&u.shift(),f=u.length-1),h(),L())},F=()=>{R(),o.dispatchEvent(new Event("change",{bubbles:!0}))},A=l=>{const d=f+l;d<0||d>=u.length||(f=d,y=!0,o.innerHTML=u[f],s=null,E(),y=!1,L(),o.dispatchEvent(new Event("change",{bubbles:!0})))},C=(l,d)=>{t.readonly||(E(),document.execCommand(l,!1,d),h(),M(),F())},N=l=>{if(t.readonly)return;E();const d=window.getSelection().getRangeAt(0);d.deleteContents(),d.insertNode(l),d.setStartAfter(l),d.collapse(!0),s=d.cloneRange(),M(),F()},x=(l,d,w,v=!0)=>{const k=r("button",v?"fc-rich-tool fc-rich-advanced":"fc-rich-tool");return k.type="button",k.ariaLabel=l,k.title=l,k.disabled=t.readonly,Ce[d]?k.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${Ce[d]}</svg>`:k.textContent=d,k.onmousedown=P=>{P.preventDefault(),h()},k.onclick=P=>{P.stopPropagation(),w()},i.append(k),m.set(l,k),k},z=(l,d)=>{if(!t.readonly){if(h(),!a.hidden&&a.ariaLabel===l){M();return}M(),a.className="fc-rich-menu",a.ariaLabel=l,a.hidden=!1,b=de({anchor:m.get(l),anchorMode:"element",content:a,width:"auto",onDismiss:M,onEscape:E}),d(),b==null||b.reposition()}},q=(l,d)=>{const w=r("button","fc-rich-menu-option",l);return w.type="button",w.onmousedown=v=>v.preventDefault(),w.onclick=v=>{v.stopPropagation(),d()},a.append(w),w};x("撤销","undo",()=>A(-1),!1),x("重做","redo",()=>A(1),!1),x("格式刷","paint",()=>{h();const l=s==null?void 0:s.startContainer,d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;!d||!o.contains(d)||(T={tag:/^(B|STRONG|I|EM|U|S)$/.test(d.tagName)?d.tagName.toLowerCase():"span",css:d.getAttribute("style")||""},m.get("格式刷").classList.add("active"))}),x("正文样式","Aa⌄",()=>z("正文样式",()=>{for(const[l,d]of[["正文","p"],["标题 1","h1"],["标题 2","h2"],["标题 3","h3"],["标题 4","h4"],["标题 5","h5"]])q(l,()=>C("formatBlock",d))}));const j=["#1f2329","#8f959e","#ffffff","#f54a45","#ff8800","#ffc60a","#34c724","#14b8a6","#3370ff","#7f3bf5","#f7cdd9","#fce2cf","#fff3b8","#d9f5d6","#d6e8ff","#e9ddfa"];for(const[l,d,w]of[["文字颜色","A⌄","foreColor"],["背景高亮","▰⌄","hiliteColor"]])x(l,d,()=>z(l,()=>{a.classList.add("fc-rich-colors");for(const v of j){const k=q(v,()=>C(w,v));k.textContent="",k.style.backgroundColor=v,k.ariaLabel=`${l} ${v}`}q("清除",()=>C(w,w==="foreColor"?"#1f2329":"transparent"))}));for(const[l,d,w]of[["加粗","B","bold"],["斜体","I","italic"],["下划线","U","underline"],["删除线","S","strikeThrough"]])x(l,d,()=>C(w));x("对齐","☰⌄",()=>z("对齐",()=>{for(const[l,d]of[["左对齐","justifyLeft"],["居中对齐","justifyCenter"],["右对齐","justifyRight"],["两端对齐","justifyFull"]])q(l,()=>C(d))})),x("有序列表","1≡",()=>C("insertOrderedList")),x("无序列表","•≡",()=>C("insertUnorderedList")),x("任务列表","task",()=>{E();const l=window.getSelection().getRangeAt(0),d=r("ul"),w=r("li");w.dataset.task="true";const v=r("input");v.type="checkbox",v.contentEditable="false",w.append(v,l.extractContents()),w.textContent||w.append(document.createTextNode("待办事项")),d.append(w),N(d)}),x("引用","quote",()=>C("formatBlock","blockquote")),x("缩进","indent",()=>z("缩进",()=>{q("增加缩进",()=>C("indent")),q("减少缩进",()=>C("outdent"))})),x("分隔线","line",()=>N(r("hr"))),x("表格","table",()=>z("表格",()=>{const l=r("p","","选择行列"),d=r("div","fc-rich-table-grid");a.append(l,d);for(let w=1;w<=6;w++)for(let v=1;v<=6;v++){const k=r("button");k.type="button",k.ariaLabel=`${w}行${v}列表格`,k.dataset.row=String(w),k.dataset.col=String(v),k.onmousedown=P=>P.preventDefault(),k.onmouseenter=()=>{l.textContent=`${w} × ${v}`,d.querySelectorAll("button").forEach(P=>P.classList.toggle("active",Number(P.dataset.row)<=w&&Number(P.dataset.col)<=v))},k.onclick=()=>{const P=r("table"),K=r("tbody");for(let Q=0;Q<w;Q++){const Y=r("tr");for(let X=0;X<v;X++){const oe=r("td");oe.append(r("br")),Y.append(oe)}K.append(Y)}P.append(K),N(P);const W=document.createRange();W.selectNodeContents(P.querySelector("td")),W.collapse(!0),s=W,E()},d.append(k)}}));const B=()=>z("链接",()=>{const l=r("input","fc-input");l.ariaLabel="链接文本",l.placeholder="输入文本",l.value=(s==null?void 0:s.toString())||"";const d=r("input","fc-input");d.ariaLabel="链接地址",d.placeholder="粘贴或输入超链接";const w=r("div","fc-error"),v=r("button","primary","确定");v.type="button",v.onclick=()=>{const k=d.value.trim();if(!je(k)){w.textContent="请输入 http、https 或 mailto 链接";return}const P=r("a","",l.value||k);P.href=k,P.target="_blank",P.rel="noopener noreferrer",N(P)},a.append(r("span","","文本"),l,r("span","","链接"),d,w,v),l.focus()});x("链接","link",B),x("插入图片","▧",()=>z("插入图片",()=>{const l=r("input","fc-input");l.type="url",l.ariaLabel="图片地址",l.placeholder="https:// 图片地址";const d=r("input","fc-input");d.ariaLabel="图片说明",d.placeholder="图片说明";const w=r("div","fc-error"),v=r("button","primary","插入");v.type="button",v.onclick=()=>{if(!/^https?:\/\//i.test(l.value.trim())||!l.checkValidity()){w.textContent="请输入有效的 http 或 https 图片地址";return}const k=r("img");k.src=l.value.trim(),k.alt=d.value,k.referrerPolicy="no-referrer",N(k)},a.append(l,d,w,v),l.focus()})),x("提及人员","@",()=>z("提及人员",()=>{var d;const l=Ae(!1,{...t,value:"",field:{...t.field,label:"人员"}},"person");p=l,a.append(l.element),l.element.addEventListener("change",w=>{var P,K;w.stopPropagation();const v=String(l.read());if(!v)return;const k=r("span","","@"+(((P=Z(t.field).find(W=>W.id===v))==null?void 0:P.label)||((K=l.element.querySelector("option:checked"))==null?void 0:K.textContent)||v));k.dataset.personId=v,k.contentEditable="false",N(k)}),(d=l.focus)==null||d.call(l)})),x("代码块","{ }",()=>C("formatBlock","pre")),x("表情","☺",()=>z("表情",()=>{a.classList.add("fc-rich-emojis");for(const l of["😀","😊","😂","👍","👏","🎉","❤️","🔥","✅","💡","🚀","👀","🤔","🙏","💪","⭐"])q(l,()=>N(document.createTextNode(l)))}));const O=x("全屏编辑","expand",()=>{h(),c=!c,e.classList.toggle("is-fullscreen",c),M(),O.ariaLabel=O.title=c?"收起全屏":"全屏编辑",O.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">${Ce[c?"collapse":"expand"]}</svg>`,E()},!1);O.disabled=!1,O.classList.add("fc-rich-expand"),n.append(O);const H=()=>{for(const l of i.children)l.inert=l.offsetTop>=i.clientHeight},$=typeof ResizeObserver>"u"?void 0:new ResizeObserver(H);$==null||$.observe(i);const U=l=>{const d=l.target;o.contains(d)||d.closest("input,textarea,select,[contenteditable=true]")||(l.preventDefault(),!e.contains(document.activeElement)&&!a.contains(document.activeElement)&&E())};return e.addEventListener("mousedown",U),a.addEventListener("mousedown",U),o.addEventListener("input",R),o.addEventListener("mouseup",()=>{if(h(),L(),T&&s&&!s.collapsed){const l=s,d=r(T.tag);d.style.cssText=T.css,d.append(l.extractContents()),l.insertNode(d),T=null,m.get("格式刷").classList.remove("active"),F()}}),o.addEventListener("keyup",()=>{h(),L()}),o.addEventListener("click",l=>{const d=l.target;if(d.tagName==="A"&&l.preventDefault(),d instanceof HTMLInputElement&&d.type==="checkbox"){if(t.readonly){l.preventDefault();return}d.toggleAttribute("checked",d.checked),F()}M()}),o.addEventListener("drop",l=>l.preventDefault()),o.addEventListener("paste",l=>{var w,v;if(t.readonly){l.preventDefault();return}l.preventDefault(),h();const d=(w=l.clipboardData)==null?void 0:w.getData("text/html");if(d){const k=document.createElement("template");k.innerHTML=he(d);const P=k.content,K=document.createTextNode("");P.append(K),E();const W=window.getSelection().getRangeAt(0);W.deleteContents(),W.insertNode(P),W.setStartAfter(K),W.collapse(!0),s=W.cloneRange(),F()}else N(document.createTextNode(((v=l.clipboardData)==null?void 0:v.getData("text/plain"))||""))}),e.addEventListener("keydown",l=>{l.key==="Escape"&&!a.hidden?(l.preventDefault(),l.stopPropagation(),M(),E()):l.key==="Escape"&&c?(l.preventDefault(),l.stopPropagation(),O.click()):!t.readonly&&(l.metaKey||l.ctrlKey)&&l.key.toLowerCase()==="z"?(l.preventDefault(),A(l.shiftKey?1:-1)):(l.metaKey||l.ctrlKey)&&l.key.toLowerCase()==="k"&&(l.preventDefault(),h(),B())}),e.append(n,o),L(),{element:e,content:a,inputRoot:e,read:()=>he(o.innerHTML),validate:()=>{var l;return t.field.required&&!((l=o.textContent)!=null&&l.trim())&&!o.querySelector("img")?"请填写内容":void 0},focus:()=>o.focus(),deactivate:()=>{M(),c=!1,e.classList.remove("is-fullscreen"),O.ariaLabel=O.title="全屏编辑"},destroy:()=>{$==null||$.disconnect(),M()}}}const _e=t=>t==null?"":String(t);function wt(t){var n;const e=r("div",`fc-value fc-${t.className||""}`);if(t.field.kind==="richText"||t.field.kind==="richtext"||t.field.kind==="longText"||t.field.control==="richText")e.innerHTML=he(t.value);else if(t.field.kind==="number"&&typeof t.value=="number"){const i=t.field.numberOptions;e.textContent=t.value.toLocaleString("zh-CN",{useGrouping:(i==null?void 0:i.thousandsSeparator)??!1,maximumFractionDigits:(i==null?void 0:i.decimals)??10})+((i==null?void 0:i.suffix)||""),e.classList.add("fc-plain")}else e.textContent=_e(t.value),e.classList.add("fc-plain");return(n=e.textContent)!=null&&n.trim()||(e.textContent="待填",e.classList.add("fc-empty")),e}function ze(t,e){const i=t==="text"&&e.layout!=="compact"?r("textarea","fc-input fc-textarea"):r("input","fc-input");if(i instanceof HTMLInputElement&&(i.type=t),i.value=_e(e.value),i.disabled=e.readonly,i.required=!!e.field.required,i.ariaLabel=e.field.label,i.placeholder=e.field.placeholder||(e.layout!=="compact"?"待填":`请输入${e.field.label}`),e.field.maxLength!==void 0&&(i.maxLength=e.field.maxLength),t==="number"&&i instanceof HTMLInputElement){const o=e.field.numberOptions;i.step=String((o==null?void 0:o.step)??"any"),(o==null?void 0:o.min)!==void 0&&(i.min=String(o.min)),(o==null?void 0:o.max)!==void 0&&(i.max=String(o.max))}return i instanceof HTMLTextAreaElement&&$e(i),t==="text"&&e.layout!=="compact"&&i.addEventListener("keydown",o=>{o.key==="Enter"&&(o.preventDefault(),i.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))}),{element:i,read:()=>t==="number"?i.value===""?null:Number(i.value):i.value,validate:()=>e.field.required&&!i.value.trim()?"此项必填":i.checkValidity()?void 0:i.validationMessage||"请填写有效值",focus:()=>i.focus()}}const se=t=>t==null?"":String(t),ae=t=>t.dispatchEvent(new Event("change",{bubbles:!0}));function xe(t){try{const e=new URL(se(t));return["http:","https:"].includes(e.protocol)?e.href:void 0}catch{return}}function me(t){return r("div","fc-value fc-plain fc-"+(t.className||"")+(t.value==null||t.value===""?" fc-empty":""),se(t.value)||"待填")}function ge(t,e){const n=e==="textarea"?r("textarea","fc-input fc-textarea"):r("input","fc-input");return n instanceof HTMLInputElement&&(n.type=e),n instanceof HTMLTextAreaElement&&$e(n),n.value=se(t.value),n.disabled=t.readonly,n.required=!!t.field.required,n.ariaLabel=t.field.label,n.placeholder=t.field.placeholder||"请输入"+t.field.label,t.field.maxLength!==void 0&&(n.maxLength=t.field.maxLength),{element:n,read:()=>n.value,focus:()=>n.focus(),validate:()=>e==="url"&&n.value&&!xe(n.value)?"请输入 http 或 https 链接":n.checkValidity()?void 0:"请填写有效的"+t.field.label}}function kt(t){const e=r("div","fc-link-value"),n=xe(t.value);if(!n)return me(t);const i=r("a","fc-link",se(t.value));return i.href=n,i.target="_blank",i.rel="noopener noreferrer",i.onclick=o=>o.stopPropagation(),e.append(r("span","fc-link-icon","↗"),i),e}function Ye(t){let e=t.value==null||t.value===""?null:t.value===!0;const n=r("div","fc-switch-field"),i=r("button","fc-switch");i.type="button",i.setAttribute("role","switch"),i.ariaLabel=t.field.label,i.disabled=t.readonly;const o=r("span"),a=()=>{i.setAttribute("aria-checked",String(e===!0)),n.dataset.empty=String(e===null),o.textContent=e===null?"待填":e?"是":"否"};return i.onclick=()=>{t.readonly||(e=!e,a(),ae(n))},n.append(i,o),a(),{element:n,read:()=>e,focus:()=>i.focus()}}function Et(t){return Ye({...t,readonly:!0}).element}function Lt(t){const e=r("div","fc-signals"),n=Array.isArray(t.value)?t.value:[t.value];for(const i of n.filter(o=>o!=null&&o!=="")){const o=typeof i=="object"?i:{status:i},a=o.status??o.value,s=a===!0||a==="passed"||a==="success",c=r("span","fc-signal "+(s?"is-success":"is-pending"),(s?"● ":"○ ")+se(o.label||o.name||(s?"已满足":a===!1?"未满足":a||"等待信号")));e.append(c)}return e.children.length||e.append(r("span","fc-empty","等待外部信号")),e}function At(t){const e=t.value&&typeof t.value=="object"?t.value.display??t.value.value:t.value;return me({...t,value:e!=null&&typeof e!="object"?e:""})}function Ct(t,e){const n=r("div","fc-readonly");return n.append(e(t),r("small","fc-service-note","由系统更新 · 只读")),{element:n,read:()=>t.value}}function Ue(t){const e=t.field.radioValueType==="boolean";let n=t.value==null?"":String(t.value);const i=r("div","fc-radio-group fc-choice--radio");i.setAttribute("role","radiogroup"),i.ariaLabel=t.field.label;const o=[],a=()=>{const s=o.find(c=>c.dataset.value===n&&!c.disabled)??o.find(c=>!c.disabled);for(const c of o){const u=c.dataset.value===n;c.setAttribute("aria-checked",String(u)),c.classList.toggle("selected",u),c.tabIndex=c===s?0:-1}};for(const s of Z(t.field)){const c=r("button","fc-option fc-radio-option");c.type="button",c.dataset.value=s.id,c.setAttribute("role","radio"),c.disabled=t.readonly||!!s.disabled;const u=r("span","fc-radio-dot");u.ariaHidden="true",c.append(u,r("span","fc-option-label",s.label)),c.onclick=f=>{f.stopPropagation(),!(c.disabled||n===s.id)&&(n=s.id,a(),ae(i))},c.onkeydown=f=>{var h,E;if(!["ArrowRight","ArrowDown","ArrowLeft","ArrowUp","Home","End"].includes(f.key)||t.readonly)return;f.preventDefault(),f.stopPropagation();const T=o.filter(M=>!M.disabled),p=T.indexOf(c),b=f.key==="Home"?0:f.key==="End"?T.length-1:(p+(["ArrowLeft","ArrowUp"].includes(f.key)?-1:1)+T.length)%T.length;(h=T[b])==null||h.focus(),(E=T[b])==null||E.click()},o.push(c),i.append(c)}return o.length?n&&!o.some(s=>s.dataset.value===n)&&i.append(r("span","fc-empty","已选选项不可用")):i.append(r("span","fc-empty","暂无选项")),a(),{element:i,read:()=>e?n===""?null:n==="true":n,focus:()=>{var s;return(s=o.find(c=>c.tabIndex===0))==null?void 0:s.focus()},validate:()=>t.field.required&&!n?"请选择一个选项":void 0}}const We=t=>!Array.isArray(t)||!t.length?[]:Array.isArray(t[0])?t.map(e=>e.map(String)):[t.map(String)];function be(t,e){const n=[];for(const i of e){const o=t.find(a=>a.id===i);n.push((o==null?void 0:o.label)||i),t=(o==null?void 0:o.children)||[]}return n.join(" / ")}function xt(t){const e=r("div","fc-tags");for(const n of We(t.value)){const i=r("span","fc-tag");i.append(r("span","fc-tag-label",be(Z(t.field),n))),e.append(i)}return e.children.length||e.append(r("span","fc-empty","待填")),e}function St(t,e){const n=r("div","fc-cascade"),i=r("div","fc-choice-selection"),o=r("input","fc-choice-search");o.placeholder="",o.autocomplete="off",o.ariaLabel="输入以搜索"+e.field.label,o.disabled=e.readonly;const a=()=>{o.size=Math.max(1,[...o.value].length+1)};a();const s=r("div","fc-cascade-columns"),c=r("div","fc-error");c.setAttribute("role","status");const u=Z(e.field);let f=We(e.value),y=[];const T=[],p=(A,C,N=!1)=>A.forEach(x=>{var z;(z=x.children)!=null&&z.length?p(x.children,[...C,x.id],N||!!x.disabled):T.push({path:[...C,x.id],disabled:N||!!x.disabled})});p(u,[]);const b=(A,C)=>JSON.stringify(A)===JSON.stringify(C),h=e.layout!=="compact"&&!e.readonly;let E;const M=()=>{const A=E;E=void 0,A==null||A.close()},m=()=>{!h||E||e.readonly||(E=de({anchor:o.parentElement||n,content:s,width:"anchor",gap:4,onDismiss:()=>{E=void 0}}))},L=()=>{!h||!E||(M(),n.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))},R=A=>{if(e.readonly)return;const C=f.findIndex(N=>b(N,A));if(t&&C>=0)f.splice(C,1);else{if(t&&e.field.maxSelections&&f.length>=e.field.maxSelections){c.textContent="最多可选择 "+e.field.maxSelections+" 项";return}f=t?[...f,A]:[A]}c.textContent="",F(),n.dispatchEvent(new Event("change",{bubbles:!0})),t||L()},F=()=>{var x,z;if(i.replaceChildren(),s.replaceChildren(),f.forEach(q=>{const j=r("span","fc-tag");j.append(r("span","fc-tag-label",be(u,q)));const B=r("span","fc-tag-slot"),O=r("button","fc-choice-remove","×");O.type="button",O.disabled=e.readonly,O.ariaLabel="移除"+be(u,q),O.onclick=()=>{f=f.filter(H=>!b(q,H)),F(),n.dispatchEvent(new Event("change",{bubbles:!0}))},B.append(O),j.append(B),i.append(j)}),o.value.trim()){const q=T.filter(j=>!j.disabled&&be(u,j.path).toLocaleLowerCase().includes(o.value.trim().toLocaleLowerCase()));for(const{path:j}of q){const B=r("button","fc-option",be(u,j));B.type="button",B.disabled=e.readonly,B.setAttribute("aria-pressed",String(f.some(O=>b(O,j)))),B.onclick=()=>R(j),s.append(B)}s.classList.add("is-search"),q.length||s.append(r("p","fc-empty","暂无匹配路径"));return}s.classList.remove("is-search");let A=u,C=[],N=0;for(;A.length;){const q=r("div","fc-cascade-column");q.setAttribute("role","group"),q.ariaLabel="第"+(N+1)+"级";for(const B of A.filter(O=>!O.disabled)){const O=[...C,B.id],H=!!((x=B.children)!=null&&x.length),$=r("button","fc-option",B.label+(H?" ›":""));$.type="button",$.disabled=e.readonly,$.classList.toggle("selected",H?y[N]===B.id:f.some(U=>b(U,O))),$.setAttribute(H?"aria-expanded":"aria-pressed",String(H?y[N]===B.id:f.some(U=>b(U,O)))),$.onclick=()=>{var U,l;H?(y=O,F(),(l=(U=s.lastElementChild)==null?void 0:U.querySelector("button"))==null||l.focus()):R(O)},q.append($)}s.append(q);const j=A.find(B=>B.id===y[N]&&!B.disabled);if(!((z=j==null?void 0:j.children)!=null&&z.length))break;C=[...C,j.id],A=j.children,N++}u.length||s.append(r("p","fc-empty","暂无可选分类"))};if(o.oninput=()=>{a(),F()},o.onfocus=m,s.onkeydown=A=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(A.key))return;const C=A.target,x=[...(C.closest(".fc-cascade-column")||s).querySelectorAll("button:not(:disabled)")];if(!x.length)return;A.preventDefault();const z=x.indexOf(C);x[A.key==="Home"?0:A.key==="End"?x.length-1:(z+(A.key==="ArrowDown"?1:-1)+x.length)%x.length].focus()},n.append(i,o,c),h){const A=r("span","fc-field-chevron");A.setAttribute("aria-hidden","true"),n.append(A),n.addEventListener("click",()=>m())}else n.append(s);return F(),{element:n,content:h?s:void 0,read:()=>t?f.map(A=>[...A]):[...f[0]||[]],focus:()=>{o.focus(),m()},deactivate:()=>{o.value="",a(),M()},destroy:()=>M(),validate:()=>e.field.required&&!f.length?"请选择分类":void 0}}const ie=t=>String(t).padStart(2,"0"),Se=t=>`${t.getFullYear()}-${ie(t.getMonth()+1)}-${ie(t.getDate())}`;function ye(t){if(!/^(\d{4})-(\d{2})-(\d{2})$/.exec(t))return!1;const n=new Date(`${t}T12:00:00`);return!Number.isNaN(n.getTime())&&Se(n)===t}const Ke=t=>{var e,n,i;return{time:((e=t.field.dateOptions)==null?void 0:e.showTime)??t.field.kind!=="date",range:((n=t.field.dateOptions)==null?void 0:n.showRange)??!1,seconds:((i=t.field.dateOptions)==null?void 0:i.showSeconds)??t.field.kind==="datetime"}};function Ge(t){const{time:e,range:n,seconds:i}=Ke(t),a=(Array.isArray(t.value)?t.value:[t.value]).slice(0,n?2:1).filter(Boolean).map(s=>e?String(s).slice(0,i?19:16).replace("T"," "):String(s).slice(0,10)).join(" 至 ");return r("div",`fc-value fc-${t.className||""}${a?"":" fc-empty"}`,a||"待填")}function Mt(t){const{time:e,range:n,seconds:i}=Ke(t),o=r("div","fc-calendar"),a=Array.isArray(t.value)?t.value:[t.value],s=[0,1].map(g=>String(a[g]||"").slice(0,10)),c=[0,1].map(g=>(String(a[g]||"").slice(11,16)||"00:00")+(i?":"+(String(a[g]||"").slice(17,19)||"00"):""));let u=0,f=!1,y=ye(s[0])?new Date(`${s[0]}T12:00:00`):new Date;y=new Date(y.getFullYear(),y.getMonth(),1);const T=r("div","fc-calendar-panel"),p=r("div","fc-calendar-inputs"),b=[],h=()=>o.dispatchEvent(new Event("change",{bubbles:!0})),E=r("div","fc-error");E.setAttribute("role","status");const M=()=>{if(s.some(g=>g&&!ye(g)))return"请输入有效日期,格式为 YYYY-MM-DD";if(t.field.required&&!s[0])return"请选择日期";if(n&&!!s[0]!=!!s[1])return"请选择完整的日期范围";if(e&&c.slice(0,n?2:1).some(g=>!(i?/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/:/^([01]\d|2[0-3]):[0-5]\d$/).test(g)))return"请输入有效时间";if(n&&s[0]&&`${s[0]}T${e?c[0]:""}`>`${s[1]}T${e?c[1]:""}`)return"结束日期时间不能早于开始日期时间"},m=()=>{E.textContent=M()||"",E.textContent||h()};for(let g=0;g<(n?2:1);g++){const D=r("input","fc-input fc-calendar-date");D.type="text",D.value=s[g],D.placeholder=n?g?"结束日期":"开始日期":"YYYY-MM-DD",D.ariaLabel=n?D.placeholder:t.field.label,D.disabled=t.readonly,D.onfocus=()=>{if(u=g,f=g===1,ye(s[g])){const S=new Date(`${s[g]}T12:00:00`);y=new Date(S.getFullYear(),S.getMonth(),1)}w()},D.addEventListener("change",S=>{if(S.stopPropagation(),s[g]=D.value.trim(),ye(s[g])){const I=new Date(`${s[g]}T12:00:00`);y=new Date(I.getFullYear(),I.getMonth(),1)}w(),m()}),p.append(D),b.push(D)}const L=r("div","fc-calendar-header"),R=r("button","fc-calendar-month");R.type="button",R.ariaLabel="选择年份和月份",R.setAttribute("aria-expanded","false"),R.setAttribute("aria-live","polite");const F=(g,D,S)=>{const I=r("button","fc-calendar-nav");return I.type="button",I.ariaLabel=g,I.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${S?"M10 6l-6 6 6 6M19 6l-6 6 6 6":"M15 6l-6 6 6 6"}"/></svg>`,D>0&&I.classList.add("next"),I.onclick=()=>{y=new Date(y.getFullYear(),y.getMonth()+D,1),w()},I};L.append(F("上一年",-12,!0),F("上个月",-1,!1),R,F("下个月",1,!1),F("下一年",12,!0));const A=r("div","fc-calendar-weekdays");for(const g of["日","一","二","三","四","五","六"])A.append(r("span","",g));const C=r("div","fc-calendar-days");C.setAttribute("role","group"),C.ariaLabel="选择日期";const N=r("div","fc-calendar-period");N.hidden=!0;const x=r("button","fc-calendar-back","‹ 返回选择日期");x.type="button";const z=r("div","fc-calendar-period-columns"),q=r("div","fc-calendar-period-list");q.setAttribute("role","group"),q.ariaLabel="年份";const j=r("div","fc-calendar-period-list");j.setAttribute("role","group"),j.ariaLabel="月份";const B=r("div","fc-calendar-period-list");B.ariaLabel="秒",B.hidden=!0,z.append(q,j,B),N.append(x,z);let O="period",H=0;const $=[],U=(g=!1)=>{const D=c[H].split(":").map(Number),S=O==="period"?[[q,y.getFullYear(),"年"],[j,y.getMonth()+1,"月"]]:[[q,D[0],"时"],[j,D[1],"分"],[B,D[2],"秒"]];for(const[I,te,fe]of S)for(const ne of I.querySelectorAll("button")){const pe=Number(ne.dataset.value)===te;ne.classList.toggle("selected",pe),ne.setAttribute("aria-pressed",String(pe)),ne.textContent=`${O==="time"?ie(Number(ne.dataset.value)):ne.dataset.value}${pe?fe:""}`,pe&&g&&(I.scrollTop=Math.max(0,ne.offsetTop-108))}},l=(g,D)=>{const S=r("button","fc-calendar-period-option",String(g));return S.type="button",S.dataset.value=String(g),S.ariaLabel=`${O==="time"?ie(g):g}${O==="time"?D?"时":"分":D?"年":"月"}`,S.disabled=O==="time"&&t.readonly,S.onclick=()=>{if(O==="time"){const I=c[H].split(":");I[D?0:1]=ie(g),c[H]=I.join(":"),$[H].textContent=c[H],U(),m();return}y.setFullYear(D?g:y.getFullYear(),D?y.getMonth():g-1,1),U(),w()},S},d=(g,D=0)=>{if(O=g,H=D,q.replaceChildren(),j.replaceChildren(),B.replaceChildren(),B.hidden=g!=="time"||!i,q.ariaLabel=g==="period"?"年份":"小时",j.ariaLabel=g==="period"?"月份":"分钟",g==="period"){for(let S=Math.max(1,y.getFullYear()-100);S<=Math.min(9999,y.getFullYear()+100);S++)q.append(l(S,!0));for(let S=1;S<=12;S++)j.append(l(S,!1))}else{for(let S=0;S<24;S++)q.append(l(S,!0));for(let S=0;S<60;S++)j.append(l(S,!1));if(i)for(let S=0;S<60;S++){const I=r("button","fc-calendar-period-option",ie(S));I.type="button",I.dataset.value=String(S),I.ariaLabel=ie(S)+"秒",I.disabled=t.readonly,I.onclick=()=>{const te=c[H].split(":");te[2]=ie(S),c[H]=te.join(":"),$[H].textContent=c[H],U(),m()},B.append(I)}}o.classList.add("choosing-period"),N.hidden=!1,(g==="period"?R:$[D]).setAttribute("aria-expanded","true"),U(!0),x.focus()};R.onclick=()=>d("period"),x.onclick=()=>{o.classList.remove("choosing-period"),N.hidden=!0;const g=O==="period"?R:$[H];g.setAttribute("aria-expanded","false"),w(),g.focus()},N.addEventListener("keydown",g=>{if(g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),x.click()),!["ArrowUp","ArrowDown","Home","End"].includes(g.key))return;const D=g.target,S=D.closest(".fc-calendar-period-list");if(!S)return;const I=[...S.querySelectorAll("button")],te=I.indexOf(D),fe=g.key==="Home"?0:g.key==="End"?I.length-1:Math.max(0,Math.min(I.length-1,te+(g.key==="ArrowDown"?1:-1)));g.preventDefault(),I[fe].focus()});function w(){R.textContent=`${y.getFullYear()}年 ${y.getMonth()+1}月`,b.forEach((D,S)=>D.classList.toggle("active",S===u)),C.replaceChildren();for(let D=0;D<y.getDay();D++)C.append(r("span","fc-calendar-blank"));const g=new Date(y.getFullYear(),y.getMonth()+1,0).getDate();for(let D=1;D<=g;D++){const S=Se(new Date(y.getFullYear(),y.getMonth(),D)),I=r("button","fc-calendar-day",String(D));I.type="button",I.ariaLabel=S,I.disabled=t.readonly;const te=s[0]===S||n&&s[1]===S;I.classList.toggle("selected",te),I.setAttribute("aria-pressed",String(te)),I.classList.toggle("in-range",n&&!!s[0]&&!!s[1]&&S>s[0]&&S<s[1]),S===Se(new Date)&&(I.classList.add("today"),I.setAttribute("aria-current","date")),I.onclick=()=>{var fe;n?f?(s[1]=S,s[0]&&s[1]<s[0]&&([s[0],s[1]]=[s[1],s[0]]),u=0,f=!1):(s[0]=S,s[1]="",u=1,f=!0):s[0]=S,b.forEach((ne,pe)=>ne.value=s[pe]),w(),!n||s[1]?m():E.textContent="",(fe=C.querySelector(`[aria-label="${S}"]`))==null||fe.focus(),(!n||s[1])&&o.dispatchEvent(new Event("fc-collapse",{bubbles:!0}))},C.append(I)}}T.append(L,A,C,N);const v=r("div","fc-calendar-time");if(e){for(let g=0;g<(n?2:1);g++){const D=r("div","fc-calendar-time-field"),S=n?g?"结束时间":"开始时间":"时间",I=r("button","fc-input fc-calendar-time-trigger",c[g]);I.type="button",I.disabled=t.readonly,I.ariaLabel=S,I.setAttribute("aria-expanded","false"),I.onclick=()=>d("time",g),$.push(I),D.append(r("span","",S),I),v.append(D)}T.append(v)}const k=r("button","fc-calendar-clear","清空");k.type="button",k.disabled=t.readonly,k.onclick=()=>{s.fill(""),b.forEach(g=>g.value=""),u=0,f=!1,w(),m()},o.append(p,T,k,E);const P=()=>{const g=s.slice(0,n?2:1).map((D,S)=>D?D+(e?`T${c[S]}`:""):"");return n?g.some(Boolean)?g:[]:g[0]};if(t.layout==="compact"||t.readonly)return w(),{element:o,read:P,validate:M,focus:()=>{b[0].focus()},deactivate:()=>{o.classList.remove("choosing-period"),N.hidden=!0}};const K=r("div","fc-date-mirror"),W=()=>K.replaceChildren(Ge({...t,value:P()})),Q=r("span","fc-field-chevron");Q.setAttribute("aria-hidden","true");const Y=r("div","fc-date-trigger");Y.tabIndex=0,Y.setAttribute("role","button"),Y.ariaLabel=`编辑${t.field.label}`,Y.append(K,Q);let X;const oe=()=>{const g=X;X=void 0;const D=!!g&&g.element.contains(document.activeElement);g==null||g.close(),Q.classList.remove("is-open"),D&&queueMicrotask(()=>{X||!Y.isConnected||Y.dispatchEvent(new Event("fc-collapse",{bubbles:!0}))})},Ie=()=>{X||t.readonly||(W(),X=de({anchor:Y,content:o,width:320,gap:4,onDismiss:()=>{X=void 0,Q.classList.remove("is-open")}}),Q.classList.add("is-open"))};return Y.onclick=()=>Ie(),Y.onkeydown=g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),Ie())},o.addEventListener("focusout",g=>{const D=g.relatedTarget;if(D&&(o.contains(D)||Y.contains(D)||ve(D)))return;const S=new Event("focusout",{bubbles:!0});D&&Object.defineProperty(S,"relatedTarget",{value:D}),Y.dispatchEvent(S)}),o.addEventListener("change",()=>Y.dispatchEvent(new Event("change",{bubbles:!0}))),w(),W(),{element:Y,content:o,inputRoot:Y,read:P,validate:M,focus:()=>{Ie(),b[0].focus()},deactivate:oe,destroy:oe}}function Je(t){var h,E,M;let e=Array.isArray(t.value)?structuredClone(t.value):[];const n=r("div","fc-attachments"),i=r("div","fc-file-list"),o=r("label","fc-upload-zone","+ 上传附件"),a=r("input");a.type="file",a.multiple=!0,a.ariaLabel="上传"+t.field.label,a.accept=((h=t.field.attachmentOptions)==null?void 0:h.accept)||"",a.disabled=t.readonly||!((E=t.services)!=null&&E.upload);const s=r("p","fc-error");s.setAttribute("role","status");const c=r("button","fc-retry","重试上传");c.type="button",c.hidden=!0;let u=[],f=!1,y=!1,T;const p=()=>{i.replaceChildren(),e.forEach((m,L)=>{const R=r("div","fc-file-row"),F=xe(m.url),A=F?r("a","fc-link",m.name):r("span","",m.name);if(A.tagName==="A"){const C=A;C.href=F,C.target="_blank",C.rel="noopener noreferrer"}if(R.append(r("span","fc-file-icon","▤"),A),m.size!=null&&R.append(r("small","fc-file-size",Math.ceil(m.size/1024)+" KB")),!t.readonly){const C=r("button","fc-file-remove","×");C.type="button",C.disabled=f,C.ariaLabel="移除"+m.name,C.onclick=()=>{e.splice(L,1),p(),ae(n)},R.append(C)}i.append(R)}),e.length||i.append(r("span","fc-empty","暂无附件"))},b=async()=>{var R;if(!((R=t.services)!=null&&R.upload)||t.readonly||f||!u.length)return;const m=t.field.attachmentOptions;if(m!=null&&m.maxFiles&&e.length+u.length>m.maxFiles){s.textContent="最多上传 "+m.maxFiles+" 个文件";return}if(m!=null&&m.maxBytes&&u.some(F=>F.size>m.maxBytes)){s.textContent="文件大小超过限制";return}const L=((m==null?void 0:m.accept)||"").split(",").map(F=>F.trim().toLowerCase()).filter(Boolean);if(L.length&&u.some(F=>!L.some(A=>A.startsWith(".")?F.name.toLowerCase().endsWith(A):A.endsWith("/*")?F.type.toLowerCase().startsWith(A.slice(0,-1)):F.type.toLowerCase()===A))){s.textContent="文件类型不符合要求";return}T=new AbortController,f=!0,a.disabled=!0,c.hidden=!0,s.textContent="上传中…",n.setAttribute("aria-busy","true"),p();try{const F=await t.services.upload(t.field,u,T.signal);if(y)return;if(F.length!==u.length||F.some(A=>!A.id||!A.name))throw new Error("Invalid file references");e=[...e,...F],u=[],s.textContent="",a.value=""}catch{y||(s.textContent="上传失败,已保留原有附件",c.hidden=!1)}finally{y||(f=!1,a.disabled=!1,n.setAttribute("aria-busy","false"),p(),u.length||ae(n))}};return a.onchange=m=>{m.stopPropagation(),u=Array.from(a.files||[]),b()},c.onclick=()=>void b(),o.append(a),n.append(i),t.readonly||(n.append(o),(M=t.services)!=null&&M.upload||n.append(r("p","fc-service-note","上传服务未接入"))),n.append(s,c),p(),{element:n,read:()=>structuredClone(e),focus:()=>a.focus(),validate:()=>f?"请等待上传完成":u.length?"请完成或重新选择上传文件":t.field.required&&!e.length?"请上传附件":void 0,destroy:()=>{y=!0,T==null||T.abort()}}}function Me(t){if(t&&typeof t=="object"&&!Array.isArray(t)){const e=t;return{selected:Array.isArray(e.selected)?[...e.selected]:[],counts:{...e.counts},total:e.total}}return{selected:[],counts:{}}}function Qe(t,e){var B,O;let n=Me(t.value),i=[...n.selected];const o=e==="attitude"?[{id:"like",label:"赞同"}]:Z(t.field),a=r("div","fc-vote"),s=r("button","fc-vote-trigger");s.type="button",s.setAttribute("aria-haspopup","dialog"),s.setAttribute("aria-expanded","false");const c=r("span","fc-vote-icon","+");c.ariaHidden="true";const u=r("span");s.append(c,u);const f=r("section","fc-vote-panel");f.setAttribute("role","dialog"),f.ariaLabel=t.field.label;const y=r("div","fc-vote-header"),T=r("span","fc-vote-total");y.append(r("strong","",e==="attitude"?"表态投票":e==="multi"?"投票-多选":"投票-单选"),T);const p=r("div","fc-vote-list");p.setAttribute("role",e==="multi"?"group":"radiogroup"),p.ariaLabel=t.field.label;const b=r("p","fc-error");b.setAttribute("role","status");const h=r("button","fc-vote-submit","确认投票");h.type="button";const E=r("button","fc-vote-withdraw","撤回投票");E.type="button";const M=r("button","fc-vote-withdraw","重新加载");M.type="button",M.hidden=!0;const m=r("div","fc-vote-actions");m.append(h,E);let L=!1,R=!1,F=!1,A=!((B=t.services)!=null&&B.loadVote),C,N;const x=()=>{var H,$,U;u.textContent=n.selected.length?"已投票":"投票",s.classList.toggle("is-voted",!!n.selected.length),s.ariaLabel=`${t.field.label},${u.textContent}`,T.textContent=R?"加载中…":A?`${n.total??Object.values(n.counts).reduce((l,d)=>l+d,0)}人已投`:"待加载",f.setAttribute("aria-busy",String(L||R)),p.replaceChildren();for(const l of o){const d=r("button","fc-vote-option");d.type="button",d.dataset.value=l.id,d.disabled=t.readonly||L||R||!A||!((H=t.services)!=null&&H.vote)||!!l.disabled;const w=i.includes(l.id);d.classList.toggle("selected",w),d.setAttribute("role",e==="multi"?"checkbox":"radio"),d.setAttribute("aria-checked",String(w));const v=r("span",e==="multi"?"fc-vote-check":"fc-radio-dot");v.ariaHidden="true",d.append(v,r("span","fc-vote-label",l.label)),A&&Object.keys(n.counts).length&&d.append(r("span","fc-vote-count",`${n.counts[l.id]??0} 票`)),d.onclick=()=>{var k;d.disabled||(i=e==="multi"?w?i.filter(P=>P!==l.id):[...i,l.id]:[l.id],x(),(k=p.querySelector(`[data-index="${o.indexOf(l)}"]`))==null||k.focus())},d.dataset.index=String(o.indexOf(l)),p.append(d)}o.length||p.append(r("p","fc-empty","暂无投票选项")),h.disabled=L||R||!A||!(($=t.services)!=null&&$.vote)||!i.length,h.textContent=L?"提交中…":n.selected.length?"确认改票":"确认投票",E.hidden=!n.selected.length,E.disabled=L||R||!A,m.hidden=t.readonly||!((U=t.services)!=null&&U.vote),N==null||N.reposition()};p.onkeydown=H=>{if(!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(H.key))return;const $=[...p.querySelectorAll("button:not(:disabled)")];if(!$.length)return;H.preventDefault(),H.stopPropagation();const U=$.indexOf(document.activeElement),l=H.key==="Home"?0:H.key==="End"?$.length-1:(U+(["ArrowUp","ArrowLeft"].includes(H.key)?-1:1)+$.length)%$.length;$[l].focus(),e!=="multi"&&$[l].click()};const z=()=>{N==null||N.close(),N=void 0},q=async()=>{var H;if(!(!((H=t.services)!=null&&H.loadVote)||R||L)){R=!0,b.textContent="",M.hidden=!0,C=new AbortController,x();try{const $=await t.services.loadVote(t.field,C.signal);if(F||C.signal.aborted)return;n=Me($),i=[...n.selected],A=!0}catch{F||(A=!1,b.textContent="加载失败,请重试",M.hidden=!1)}finally{F||(R=!1,x())}}},j=async H=>{var $;if(!(L||R||!A||t.readonly||!(($=t.services)!=null&&$.vote))){L=!0,b.textContent="",C=new AbortController,x();try{const U=await t.services.vote(t.field,[...H],C.signal);if(F||C.signal.aborted)return;n=Me(U),i=[...n.selected],L=!1,ae(a),z(),s.focus()}catch{F||(b.textContent="投票失败,请重试")}finally{F||(L=!1,x())}}};return s.onclick=H=>{if(H.stopPropagation(),N){z();return}i=[...n.selected],b.textContent="",x(),N=de({anchor:s,anchorMode:"element",content:f,width:360,onDismiss:()=>{N=void 0,s.setAttribute("aria-expanded","false"),L||(i=[...n.selected])},onEscape:()=>s.focus()}),s.setAttribute("aria-expanded","true"),f.tabIndex=-1,f.focus(),q()},h.onclick=()=>{i.length&&j(i)},E.onclick=()=>void j([]),M.onclick=()=>void q(),f.append(y,p,b,M,m),!t.readonly&&!((O=t.services)!=null&&O.vote)&&f.append(r("p","fc-service-note","创建工作项后可投票")),a.append(s),x(),{element:a,content:f,read:()=>structuredClone(n),focus:()=>s.focus(),validate:()=>L?"请等待投票完成":void 0,deactivate:z,destroy:()=>{F=!0,C==null||C.abort(),z()}}}function Dt(t){const e=t.value&&typeof t.value=="object"?t.value:{},n=r("div","fc-location"),o=[["address","地址","text"],["longitude","经度","number"],["latitude","纬度","number"]].map(([s,c,u])=>{const f=r("label","fc-location-part",c),y=r("input","fc-input");return y.type=u,y.value=se(e[s]),y.disabled=t.readonly,y.ariaLabel=c,y.placeholder=c,u==="number"&&(y.step="any",y.min=s==="longitude"?"-180":"-90",y.max=s==="longitude"?"180":"90"),f.append(y),n.append(f),y}),a=()=>o.every(s=>!s.value)?null:{address:o[0].value,longitude:o[1].value?Number(o[1].value):null,latitude:o[2].value?Number(o[2].value):null};return{element:n,read:a,focus:()=>o[0].focus(),validate:()=>{if(!a())return t.field.required?"请填写位置":void 0;if(o.slice(1).some(s=>s.value===""||!s.checkValidity()))return"请填写有效的经纬度"}}}function Tt(t){const e=t.value;return me({...t,value:e&&typeof e=="object"?se(e.address)||[e.longitude,e.latitude].filter(n=>n!=null).join(", "):""})}function Ft(t,e){const n=r("div","fc-composite"),i=r("div","fc-composite-rows"),o=r("button","fc-composite-add","+ 添加一组");o.type="button";const a=t.field.compositeFields||[],s=[];let c=!1;const u=b=>({...b.value,...Object.fromEntries(b.editors.map(({field:h,editor:E})=>[h.key,E.read()]))}),f=b=>{b.editors.forEach(({editor:h})=>{var E;return(E=h.destroy)==null?void 0:E.call(h)}),b.remove&&(b.remove.onclick=null),b.element.remove()},y=r("p","fc-empty","暂无记录"),T=()=>{s.forEach((b,h)=>{b.legend.textContent="第 "+(h+1)+" 组"}),o.disabled=t.readonly||!a.length||s.length>=(t.field.maxRows||100),s.length?y.remove():i.append(y)},p=b=>{const h=r("fieldset","fc-composite-row"),E=r("legend");h.append(E);const M=a.map(L=>{const R=e(L),F=R.createEditor({...t,field:L,value:b[L.key],readonly:t.readonly||L.editable===!1||!!R.readonly,focusBoundary:void 0,onSelectedOptions:C=>{var N;(N=t.services)!=null&&N.searchOptions&&(L.choices=[...new Map([...Z(L),...C].map(x=>[x.id,x])).values()])}}),A=r("div","fc-composite-field");return A.append(r("label","",L.label+(L.required?" *":"")),F.element),h.append(A),{field:L,editor:F}}),m={value:b,element:h,legend:E,editors:M};if(!t.readonly){const L=r("button","fc-composite-remove","删除此组");L.type="button",L.onclick=()=>{if(c)return;const R=s.indexOf(m);R<0||(f(m),s.splice(R,1),T(),ae(n))},m.remove=L,h.append(L)}s.push(m),i.append(h),T()};for(const b of Array.isArray(t.value)?t.value:[])p(structuredClone(b));return o.onclick=()=>{c||o.disabled||(p({}),ae(n))},n.append(i),t.readonly||n.append(o),a.length||n.append(r("p","fc-service-note","请配置复合子字段")),T(),{element:n,read:()=>s.map(u),validate:()=>{var b;if(t.field.required&&!s.length)return"请至少添加一组";for(const[h,E]of s.entries())for(const{field:M,editor:m}of E.editors){const L=(b=m.validate)==null?void 0:b.call(m);if(L)return"第 "+(h+1)+" 组 · "+M.label+":"+L}},destroy:()=>{c||(c=!0,o.onclick=null,s.forEach(f))}}}class ee extends J{renderDisplay(e){return{element:wt(e)}}renderEditing(e){return ze("text",e)}}class Ze extends ee{renderDisplay(e){return super.renderDisplay({...e,field:{...e.field,kind:"number"}})}renderEditing(e){return ze("number",e)}}class Xe extends ee{renderDisplay(e){return super.renderDisplay({...e,field:{...e.field,control:"richText"}})}renderEditing(e){return yt(e)}}class et extends ee{renderDisplay(e){return{element:me(e)}}renderEditing(e){return ge(e,"textarea")}}class De extends ee{renderDisplay(e){return{element:kt(e)}}renderEditing(e){return ge(e,"url")}}class tt extends ee{renderEditing(e){return ge(e,"email")}}class nt extends ee{renderEditing(e){return ge(e,"tel")}}class ce extends J{constructor(){super(...arguments);_(this,"multiple",!1);_(this,"variant","choice")}renderDisplay(n){return{element:Be(n,this.variant==="radio"?"choice":this.variant)}}renderEditing(n){return Ae(this.multiple,n,this.variant)}}class it extends ce{constructor(){super(...arguments);_(this,"multiple",!0)}}class ot extends ce{constructor(){super(...arguments);_(this,"variant","radio")}renderDisplay(n){return n.layout==="compact"?{element:Be(n)}:Ue({...n,readonly:!0})}renderEditing(n){if(n.layout!=="compact")return Ue(n);const i=Ae(!1,n,"choice");return n.field.radioValueType!=="boolean"?i:{...i,read:()=>{const o=i.read();return o===""?null:o==="true"}}}}class Te extends ce{constructor(){super(...arguments);_(this,"variant","person")}}class st extends Te{constructor(){super(...arguments);_(this,"multiple",!0)}}class Fe extends ce{constructor(){super(...arguments);_(this,"variant","relation")}}class at extends Fe{constructor(){super(...arguments);_(this,"multiple",!0)}}class Re extends J{constructor(){super(...arguments);_(this,"multiple",!1)}renderDisplay(n){return{element:xt(n)}}renderEditing(n){return St(this.multiple,n)}}class rt extends Re{constructor(){super(...arguments);_(this,"multiple",!0)}}class Ne extends J{normalize(e){return e}renderDisplay(e){return{element:Ge(this.normalize(e))}}renderEditing(e){return Mt(this.normalize(e))}}class Ve extends Ne{constructor(){super(...arguments);_(this,"range",!1)}normalize(n){return{...n,field:{...n.field,dateOptions:{showTime:!1,showRange:this.range,...n.field.dateOptions}}}}}class lt extends Ve{constructor(){super(...arguments);_(this,"range",!0)}}class dt extends J{renderDisplay(e){return{element:Et(e)}}renderEditing(e){return Ye(e)}}class ct extends J{renderDisplay(e){return Je({...e,readonly:!0})}renderEditing(e){return Je(e)}}class ut extends J{renderDisplay(e){return{element:Tt(e)}}renderEditing(e){return Dt(e)}}class we extends J{constructor(){super(...arguments);_(this,"mode","attitude")}renderDisplay(n){return Qe({...n,readonly:!0},this.mode)}renderEditing(n){return Qe(n,this.mode)}}class ft extends we{constructor(){super(...arguments);_(this,"mode","single")}}class pt extends we{constructor(){super(...arguments);_(this,"mode","multi")}}class ue extends J{isReadonly(){return!0}constructor(e){super({...e,readonly:!0})}renderDisplay(e){return{element:At(e)}}renderEditing(e){return Ct(e,n=>this.renderDisplay(n).element)}}class He extends ue{renderDisplay(e){return{element:Lt(e)}}}class ht extends ee{renderDisplay(e){const n=document.createElement("button");return n.type="button",n.className="fc-detail-link",n.textContent=e.field.label,n.onclick=i=>{var o;i.stopPropagation(),(o=e.onAction)==null||o.call(e,{type:"open",value:e.value})},{element:n,destroy:()=>{n.onclick=null}}}}class mt extends J{constructor(e,n){super(e),this.resolve=n}renderDisplay(e){var o;if(e.layout==="compact")return{element:me({...e,value:Array.isArray(e.value)&&e.value.length?e.value.length+" 组记录":""})};const n=document.createElement("div");n.className="fc-composite";const i=[];for(const a of Array.isArray(e.value)?e.value:[]){const s=document.createElement("fieldset");s.className="fc-composite-row";for(const c of e.field.compositeFields??[]){const u=document.createElement("label");u.textContent=c.label;const f={...e,field:c,value:a[c.key],readonly:!0},y=this.resolve(c),T=((o=y.renderView)==null?void 0:o.call(y,f))??{element:y.render(f)};i.push(T),s.append(u,T.element)}n.append(s)}return{element:n,destroy:()=>i.forEach(a=>{var s;return(s=a.destroy)==null?void 0:s.call(a)})}}renderEditing(e){return Ft(e,this.resolve)}}const Rt={textarea:"保留换行的纯文本,支持长度限制",radio:"平铺选项,一次选择一项",cascadeSingle:"逐级浏览分类,选择完整路径",cascadeMulti:"逐级浏览并选择多条路径",person:"按姓名搜索,以稳定人员 ID 保存",multiPerson:"按姓名搜索,以稳定人员 ID 保存",date:"日历选择和直接输入,支持清空",dateRange:"连续选择起止日期,校验完整范围",url:"填写网址并在新窗口安全打开",cloudDocument:"添加云文档链接,点击打开原文档",email:"邮箱输入与格式校验",phone:"支持国家区号的电话输入",switch:"以是或否记录布尔状态",attachment:"文件列表、上传与删除,支持上传失败重试",location:"填写地址和经纬度,校验坐标边界",relation:"按名称或编号搜索工作项,点击名称打开详情",multiRelation:"按名称或编号搜索工作项,点击名称打开详情",attitudeVote:"选择并提交投票,结果以宿主服务回读为准",singleVote:"选择并提交投票,结果以宿主服务回读为准",multiVote:"选择并提交投票,结果以宿主服务回读为准",externalSignal:"由外部系统更新,系统内只读",externalMultiSignal:"由外部系统更新,系统内只读",formula:"展示服务端计算结果,不可手工覆盖",aggregate:"展示服务端计算结果,不可手工覆盖",ai:"展示服务端计算结果,不可手工覆盖",system:"展示服务端计算结果,不可手工覆盖",composite:"可重复字段组,复用已注册子控件并逐组校验",multiPersonComposite:"可重复字段组,复用已注册子控件并逐组校验",text:"单行输入,支持清空和必填校验",richText:"紧凑编辑与全屏排版,支持标题、颜色、列表、表格和链接",select:"从字段配置中选择一个选项",multiSelect:"点击标签选择多项,保存为数组",number:"支持小数和负数,空值与零分别保存",dateTime:"日历、时间与日期范围",detail:"由调用方处理关联内容导航"},Nt={title:"text",longText:"richText",status:"select",richtext:"richText",single_select:"select",multi_select:"multiSelect",user:"person",multi_user:"multiPerson",multi_person:"multiPerson",cascade_select:"cascadeSingle",cascade_single:"cascadeSingle",cascade_multi:"cascadeMulti",daterange:"dateRange",date_range:"dateRange",datetime:"dateTime",multi_relation:"multiRelation",attitude_vote:"attitudeVote",single_vote:"singleVote",multi_vote:"multiVote",vote:"attitudeVote",external_signal:"externalSignal",external_multi_signal:"externalMultiSignal",multi_person_composite:"multiPersonComposite",cloud_document:"cloudDocument"},Vt=[["text","单行文本",ee,"文本","T"],["richText","富文本",Xe,"文本","¶"],["select","单选",ce,"选择","◉"],["multiSelect","多选",it,"选择","☑"],["number","数字",Ze,"其他","#"],["dateTime","日期时间",Ne,"日期","◷"],["detail","详情页查看",ht,"关联工作项","↗"],["textarea","多行文本",et,"文本","≡"],["radio","单选按钮",ot,"选择","◉"],["cascadeSingle","级联单选",Re,"选择","⑂"],["cascadeMulti","级联多选",rt,"选择","⑂"],["person","单选人员",Te,"人员","♙"],["multiPerson","多选人员",st,"人员","♙"],["date","日期",Ve,"日期","▦"],["dateRange","日期区间",lt,"日期","▦"],["url","URL 链接",De,"其他","↗"],["cloudDocument","关联云文档",De,"其他","▤"],["email","邮箱",tt,"其他","@"],["phone","电话",nt,"其他","☎"],["switch","开关",dt,"其他","◐"],["attachment","附件",ct,"其他","⌑"],["location","地理位置",ut,"其他","⌖"],["relation","单选关联工作项",Fe,"关联工作项","↗"],["multiRelation","多选关联工作项",at,"关联工作项","↗"],["attitudeVote","表态投票",we,"投票","♡"],["singleVote","单选投票",ft,"投票","♡"],["multiVote","多选投票",pt,"投票","♡"],["externalSignal","系统外信号",He,"系统","◌",!0],["externalMultiSignal","多值系统外信号",He,"系统","◌",!0],["formula","公式计算",ue,"系统","ƒ",!0],["aggregate","聚合计算",ue,"系统","ƒ",!0],["ai","AI 字段",ue,"系统","ƒ",!0],["system","系统字段",ue,"系统","ƒ",!0]];function Ht(t=[]){const e=new Map,n=s=>{if(!/^[A-Za-z][\w-]*$/.test(s.id))throw new Error("Invalid control id");if(e.has(s.id))throw new Error(`Control already registered: ${s.id}`);e.set(s.id,s)},i=s=>{const c=s.control||Nt[s.kind||"text"]||s.kind||"text",u=e.get(c);if(!u)throw new Error(`Unknown control: ${c}`);return u},o=s=>i(s.field).create(s),a=s=>{const c=i(s);return{...c,render:u=>c.create(u).render().element,renderView:u=>c.create(u).render(),createEditor:u=>c.create(u).createEditor()}};for(const[s,c,u,f,y,T]of Vt)n({id:s,label:c,description:Rt[s]||c,glyph:y,group:f,readonly:T,action:s==="detail"?"view":s==="select"||s==="multiSelect"?"select":void 0,create:p=>new u({...p,readonly:T||p.readonly})});for(const[s,c]of[["composite","复合字段"],["multiPersonComposite","多人复合字段"]])n({id:s,label:c,description:"组合多个已注册字段",glyph:"▦",group:"其他",create:u=>new mt(u,a)});return t.forEach(n),{register:n,resolve:i,create:o,list:()=>[...e.values()]}}class It extends J{constructor(e,n){super(e),this.control=n}renderDisplay(e){return{element:this.control.render(e)}}renderEditing(e){return this.control.createEditor(e)}}V.ActionField=ht,V.AttachmentField=ct,V.BaseField=J,V.CascadeField=Re,V.ChoiceField=ce,V.CompositeField=mt,V.ComputedField=ue,V.CustomField=It,V.DateField=Ve,V.DateRangeField=lt,V.DateTimeField=Ne,V.EmailField=tt,V.LinkField=De,V.LocationField=ut,V.MultiCascadeField=rt,V.MultiChoiceField=it,V.MultiPersonField=st,V.MultiRelationField=at,V.MultiVoteField=pt,V.NumberField=Ze,V.PersonField=Te,V.PhoneField=nt,V.RadioField=ot,V.RelationField=Fe,V.RichTextField=Xe,V.SignalField=He,V.SingleVoteField=ft,V.SwitchField=dt,V.TextField=ee,V.TextareaField=et,V.VoteField=we,V.closeAllFieldPopups=Pe,V.createFieldRegistry=Ht,V.openFieldPopup=de,V.renderContent=Ee,V.sanitizeRichText=he,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
1
+ (function(H,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(H=typeof globalThis<"u"?globalThis:H||self,J(H.RowviaFields={}))})(this,function(H){"use strict";var Gt=Object.defineProperty;var Jt=(H,J,de)=>J in H?Gt(H,J,{enumerable:!0,configurable:!0,writable:!0,value:de}):H[J]=de;var Y=(H,J,de)=>Jt(H,typeof J!="symbol"?J+"":J,de);class J{constructor(){Y(this,"cleanups",new Set);Y(this,"stopped",!1)}get destroyed(){return this.stopped}add(e){return this.stopped?e():this.cleanups.add(e),()=>{this.cleanups.delete(e)&&e()}}listen(e,n,o,i){return e.addEventListener(n,o,i),this.add(()=>e.removeEventListener(n,o,i))}timeout(e,n){if(this.stopped)return 0;const o=window.setTimeout(()=>{i(),this.stopped||e()},n),i=this.add(()=>window.clearTimeout(o));return o}interval(e,n){if(this.stopped)return 0;const o=window.setInterval(()=>{this.stopped||e()},n);return this.add(()=>window.clearInterval(o)),o}destroy(){if(this.stopped)return;this.stopped=!0;const e=[...this.cleanups].reverse();this.cleanups.clear();let n;for(const o of e)try{o()}catch(i){n??(n=i)}if(n!==void 0)throw n}}function de(t,e,n={},o=[]){const i=new J,a=new Set,s=p=>[...a].some(g=>g.contains(p)),c=new Set,u=new WeakMap,m=p=>{const g=p.target;if(!(g!=null&&g.closest))return;const f=g.closest('button,input,select,textarea,a,[data-action],[contenteditable],[role="button"],[role="tab"],[data-node-id],[data-rowid],[data-viewport],canvas');if(!f||!s(f))return;const y={};for(let w=f;w&&s(w);w=w.parentElement)for(const[C,N]of Object.entries(w.dataset))N!==void 0&&!(C in y)&&(y[C]=N);const D=f;u.has(p)||(u.set(p,{component:e,type:p.type,action:y.action??y.control,value:"value"in f?D.value:void 0,checked:D.type==="checkbox"||D.type==="radio"?D.checked:void 0,data:y,originalEvent:p}),queueMicrotask(()=>E(p)))},E=p=>{var y;const g=u.get(p);if(!g||i.destroyed)return;u.delete(p),(y=n.onInteraction)==null||y.call(n,g);for(const D of[...c])D(g);const f=t.ownerDocument.defaultView.CustomEvent;t.dispatchEvent(new f("rowvia:interaction",{detail:g,bubbles:!0}))},M=p=>{if(i.destroyed||a.has(p))return()=>{};a.add(p);const g=[];for(const f of["click","dblclick","contextmenu","input","change","submit","keydown","pointerdown","pointerup","wheel"])g.push(i.listen(p,f,m,{capture:!0,passive:!0}));return()=>{a.delete(p),g.forEach(f=>f())}};for(const p of[t,...o])M(p);return{addRoot:M,onInteraction(p){return i.destroyed?()=>{}:(c.add(p),()=>{c.delete(p)})},destroy(){i.destroy(),c.clear(),a.clear()}}}function At(t){for(let e=t.parentElement;e;e=(e==null?void 0:e.parentElement)??null){const n=(t.ownerDocument.defaultView||window).getComputedStyle(e),o=a=>!!a&&a!=="none";if(!o(n.transform)&&!o(n.filter)&&!o(n.perspective)&&!/transform|filter|perspective/.test(n.willChange??""))continue;const i=e.getBoundingClientRect();return{x:i.left+(parseFloat(n.borderLeftWidth)||0),y:i.top+(parseFloat(n.borderTopWidth)||0)}}return{x:0,y:0}}function Ct(t,e,n,o,i={}){var C,N;const a=e.ownerDocument,s=a.defaultView||window;let c=!1,u=!1,m=0;const E=((C=s.requestAnimationFrame)==null?void 0:C.bind(s))??(S=>s.setTimeout(()=>S(0),0)),M=((N=s.cancelAnimationFrame)==null?void 0:N.bind(s))??s.clearTimeout.bind(s),p=()=>{var k;if(c)return;if(!e.isConnected||!t.isConnected){u||(u=!0,w(),o());return}if((k=i.paused)!=null&&k.call(i))return;(!t.style.left||t.style.left==="auto")&&(t.style.left="0px"),(!t.style.top||t.style.top==="auto")&&(t.style.top="0px");const S=e.getBoundingClientRect(),b=i.sizeElement??t,x=a.documentElement.clientWidth||s.innerWidth,V=a.documentElement.clientHeight||s.innerHeight;if(i.width!==void 0){const I=b.getBoundingClientRect(),W=b.offsetWidth&&I.width/b.offsetWidth||1,_=i.width==="anchor"?S.width+(i.widthOffset??0):typeof i.width=="function"?i.width():i.width;b.style.width=_==="auto"?"max-content":`${Math.min(_,x-16)/W}px`}const A=t.getBoundingClientRect(),z=b.getBoundingClientRect(),j=A.width||z.width,B=A.height||z.height,q=t.offsetWidth&&A.width/t.offsetWidth||1,P=t.offsetHeight&&A.height/t.offsetHeight||1,R=!A.width&&!A.height&&!t.offsetWidth&&!t.offsetHeight?At(t):void 0,$=(R==null?void 0:R.x)??A.left-(parseFloat(t.style.left)||0)*q,U=(R==null?void 0:R.y)??A.top-(parseFloat(t.style.top)||0)*P,l=(I,W,_)=>Math.max(8,Math.min(I,_-W-8)),d=l(i.align==="end"||n==="cell"?S.right-j:S.left,j,x),L=i.gap??4;let h=S.bottom+L;h+B>V-8&&S.top-B-L>=8&&(h=S.top-B-L),t.style.left=`${(d-$)/q}px`,t.style.top=`${(l(h,B,V)-U)/P}px`},g=()=>{!c&&!m&&(m=E(()=>{m=0,p()}))},f=s.ResizeObserver??(typeof ResizeObserver>"u"?void 0:ResizeObserver),y=f?new f(g):void 0;y==null||y.observe(t),y==null||y.observe(e),i.sizeElement&&(y==null||y.observe(i.sizeElement));const D=new s.MutationObserver(()=>{(!e.isConnected||!t.isConnected)&&g()});D.observe(a.documentElement,{childList:!0,subtree:!0}),s.addEventListener("scroll",g,!0),s.addEventListener("resize",g);function w(){c=!0,M(m),y==null||y.disconnect(),D.disconnect(),s.removeEventListener("scroll",g,!0),s.removeEventListener("resize",g)}return p(),{update:p,destroy:w}}const ke=Symbol.for("rowvia.field-popup.registry");function Ee(t){const e=t;return e[ke]??(e[ke]={live:new Map,presentations:new WeakMap})}function ve(t,e){if(!t)return!1;const{live:n}=Ee(t.ownerDocument??document),o=e?[e]:[],i=new Set;for(let a=0;a<Math.max(1,o.length);a++)for(const[s,c]of n)if(!(i.has(s)||e&&!o[a].contains(c))){if(s.element.contains(t))return!0;i.add(s),o.push(s.element)}return!1}function qe(t){const{live:e}=Ee((t==null?void 0:t.ownerDocument)??document);for(const[n,o]of[...e])(!t||t.contains(o))&&n.close()}function ce(t){var S;const{live:e,presentations:n}=Ee(t.anchor.ownerDocument);let o;for(let b=t.anchor;b&&(o=(S=n.get(b))==null?void 0:S(t.anchor),!o);b=b.parentElement);t={...t,...o};const{anchor:i,content:a,width:s="anchor",gap:c=4,onDismiss:u}=t,m=i.ownerDocument,E=t.anchorMode==="element"?i:i.closest(".fc-focus-body")||i,M=m.createElement("div");M.className="rowvia-field-scope rowvia-field-popup-layer",o!=null&&o.className&&M.classList.add(...o.className.split(/\s+/).filter(Boolean));const p=m.createElement("div");p.className="rowvia-field-popup",p.append(a),M.append(p),(i.closest("dialog[open]")||m.body||m.documentElement).append(M);let g=!1,f;const y=()=>f==null?void 0:f.update(),D=()=>{g||(g=!0,qe(M),e.delete(N),m.removeEventListener("pointerdown",w,!0),m.removeEventListener("keydown",C,!0),f==null||f.destroy(),M.remove(),u==null||u())},w=b=>{const x=b.target;x&&(M.contains(x)||E.contains(x)||i.contains(x)||ve(x,M))||D()},C=b=>{if(b.key!=="Escape"||[...e.keys()][e.size-1]!==N)return;if(b.preventDefault(),b.stopPropagation(),D(),t.onEscape){t.onEscape();return}const x=m.defaultView.CustomEvent;i.dispatchEvent(new x("fc-collapse",{bubbles:!0,detail:{reason:"escape"}}))},N={element:M,reposition:y,close:D};return e.set(N,i),m.addEventListener("pointerdown",w,!0),m.addEventListener("keydown",C,!0),f=Ct(M,E,"below",D,{sizeElement:p,width:s,widthOffset:2,gap:c,align:t.align}),N}const Le=new WeakMap;function xt(t,e){let n=Le.get(t);if(!n){const i=new Set,a=s=>{for(const c of[...i])i.has(c)&&!c.contains(s.target,s)&&c.leave(s)};t.addEventListener("pointerdown",a,!0),t.addEventListener("focusin",a,!0),n={boundaries:i,stop:()=>{t.removeEventListener("pointerdown",a,!0),t.removeEventListener("focusin",a,!0)}},Le.set(t,n)}n.boundaries.add(e);const o=n;return()=>{!o.boundaries.delete(e)||o.boundaries.size||(o.stop(),Le.delete(t))}}class X{constructor(e){Y(this,"root");Y(this,"destroying",!1);Y(this,"feedback");Y(this,"options");Y(this,"value");Y(this,"committedValue");Y(this,"state");Y(this,"view");Y(this,"viewLife",new J);Y(this,"life",new J);Y(this,"listeners",new Set);Y(this,"interactions");Y(this,"interactionListeners",new Set);Y(this,"mounted",!1);Y(this,"handled",new WeakSet);this.options={...e},this.value=e.value,this.committedValue=e.value,this.state=e.readonly||e.canEdit===!1?"display":e.state??"display"}get element(){if(this.root)return this.root;const e=document.createElement("div");return e.className="rowvia-field",e.tabIndex=0,e.setAttribute("aria-label",this.options.field.label),this.root=e,e}bindRoot(){this.life.listen(this.element,"pointerenter",()=>{this.state==="display"&&this.setState("hover","user")}),this.life.listen(this.element,"pointerleave",()=>{this.state==="hover"&&this.setState("display","user")}),this.life.listen(this.element,"click",e=>{e.target.closest("button,a,input,textarea,select,[contenteditable]")||this.edit("user")}),this.life.listen(this.element,"keydown",e=>{const n=e.key;n==="Escape"&&this.state==="editing"?(e.preventDefault(),this.cancel("user")):(n==="Enter"||n===" ")&&this.state!=="editing"&&e.target===this.element&&(e.preventDefault(),this.edit("user"))}),this.life.listen(this.element,"fc-collapse",e=>{var n;((n=e.detail)==null?void 0:n.reason)==="escape"?this.cancel("user"):this.commit("user")}),this.life.listen(this.element,"focusout",()=>{queueMicrotask(()=>{var n,o;if(this.life.destroyed||!this.element.isConnected||this.state!=="editing")return;const e=this.element.ownerDocument.activeElement;this.element.contains(e)||(o=(n=this.view)==null?void 0:n.content)!=null&&o.contains(e)||ve(e,this.element)||this.commit("user")})})}renderHover(e){return this.renderDisplay(e)}beforeInput(e){return e}beforeCommit(e){return!0}beforeCancel(e){return!0}beforeStateChange(e){return!0}validateValue(e){}isReadonly(){return!!this.options.readonly||this.options.canEdit===!1||this.options.field.editable===!1}onOutput(e){}get snapshot(){return{key:this.options.field.key,value:this.read(),committedValue:this.committedValue,state:this.state,readonly:this.isReadonly()}}mount(e){if(this.life.destroyed)throw new Error("Cannot mount a destroyed field");return this.mounted||(this.mounted=!0,this.bindRoot(),this.draw()),e==null||e.append(this.element),this}read(){var e;return this.state==="editing"&&((e=this.view)!=null&&e.read)?this.view.read():this.value}on(e){return this.life.destroyed?()=>{}:(this.listeners.add(e),()=>{this.listeners.delete(e)})}onInteraction(e){return this.life.destroyed?()=>{}:(this.interactionListeners.add(e),()=>{this.interactionListeners.delete(e)})}input(e,n="api",o){var c;if(this.life.destroyed||this.snapshot.readonly)return;const i=this.value,a=this.snapshot,s=this.beforeInput(e);this.value=(c=this.options.hooks)!=null&&c.beforeInput?this.options.hooks.beforeInput(s,a):s,(n==="api"||!Object.is(e,this.value))&&this.draw(),this.emit("input",n,{previousValue:i,originalEvent:o})}setValue(e){if(this.life.destroyed)return;const n=this.read();this.value=e,this.committedValue=e,this.draw(),this.emit("change","api",{previousValue:n})}update(e){this.life.destroyed||(this.value=this.read(),this.options={...this.options,...e},"value"in e&&(this.value=this.committedValue=e.value),e.state&&(this.state=e.state),this.isReadonly()&&(this.state="display"),this.draw())}validate(){var o,i,a,s;const e=this.read(),n=e==null||e===""||Array.isArray(e)&&e.length===0;return(this.options.field.required&&n?"此项必填":void 0)||this.validateValue(e)||((i=(o=this.view)==null?void 0:o.validate)==null?void 0:i.call(o))||((s=(a=this.options.hooks)==null?void 0:a.validate)==null?void 0:s.call(a,e))}commit(e="api"){var i,a;if(this.life.destroyed||this.snapshot.readonly)return!1;const n=this.validate();if(this.showValidation(n),n)return this.emit("invalid",e,{message:n}),!1;const o=this.event("commit",e,{previousValue:this.committedValue});return!this.beforeCommit(o)||((a=(i=this.options.hooks)==null?void 0:i.beforeCommit)==null?void 0:a.call(i,o))===!1?!1:(this.value=this.read(),this.committedValue=this.value,this.element.removeAttribute("aria-invalid"),this.emit("commit",e,{previousValue:o.previousValue}),this.setState("display",e),!0)}cancel(e="api"){var i,a,s,c;if(this.life.destroyed)return;const n=this.event("cancel",e);if(!this.beforeCancel(n)||((a=(i=this.options.hooks)==null?void 0:i.beforeCancel)==null?void 0:a.call(i,n))===!1)return;const o=this.event("state",e,{previousState:this.state,state:"display",value:this.committedValue});this.state!=="display"&&(!this.beforeStateChange(o)||((c=(s=this.options.hooks)==null?void 0:s.beforeStateChange)==null?void 0:c.call(s,o))===!1)||(this.value=this.committedValue,this.disposeView(),this.state="display",this.draw(),this.emit("cancel",e),o.previousState!=="display"&&this.publish(o))}edit(e="api"){var n,o;this.life.destroyed||(this.setState("editing",e),this.state==="editing"&&((o=(n=this.view)==null?void 0:n.focus)==null||o.call(n)))}setState(e,n="api"){var a,s,c,u;if(this.life.destroyed||e===this.state||e==="editing"&&this.snapshot.readonly)return;const o=this.event("state",n,{previousState:this.state});if(o.state=e,!this.beforeStateChange(o)||((s=(a=this.options.hooks)==null?void 0:a.beforeStateChange)==null?void 0:s.call(a,o))===!1)return;const i=this.state!=="editing"&&e!=="editing"&&!((c=this.options.renderers)!=null&&c.display)&&!((u=this.options.renderers)!=null&&u.hover)&&this.renderHover===X.prototype.renderHover;this.value=this.read(),this.state=e,i&&this.view?this.element.dataset.state=e:this.draw(),this.publish(o)}action(e,n){var i,a;if(this.life.destroyed)return;const o={type:e,value:n};(a=(i=this.options).onAction)==null||a.call(i,o),this.emit("action","api",{action:o})}destroy(){var e,n;if(!(this.life.destroyed||this.destroying)){this.destroying=!0,this.value=this.read();try{this.emit("destroy","api")}finally{try{this.disposeView()}finally{(e=this.interactions)==null||e.destroy(),this.life.destroy(),this.listeners.clear(),this.interactionListeners.clear(),(n=this.root)==null||n.remove()}}}}createEditor(){if(this.life.destroyed)throw new Error("Cannot edit a destroyed field");this.disposeView(),this.state="editing";const e=this.renderEditing(this.context());return this.view=e,this.watch(e),{...e,read:()=>this.read(),validate:()=>this.validate(),onInteraction:n=>this.onInteraction(n),destroy:()=>this.destroy()}}render(){if(this.life.destroyed)throw new Error("Cannot render a destroyed field");return this.disposeView(),this.view=this.renderDisplay(this.context()),{...this.view,destroy:()=>this.destroy()}}context(){return{...this.options,readonly:this.isReadonly(),value:this.value,onAction:e=>this.action(e.type,e.value)}}showValidation(e){var n;if(this.mounted){if(!e){this.element.removeAttribute("aria-invalid"),(n=this.feedback)==null||n.remove();return}this.feedback??(this.feedback=this.element.ownerDocument.createElement("div")),this.feedback.className="fc-error",this.feedback.setAttribute("role","status"),this.feedback.textContent=e,this.element.setAttribute("aria-invalid","true"),this.element.append(this.feedback)}}draw(){var E,M,p,g,f,y,D;if(!this.mounted||this.life.destroyed)return;const e=this.element.ownerDocument.activeElement,n=this.state==="editing"&&!!e&&(!!((E=this.view)!=null&&E.element.contains(e))||!!((p=(M=this.view)==null?void 0:M.content)!=null&&p.contains(e))),o=e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?{start:e.selectionStart,end:e.selectionEnd}:void 0;this.disposeView(),this.isReadonly()&&(this.state="display");const i=this.snapshot,a=this.options.content,s=typeof a=="function"?a(i):a??{kind:"text",text:this.value==null?"":String(this.value)},c=this.context(),u=()=>this.state==="editing"?this.renderEditing(c):a?Ae(s):this.state==="hover"?this.renderHover(c):this.renderDisplay(c),m={...i,element:this.element,field:this.options.field,content:s,renderDefault:u,input:w=>this.input(w),commit:()=>this.commit(),cancel:()=>this.cancel(),edit:()=>this.edit(),action:(w,C)=>this.action(w,C)};if(this.view=((f=(g=this.options.renderers)==null?void 0:g[this.state])==null?void 0:f.call(g,m))??u(),this.element.setAttribute("aria-label",this.options.field.label),this.element.dataset.state=this.state,this.element.dataset.readonly=String(i.readonly),this.element.replaceChildren(this.view.element),this.element.removeAttribute("aria-invalid"),this.watch(this.view),n){(D=(y=this.view).focus)==null||D.call(y);const w=this.element.ownerDocument.activeElement;if((o==null?void 0:o.start)!=null&&o.end!=null&&(w instanceof HTMLInputElement||w instanceof HTMLTextAreaElement))try{w.setSelectionRange(o.start,o.end)}catch{}}}watch(e){if(this.mounted&&this.state==="editing"){const o=()=>[this.element,e.content,this.options.focusBoundary].filter(i=>!!i);this.viewLife.add(xt(this.element.ownerDocument,{contains:(i,a)=>o().some(s=>a.composedPath().includes(s)||!!i&&s.contains(i)||ve(i,s)),leave:()=>{this.element.isConnected&&this.commit("user")}}))}this.interactions??(this.interactions=de(this.mounted?this.element:e.element,`field:${this.options.field.key}`,{onInteraction:o=>{var i,a;(a=(i=this.options).onInteraction)==null||a.call(i,o);for(const s of this.interactionListeners)s(o)}}));const n=[...new Set([e.element,e.content].filter(o=>!!o))];for(const o of n)this.viewLife.add(this.interactions.addRoot(o));for(const o of e.inputRoot?[e.inputRoot]:n)for(const i of["input","change"])this.viewLife.listen(o,i,a=>{var s;this.handled.has(a)||(this.handled.add(a),this.input(((s=e.read)==null?void 0:s.call(e))??this.value,"user",a),i==="change"&&this.emit("change","user",{originalEvent:a}))})}disposeView(){var n;this.viewLife.destroy(),this.viewLife=new J;const e=this.view;this.view=void 0,(n=e==null?void 0:e.destroy)==null||n.call(e)}event(e,n,o={}){return{...this.snapshot,type:e,source:n,...o}}emit(e,n,o={}){this.publish(this.event(e,n,o))}publish(e){var i,a,s;this.onOutput(e),(a=(i=this.options).onEvent)==null||a.call(i,e);for(const c of[...this.listeners])c(e);const n=this.mounted?this.element:(s=this.view)==null?void 0:s.element;if(!n)return;const o=n.ownerDocument.defaultView.CustomEvent;n.dispatchEvent(new o(`field:${e.type}`,{detail:e,bubbles:!0}))}}function Ae(t){if(t.kind==="node")return{element:t.node,destroy:t.destroy};const e=document.createElement("div");if(e.className=t.className??"",t.kind==="text")return e.textContent=t.text,{element:e};const n=t.children.map(Ae);return e.append(...n.map(o=>o.element)),{element:e,destroy:()=>n.forEach(o=>{var i;return(i=o.destroy)==null?void 0:i.call(o)})}}function r(t,e="",n){const o=document.createElement(t);return o.className=e,n!==void 0&&(o.textContent=n),o}function Be(t,e=312){t.rows=1,t.style.resize="none";const n=()=>{t.style.height="auto";const o=t.scrollHeight;o>0&&(t.style.height=Math.min(o,e)+"px"),t.style.overflowY=o>e?"auto":"hidden"};return t.addEventListener("input",n),t.addEventListener("focus",n),queueMicrotask(n),n}const ee=t=>t.choices??(t.options||[]).map(e=>({id:e,label:e})),ze=["rgba(61, 188, 47, 0.2)","rgba(0, 184, 159, 0.2)","rgba(244, 118, 189, 0.2)","rgba(149, 155, 238, 0.2)","rgba(184, 143, 255, 0.2)"],Ce=(t,e)=>{var n,o;return((n=ee(t).find(i=>i.id===e))==null?void 0:n.color)||((o=t.colors)==null?void 0:o[e])||ze[Math.max(0,ee(t).findIndex(i=>i.id===e))%ze.length]},Ye=t=>(Array.isArray(t)?t:t==null||t===""?[]:[t]).map(String);function St(t,e){var n;return((n=ee(t).find(o=>o.id===e))==null?void 0:n.label)||e}function je(t,e="choice"){const n=r("div","fc-tags");for(const o of Ye(t.value)){const i=St(t.field,o),a=r(e==="relation"?"button":"span","fc-tag fc-tag--"+e);e==="choice"&&(a.style.backgroundColor=Ce(t.field,o)),e==="person"&&a.append(r("span","fc-avatar",i.slice(0,1))),a.append(r("span","fc-tag-label",i)),a.tagName==="BUTTON"&&(a.type="button",a.onclick=s=>{var c;s.stopPropagation(),(c=t.onAction)==null||c.call(t,{type:"open",value:o})}),n.append(a)}return n.children.length||n.append(r("span","fc-empty","待填")),n}function xe(t,e,n="choice"){var l;const o=r("div","fc-choice fc-choice--"+n);let i=Ye(e.value).slice(0,t?void 0:1);const a=new Map(ee(e.field).map(d=>[d.id,d]));let s=ee(e.field);const c=t&&(e.field.maxSelections??0)>0?e.field.maxSelections:1/0,u=r("select","fc-select");u.hidden=!0,u.multiple=t,u.disabled=e.readonly,u.required=!!e.field.required,u.ariaLabel=e.field.label;const m=r("div","fc-choice-head"),E=r("div","fc-choice-selection"),M=r("span","fc-empty fc-choice-placeholder","待填"),p=r("input","fc-choice-search");p.placeholder="",p.autocomplete="off",p.ariaLabel="输入以搜索"+e.field.label,p.disabled=e.readonly;const g=()=>{p.size=Math.max(1,[...p.value].length+1)};g();const f=r("div","fc-option-list");f.setAttribute("role",n==="radio"?"radiogroup":"group"),f.ariaLabel=e.field.label;const y=r("div","fc-error fc-choice-feedback");y.setAttribute("role","status");const D=r("div","fc-picker-status");D.setAttribute("role","status");const w=r("button","fc-retry","重试");w.type="button",w.hidden=!0;let C,N=0,S=!1,b=!1;const x=n!=="radio"&&!!((l=e.services)!=null&&l.searchOptions),V=n!=="radio"&&e.layout!=="compact"&&!e.readonly;let A;const z=()=>{const d=A;A=void 0,d==null||d.close()},j=()=>{!V||S||A||e.readonly||(A=ce({anchor:m,content:f,width:"anchor",onDismiss:()=>{A=void 0}}))},B=()=>{!V||!A||(z(),o.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))},q=()=>{var d;(d=e.onSelectedOptions)==null||d.call(e,i.map(L=>a.get(L)).filter(L=>!!L)),o.dispatchEvent(new Event("change",{bubbles:!0}))},P=()=>{var d;if(u.replaceChildren(),!t){const L=r("option");L.value="",u.append(L)}for(const L of new Set([...s.map(h=>h.id),...i])){const h=r("option","",((d=a.get(L))==null?void 0:d.label)||L);h.value=L,h.selected=i.includes(L),u.append(h)}t||(u.value=i[0]||"")},R=()=>{E.replaceChildren(),f.replaceChildren(),P(),!i.length&&!p.value&&E.append(M);for(const h of i){const k=a.get(h),I=r("span","fc-tag fc-tag--"+n);(n==="choice"||n==="radio")&&(I.style.backgroundColor=Ce(e.field,h)),n==="person"&&I.append(r("span","fc-avatar",((k==null?void 0:k.label)||h).slice(0,1))),I.append(r("span","fc-tag-label",((k==null?void 0:k.label)||h)+(k!=null&&k.disabled?"(已停用)":"")));const W=r("span","fc-tag-slot"),_=r("button","fc-choice-remove","×");_.type="button",_.disabled=e.readonly,_.ariaLabel="移除"+((k==null?void 0:k.label)||h),_.onclick=oe=>{oe.stopPropagation(),i=i.filter(Q=>Q!==h),y.textContent="",R(),p.focus(),q()},W.append(_),I.append(W),E.append(I)}const d=p.value.trim().toLocaleLowerCase(),L=s.filter(h=>!h.disabled&&(x||(h.label+" "+h.id+" "+(h.description||"")).toLocaleLowerCase().includes(d)));for(const h of L){const k=r("button","fc-option");k.type="button",k.dataset.value=h.id,k.disabled=e.readonly||b;const I=i.includes(h.id);k.classList.toggle("selected",I),k.setAttribute(n==="radio"?"aria-checked":"aria-pressed",String(I)),n==="radio"&&k.setAttribute("role","radio");const W=r("span","fc-option-label"+(n==="choice"?" fc-tag":""),h.label);n==="choice"&&(W.style.backgroundColor=Ce(e.field,h.id)),n==="person"&&k.append(r("span","fc-avatar",h.label.slice(0,1))),n==="relation"&&k.append(r("span","fc-relation-icon","↗"));const _=r("span","fc-option-copy");_.append(W),h.description&&_.append(r("small","fc-option-description",h.description)),k.append(_,r("span","fc-option-mark",I?"✓":"")),k.onclick=oe=>{if(oe.stopPropagation(),!e.readonly){if(!t)i=[h.id];else if(I)i=i.filter(Q=>Q!==h.id);else{const Q=h.exclusive?[]:i.filter(te=>{var K;return!((K=a.get(te))!=null&&K.exclusive)});if(Q.length>=c){y.textContent="最多可选择 "+c+" 项";return}i=[...Q,h.id]}y.textContent="",t||(p.value="",g()),R(),f.querySelectorAll("button").forEach(Q=>{Q.dataset.value===h.id&&Q.focus()}),q(),!t&&V&&B()}},f.append(k)}!L.length&&!b&&f.append(r("p","fc-empty fc-choice-empty","暂无匹配选项"))},$=async()=>{C==null||C.abort();const d=++N;C=new AbortController,b=!0,w.hidden=!0,D.textContent="加载中…",o.setAttribute("aria-busy","true"),R();try{const L=await e.services.searchOptions(e.field,p.value.trim(),C.signal);if(S||d!==N)return;s=L,L.forEach(h=>a.set(h.id,h)),D.textContent=""}catch{if(S||d!==N)return;s=[],D.textContent="加载失败,请重试",w.hidden=!1}finally{!S&&d===N&&(b=!1,o.setAttribute("aria-busy","false"),R())}};p.oninput=()=>{g(),x?$():R()},p.onfocus=()=>j(),m.onclick=d=>{d.target.closest("button")||p.focus()},w.onclick=()=>void $();const U=d=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Home","End"].includes(d.key))return;const L=[...f.querySelectorAll("button:not(:disabled)")];if(!L.length)return;d.preventDefault();const h=L.indexOf(document.activeElement),k=d.key==="Home"?0:d.key==="End"?L.length-1:(h+(d.key==="ArrowUp"||d.key==="ArrowLeft"?-1:1)+L.length)%L.length;L[k].focus()};if(f.onkeydown=U,p.onkeydown=d=>{d.key==="ArrowDown"&&(j(),U(d))},u.onchange=()=>{i=[...u.selectedOptions].map(d=>d.value).filter(Boolean),R()},m.append(E),n!=="radio"&&m.append(p),V){const d=r("span","fc-field-chevron");d.setAttribute("aria-hidden","true"),m.append(d),o.append(u,m,D,w,y)}else o.append(u,m,D,f,w,y);return R(),x&&!e.readonly&&$(),{element:o,content:V?f:void 0,read:()=>t?[...i]:i[0]||"",validate:()=>e.field.required&&!i.length?"请选择一个选项":i.length>c?"最多可选择 "+c+" 项":void 0,focus:()=>{var d;if(n==="radio"){(d=f.querySelector("button"))==null||d.focus();return}p.focus(),j()},deactivate:()=>{p.value="",g(),z()},destroy:()=>{S=!0,++N,C==null||C.abort(),z()}}}const Dt=new Set("P DIV BR STRONG B EM I U S STRIKE UL OL LI BLOCKQUOTE H1 H2 H3 H4 H5 SPAN FONT A IMG PRE CODE HR TABLE THEAD TBODY TR TH TD INPUT".split(" ")),_e=t=>/^(https?:\/\/|mailto:)/i.test(t.trim());function he(t){const e=document.createElement("template");e.innerHTML=String(t??"");const n=o=>{for(const i of[...o.childNodes]){if(i.nodeType!==1)continue;const a=i;if(["SCRIPT","STYLE","IFRAME","OBJECT","SVG","MATH"].includes(a.tagName)){a.remove();continue}if(n(a),!Dt.has(a.tagName)){a.replaceWith(...a.childNodes);continue}if(a.tagName==="INPUT"&&a.getAttribute("type")!=="checkbox"){a.remove();continue}const s=a.getAttribute("href")||"",c=a.getAttribute("src")||"",u=a.getAttribute("alt")||"",m=a.getAttribute("data-person-id"),E=a.hasAttribute("checked"),M=a.getAttribute("data-task")==="true",p=["color","background-color","text-align","margin-left","font-weight","font-style","text-decoration-line"].map(f=>[f,a.style.getPropertyValue(f)]),g=a.tagName==="FONT"?a.getAttribute("color"):null;for(const f of[...a.attributes])a.removeAttribute(f.name);for(const[f,y]of p)(f==="color"||f==="background-color"?/^(#[a-f\d]{3,8}|rgba?\([\d.,%\s]+\)|[a-z]+)$/i.test(y):f==="text-align"?/^(left|center|right|justify)$/.test(y):f==="margin-left"?/^\d{1,3}px$/.test(y):/^(bold|normal|italic|underline|line-through|[1-9]00)$/.test(y))&&a.style.setProperty(f,y);if(g&&/^(#[a-f\d]{3,8}|[a-z]+)$/i.test(g)&&(a.style.color=g),a.tagName==="A"&&_e(s)&&(a.setAttribute("href",s.trim()),a.setAttribute("target","_blank"),a.setAttribute("rel","noopener noreferrer")),a.tagName==="IMG"){if(!/^https?:\/\//i.test(c.trim())){a.remove();continue}a.setAttribute("src",c.trim()),a.setAttribute("alt",u),a.setAttribute("loading","lazy"),a.setAttribute("referrerpolicy","no-referrer")}a.tagName==="SPAN"&&m&&(a.setAttribute("data-person-id",m),a.setAttribute("contenteditable","false")),a.tagName==="INPUT"&&(a.setAttribute("type","checkbox"),a.setAttribute("contenteditable","false"),E&&a.setAttribute("checked","")),M&&a.tagName==="LI"&&a.setAttribute("data-task","true")}};return n(e.content),e.innerHTML}const Se={undo:'<path d="M9 5 4 10l5 5M4 10h10a6 6 0 0 1 0 12"/>',redo:'<path d="m15 5 5 5-5 5m5-5H10a6 6 0 0 0 0 12"/>',expand:'<path d="M14 3h7v7m0-7-7 7M10 21H3v-7m0 7 7-7"/>',collapse:'<path d="M21 3l-7 7m0-7v7h7M3 21l7-7m-7 0h7v7"/>',paint:'<path d="M3 3h14v7H3zM17 6h4v8h-9v7"/>',quote:'<path d="M4 12h5v7H2v-7l5-7m10 7h5v7h-7v-7l5-7"/>',table:'<rect x="3" y="3" width="18" height="18" rx="1"/><path d="M3 9h18M3 15h18M9 3v18M15 3v18"/>',link:'<path d="m10 14 4-4m-7 7-1 1a4 4 0 0 1-6-6l5-5a4 4 0 0 1 6 0m2 10 5-5a4 4 0 0 0-6-6l-1 1"/>',task:'<rect x="3" y="3" width="18" height="18" rx="1"/><path d="m7 12 3 3 7-7"/>',indent:'<path d="M10 5h11M10 12h11M10 19h11M2 8l4 4-4 4"/>',line:'<path d="M3 12h18M3 5h3m3 0h3m3 0h3M3 19h3m3 0h3m3 0h3"/>'};function Mt(t){const e=r("div",`fc-rich${t.layout==="compact"?" fc-rich-compact":""}`),n=r("div","fc-rich-toolbar");n.setAttribute("role","toolbar"),n.ariaLabel="文本格式";const o=r("div","fc-rich-tools");n.append(o);const i=r("div","fc-rich-content");i.contentEditable=String(!t.readonly),i.setAttribute("role","textbox"),i.setAttribute("aria-multiline","true"),i.ariaLabel=t.field.label,i.tabIndex=t.readonly?-1:0,i.innerHTML=he(t.value);const a=r("div","fc-rich-menu");a.hidden=!0;let s=null,c=!1,u=[i.innerHTML],m=0,E=!1,M=null,p,g;const f=()=>{const l=window.getSelection();l!=null&&l.rangeCount&&i.contains(l.anchorNode)&&i.contains(l.focusNode)&&(s=l.getRangeAt(0).cloneRange())},y=()=>{i.focus();const l=window.getSelection();if(!l)return;const d=s&&i.contains(s.commonAncestorContainer)?s:document.createRange();d!==s&&(d.selectNodeContents(i),d.collapse(!1)),l.removeAllRanges(),l.addRange(d),s=d},D=()=>{var d;const l=g;g=void 0,l==null||l.close(),(d=p==null?void 0:p.destroy)==null||d.call(p),p=void 0,a.hidden=!0,a.replaceChildren()},w=new Map,C=()=>{var l;w.get("撤销").disabled=t.readonly||m===0,w.get("重做").disabled=t.readonly||m===u.length-1;for(const[d,L]of[["加粗","bold"],["斜体","italic"],["下划线","underline"],["删除线","strikeThrough"],["有序列表","insertOrderedList"],["无序列表","insertUnorderedList"]]){const h=w.get(d);if(!h)continue;const k=!!((l=document.queryCommandState)!=null&&l.call(document,L));h.classList.toggle("active",k),h.setAttribute("aria-pressed",String(k))}},N=()=>{E||(i.innerHTML!==u[m]&&(u=u.slice(0,m+1),u.push(i.innerHTML),u.length>100&&u.shift(),m=u.length-1),f(),C())},S=()=>{N(),i.dispatchEvent(new Event("change",{bubbles:!0}))},b=l=>{const d=m+l;d<0||d>=u.length||(m=d,E=!0,i.innerHTML=u[m],s=null,y(),E=!1,C(),i.dispatchEvent(new Event("change",{bubbles:!0})))},x=(l,d)=>{t.readonly||(y(),document.execCommand(l,!1,d),f(),D(),S())},V=l=>{if(t.readonly)return;y();const d=window.getSelection().getRangeAt(0);d.deleteContents(),d.insertNode(l),d.setStartAfter(l),d.collapse(!0),s=d.cloneRange(),D(),S()},A=(l,d,L,h=!0)=>{const k=r("button",h?"fc-rich-tool fc-rich-advanced":"fc-rich-tool");return k.type="button",k.ariaLabel=l,k.title=l,k.disabled=t.readonly,Se[d]?k.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${Se[d]}</svg>`:k.textContent=d,k.onmousedown=I=>{I.preventDefault(),f()},k.onclick=I=>{I.stopPropagation(),L()},o.append(k),w.set(l,k),k},z=(l,d)=>{if(!t.readonly){if(f(),!a.hidden&&a.ariaLabel===l){D();return}D(),a.className="fc-rich-menu",a.ariaLabel=l,a.hidden=!1,g=ce({anchor:w.get(l),anchorMode:"element",content:a,width:"auto",onDismiss:D,onEscape:y}),d(),g==null||g.reposition()}},j=(l,d)=>{const L=r("button","fc-rich-menu-option",l);return L.type="button",L.onmousedown=h=>h.preventDefault(),L.onclick=h=>{h.stopPropagation(),d()},a.append(L),L};A("撤销","undo",()=>b(-1),!1),A("重做","redo",()=>b(1),!1),A("格式刷","paint",()=>{f();const l=s==null?void 0:s.startContainer,d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;!d||!i.contains(d)||(M={tag:/^(B|STRONG|I|EM|U|S)$/.test(d.tagName)?d.tagName.toLowerCase():"span",css:d.getAttribute("style")||""},w.get("格式刷").classList.add("active"))}),A("正文样式","Aa⌄",()=>z("正文样式",()=>{for(const[l,d]of[["正文","p"],["标题 1","h1"],["标题 2","h2"],["标题 3","h3"],["标题 4","h4"],["标题 5","h5"]])j(l,()=>x("formatBlock",d))}));const B=["#1f2329","#8f959e","#ffffff","#f54a45","#ff8800","#ffc60a","#34c724","#14b8a6","#3370ff","#7f3bf5","#f7cdd9","#fce2cf","#fff3b8","#d9f5d6","#d6e8ff","#e9ddfa"];for(const[l,d,L]of[["文字颜色","A⌄","foreColor"],["背景高亮","▰⌄","hiliteColor"]])A(l,d,()=>z(l,()=>{a.classList.add("fc-rich-colors");for(const h of B){const k=j(h,()=>x(L,h));k.textContent="",k.style.backgroundColor=h,k.ariaLabel=`${l} ${h}`}j("清除",()=>x(L,L==="foreColor"?"#1f2329":"transparent"))}));for(const[l,d,L]of[["加粗","B","bold"],["斜体","I","italic"],["下划线","U","underline"],["删除线","S","strikeThrough"]])A(l,d,()=>x(L));A("对齐","☰⌄",()=>z("对齐",()=>{for(const[l,d]of[["左对齐","justifyLeft"],["居中对齐","justifyCenter"],["右对齐","justifyRight"],["两端对齐","justifyFull"]])j(l,()=>x(d))})),A("有序列表","1≡",()=>x("insertOrderedList")),A("无序列表","•≡",()=>x("insertUnorderedList")),A("任务列表","task",()=>{y();const l=window.getSelection().getRangeAt(0),d=r("ul"),L=r("li");L.dataset.task="true";const h=r("input");h.type="checkbox",h.contentEditable="false",L.append(h,l.extractContents()),L.textContent||L.append(document.createTextNode("待办事项")),d.append(L),V(d)}),A("引用","quote",()=>x("formatBlock","blockquote")),A("缩进","indent",()=>z("缩进",()=>{j("增加缩进",()=>x("indent")),j("减少缩进",()=>x("outdent"))})),A("分隔线","line",()=>V(r("hr"))),A("表格","table",()=>z("表格",()=>{const l=r("p","","选择行列"),d=r("div","fc-rich-table-grid");a.append(l,d);for(let L=1;L<=6;L++)for(let h=1;h<=6;h++){const k=r("button");k.type="button",k.ariaLabel=`${L}行${h}列表格`,k.dataset.row=String(L),k.dataset.col=String(h),k.onmousedown=I=>I.preventDefault(),k.onmouseenter=()=>{l.textContent=`${L} × ${h}`,d.querySelectorAll("button").forEach(I=>I.classList.toggle("active",Number(I.dataset.row)<=L&&Number(I.dataset.col)<=h))},k.onclick=()=>{const I=r("table"),W=r("tbody");for(let oe=0;oe<L;oe++){const Q=r("tr");for(let te=0;te<h;te++){const K=r("td");K.append(r("br")),Q.append(K)}W.append(Q)}I.append(W),V(I);const _=document.createRange();_.selectNodeContents(I.querySelector("td")),_.collapse(!0),s=_,y()},d.append(k)}}));const q=()=>z("链接",()=>{const l=r("input","fc-input");l.ariaLabel="链接文本",l.placeholder="输入文本",l.value=(s==null?void 0:s.toString())||"";const d=r("input","fc-input");d.ariaLabel="链接地址",d.placeholder="粘贴或输入超链接";const L=r("div","fc-error"),h=r("button","primary","确定");h.type="button",h.onclick=()=>{const k=d.value.trim();if(!_e(k)){L.textContent="请输入 http、https 或 mailto 链接";return}const I=r("a","",l.value||k);I.href=k,I.target="_blank",I.rel="noopener noreferrer",V(I)},a.append(r("span","","文本"),l,r("span","","链接"),d,L,h),l.focus()});A("链接","link",q),A("插入图片","▧",()=>z("插入图片",()=>{const l=r("input","fc-input");l.type="url",l.ariaLabel="图片地址",l.placeholder="https:// 图片地址";const d=r("input","fc-input");d.ariaLabel="图片说明",d.placeholder="图片说明";const L=r("div","fc-error"),h=r("button","primary","插入");h.type="button",h.onclick=()=>{if(!/^https?:\/\//i.test(l.value.trim())||!l.checkValidity()){L.textContent="请输入有效的 http 或 https 图片地址";return}const k=r("img");k.src=l.value.trim(),k.alt=d.value,k.referrerPolicy="no-referrer",V(k)},a.append(l,d,L,h),l.focus()})),A("提及人员","@",()=>z("提及人员",()=>{var d;const l=xe(!1,{...t,value:"",field:{...t.field,label:"人员"}},"person");p=l,a.append(l.element),l.element.addEventListener("change",L=>{var I,W;L.stopPropagation();const h=String(l.read());if(!h)return;const k=r("span","","@"+(((I=ee(t.field).find(_=>_.id===h))==null?void 0:I.label)||((W=l.element.querySelector("option:checked"))==null?void 0:W.textContent)||h));k.dataset.personId=h,k.contentEditable="false",V(k)}),(d=l.focus)==null||d.call(l)})),A("代码块","{ }",()=>x("formatBlock","pre")),A("表情","☺",()=>z("表情",()=>{a.classList.add("fc-rich-emojis");for(const l of["😀","😊","😂","👍","👏","🎉","❤️","🔥","✅","💡","🚀","👀","🤔","🙏","💪","⭐"])j(l,()=>V(document.createTextNode(l)))}));const P=A("全屏编辑","expand",()=>{f(),c=!c,e.classList.toggle("is-fullscreen",c),D(),P.ariaLabel=P.title=c?"收起全屏":"全屏编辑",P.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">${Se[c?"collapse":"expand"]}</svg>`,y()},!1);P.disabled=!1,P.classList.add("fc-rich-expand"),n.append(P);const R=()=>{for(const l of o.children)l.inert=l.offsetTop>=o.clientHeight},$=typeof ResizeObserver>"u"?void 0:new ResizeObserver(R);$==null||$.observe(o);const U=l=>{const d=l.target;i.contains(d)||d.closest("input,textarea,select,[contenteditable=true]")||(l.preventDefault(),!e.contains(document.activeElement)&&!a.contains(document.activeElement)&&y())};return e.addEventListener("mousedown",U),a.addEventListener("mousedown",U),i.addEventListener("input",N),i.addEventListener("mouseup",()=>{if(f(),C(),M&&s&&!s.collapsed){const l=s,d=r(M.tag);d.style.cssText=M.css,d.append(l.extractContents()),l.insertNode(d),M=null,w.get("格式刷").classList.remove("active"),S()}}),i.addEventListener("keyup",()=>{f(),C()}),i.addEventListener("click",l=>{const d=l.target;if(d.tagName==="A"&&l.preventDefault(),d instanceof HTMLInputElement&&d.type==="checkbox"){if(t.readonly){l.preventDefault();return}d.toggleAttribute("checked",d.checked),S()}D()}),i.addEventListener("drop",l=>l.preventDefault()),i.addEventListener("paste",l=>{var L,h;if(t.readonly){l.preventDefault();return}l.preventDefault(),f();const d=(L=l.clipboardData)==null?void 0:L.getData("text/html");if(d){const k=document.createElement("template");k.innerHTML=he(d);const I=k.content,W=document.createTextNode("");I.append(W),y();const _=window.getSelection().getRangeAt(0);_.deleteContents(),_.insertNode(I),_.setStartAfter(W),_.collapse(!0),s=_.cloneRange(),S()}else V(document.createTextNode(((h=l.clipboardData)==null?void 0:h.getData("text/plain"))||""))}),e.addEventListener("keydown",l=>{l.key==="Escape"&&!a.hidden?(l.preventDefault(),l.stopPropagation(),D(),y()):l.key==="Escape"&&c?(l.preventDefault(),l.stopPropagation(),P.click()):!t.readonly&&(l.metaKey||l.ctrlKey)&&l.key.toLowerCase()==="z"?(l.preventDefault(),b(l.shiftKey?1:-1)):(l.metaKey||l.ctrlKey)&&l.key.toLowerCase()==="k"&&(l.preventDefault(),f(),q())}),e.append(n,i),C(),{element:e,content:a,inputRoot:e,read:()=>he(i.innerHTML),validate:()=>{var l;return t.field.required&&!((l=i.textContent)!=null&&l.trim())&&!i.querySelector("img")?"请填写内容":void 0},focus:()=>i.focus(),deactivate:()=>{D(),c=!1,e.classList.remove("is-fullscreen"),P.ariaLabel=P.title="全屏编辑"},destroy:()=>{$==null||$.disconnect(),D()}}}const Ue=t=>t==null?"":String(t);function Tt(t){var n;const e=r("div",`fc-value fc-${t.className||""}`);if(t.field.kind==="richText"||t.field.kind==="richtext"||t.field.kind==="longText"||t.field.control==="richText")e.innerHTML=he(t.value);else if(t.field.kind==="number"&&typeof t.value=="number"){const o=t.field.numberOptions;e.textContent=t.value.toLocaleString("zh-CN",{useGrouping:(o==null?void 0:o.thousandsSeparator)??!1,maximumFractionDigits:(o==null?void 0:o.decimals)??10})+((o==null?void 0:o.suffix)||""),e.classList.add("fc-plain")}else e.textContent=Ue(t.value),e.classList.add("fc-plain");return(n=e.textContent)!=null&&n.trim()||(e.textContent="待填",e.classList.add("fc-empty")),e}function We(t,e){const o=t==="text"&&e.layout!=="compact"?r("textarea","fc-input fc-textarea"):r("input","fc-input");if(o instanceof HTMLInputElement&&(o.type=t),o.value=Ue(e.value),o.disabled=e.readonly,o.required=!!e.field.required,o.ariaLabel=e.field.label,o.placeholder=e.field.placeholder||(e.layout!=="compact"?"待填":`请输入${e.field.label}`),e.field.maxLength!==void 0&&(o.maxLength=e.field.maxLength),t==="number"&&o instanceof HTMLInputElement){const i=e.field.numberOptions;o.step=String((i==null?void 0:i.step)??"any"),(i==null?void 0:i.min)!==void 0&&(o.min=String(i.min)),(i==null?void 0:i.max)!==void 0&&(o.max=String(i.max))}return o instanceof HTMLTextAreaElement&&Be(o),t==="text"&&e.layout!=="compact"&&o.addEventListener("keydown",i=>{i.key==="Enter"&&(i.preventDefault(),o.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))}),{element:o,read:()=>t==="number"?o.value===""?null:Number(o.value):o.value,validate:()=>e.field.required&&!o.value.trim()?"此项必填":o.checkValidity()?void 0:o.validationMessage||"请填写有效值",focus:()=>o.focus()}}const ae=t=>t==null?"":String(t),re=t=>t.dispatchEvent(new Event("change",{bubbles:!0}));function De(t){try{const e=new URL(ae(t));return["http:","https:"].includes(e.protocol)?e.href:void 0}catch{return}}function me(t){return r("div","fc-value fc-plain fc-"+(t.className||"")+(t.value==null||t.value===""?" fc-empty":""),ae(t.value)||"待填")}function ge(t,e){const n=e==="textarea"?r("textarea","fc-input fc-textarea"):r("input","fc-input");return n instanceof HTMLInputElement&&(n.type=e),n instanceof HTMLTextAreaElement&&Be(n),n.value=ae(t.value),n.disabled=t.readonly,n.required=!!t.field.required,n.ariaLabel=t.field.label,n.placeholder=t.field.placeholder||"请输入"+t.field.label,t.field.maxLength!==void 0&&(n.maxLength=t.field.maxLength),{element:n,read:()=>n.value,focus:()=>n.focus(),validate:()=>e==="url"&&n.value&&!De(n.value)?"请输入 http 或 https 链接":n.checkValidity()?void 0:"请填写有效的"+t.field.label}}function Ft(t){const e=r("div","fc-link-value"),n=De(t.value);if(!n)return me(t);const o=r("a","fc-link",ae(t.value));return o.href=n,o.target="_blank",o.rel="noopener noreferrer",o.onclick=i=>i.stopPropagation(),e.append(r("span","fc-link-icon","↗"),o),e}function Ke(t){let e=t.value==null||t.value===""?null:t.value===!0;const n=r("div","fc-switch-field"),o=r("button","fc-switch");o.type="button",o.setAttribute("role","switch"),o.ariaLabel=t.field.label,o.disabled=t.readonly;const i=r("span"),a=()=>{o.setAttribute("aria-checked",String(e===!0)),n.dataset.empty=String(e===null),i.textContent=e===null?"待填":e?"是":"否"};return o.onclick=()=>{t.readonly||(e=!e,a(),re(n))},n.append(o,i),a(),{element:n,read:()=>e,focus:()=>o.focus()}}function Rt(t){return Ke({...t,readonly:!0}).element}function Nt(t){const e=r("div","fc-signals"),n=Array.isArray(t.value)?t.value:[t.value];for(const o of n.filter(i=>i!=null&&i!=="")){const i=typeof o=="object"?o:{status:o},a=i.status??i.value,s=a===!0||a==="passed"||a==="success",c=r("span","fc-signal "+(s?"is-success":"is-pending"),(s?"● ":"○ ")+ae(i.label||i.name||(s?"已满足":a===!1?"未满足":a||"等待信号")));e.append(c)}return e.children.length||e.append(r("span","fc-empty","等待外部信号")),e}function Vt(t){const e=t.value&&typeof t.value=="object"?t.value.display??t.value.value:t.value;return me({...t,value:e!=null&&typeof e!="object"?e:""})}function Ot(t,e){const n=r("div","fc-readonly");return n.append(e(t),r("small","fc-service-note","由系统更新 · 只读")),{element:n,read:()=>t.value}}function Ge(t){const e=t.field.radioValueType==="boolean";let n=t.value==null?"":String(t.value);const o=r("div","fc-radio-group fc-choice--radio");o.setAttribute("role","radiogroup"),o.ariaLabel=t.field.label;const i=[],a=()=>{const s=i.find(c=>c.dataset.value===n&&!c.disabled)??i.find(c=>!c.disabled);for(const c of i){const u=c.dataset.value===n;c.setAttribute("aria-checked",String(u)),c.classList.toggle("selected",u),c.tabIndex=c===s?0:-1}};for(const s of ee(t.field)){const c=r("button","fc-option fc-radio-option");c.type="button",c.dataset.value=s.id,c.setAttribute("role","radio"),c.disabled=t.readonly||!!s.disabled;const u=r("span","fc-radio-dot");u.ariaHidden="true",c.append(u,r("span","fc-option-label",s.label)),c.onclick=m=>{m.stopPropagation(),!(c.disabled||n===s.id)&&(n=s.id,a(),re(o))},c.onkeydown=m=>{var f,y;if(!["ArrowRight","ArrowDown","ArrowLeft","ArrowUp","Home","End"].includes(m.key)||t.readonly)return;m.preventDefault(),m.stopPropagation();const M=i.filter(D=>!D.disabled),p=M.indexOf(c),g=m.key==="Home"?0:m.key==="End"?M.length-1:(p+(["ArrowLeft","ArrowUp"].includes(m.key)?-1:1)+M.length)%M.length;(f=M[g])==null||f.focus(),(y=M[g])==null||y.click()},i.push(c),o.append(c)}return i.length?n&&!i.some(s=>s.dataset.value===n)&&o.append(r("span","fc-empty","已选选项不可用")):o.append(r("span","fc-empty","暂无选项")),a(),{element:o,read:()=>e?n===""?null:n==="true":n,focus:()=>{var s;return(s=i.find(c=>c.tabIndex===0))==null?void 0:s.focus()},validate:()=>t.field.required&&!n?"请选择一个选项":void 0}}const Je=t=>!Array.isArray(t)||!t.length?[]:Array.isArray(t[0])?t.map(e=>e.map(String)):[t.map(String)];function be(t,e){const n=[];for(const o of e){const i=t.find(a=>a.id===o);n.push((i==null?void 0:i.label)||o),t=(i==null?void 0:i.children)||[]}return n.join(" / ")}function Ht(t){const e=r("div","fc-tags");for(const n of Je(t.value)){const o=r("span","fc-tag");o.append(r("span","fc-tag-label",be(ee(t.field),n))),e.append(o)}return e.children.length||e.append(r("span","fc-empty","待填")),e}function $t(t,e){const n=r("div","fc-cascade"),o=r("div","fc-choice-selection"),i=r("input","fc-choice-search");i.placeholder="",i.autocomplete="off",i.ariaLabel="输入以搜索"+e.field.label,i.disabled=e.readonly;const a=()=>{i.size=Math.max(1,[...i.value].length+1)};a();const s=r("div","fc-cascade-columns"),c=r("div","fc-error");c.setAttribute("role","status");const u=ee(e.field);let m=Je(e.value),E=[];const M=[],p=(b,x,V=!1)=>b.forEach(A=>{var z;(z=A.children)!=null&&z.length?p(A.children,[...x,A.id],V||!!A.disabled):M.push({path:[...x,A.id],disabled:V||!!A.disabled})});p(u,[]);const g=(b,x)=>JSON.stringify(b)===JSON.stringify(x),f=e.layout!=="compact"&&!e.readonly;let y;const D=()=>{const b=y;y=void 0,b==null||b.close()},w=()=>{!f||y||e.readonly||(y=ce({anchor:i.parentElement||n,content:s,width:"anchor",gap:4,onDismiss:()=>{y=void 0}}))},C=()=>{!f||!y||(D(),n.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))},N=b=>{if(e.readonly)return;const x=m.findIndex(V=>g(V,b));if(t&&x>=0)m.splice(x,1);else{if(t&&e.field.maxSelections&&m.length>=e.field.maxSelections){c.textContent="最多可选择 "+e.field.maxSelections+" 项";return}m=t?[...m,b]:[b]}c.textContent="",S(),n.dispatchEvent(new Event("change",{bubbles:!0})),t||C()},S=()=>{var A,z;if(o.replaceChildren(),s.replaceChildren(),m.forEach(j=>{const B=r("span","fc-tag");B.append(r("span","fc-tag-label",be(u,j)));const q=r("span","fc-tag-slot"),P=r("button","fc-choice-remove","×");P.type="button",P.disabled=e.readonly,P.ariaLabel="移除"+be(u,j),P.onclick=()=>{m=m.filter(R=>!g(j,R)),S(),n.dispatchEvent(new Event("change",{bubbles:!0}))},q.append(P),B.append(q),o.append(B)}),i.value.trim()){const j=M.filter(B=>!B.disabled&&be(u,B.path).toLocaleLowerCase().includes(i.value.trim().toLocaleLowerCase()));for(const{path:B}of j){const q=r("button","fc-option",be(u,B));q.type="button",q.disabled=e.readonly,q.setAttribute("aria-pressed",String(m.some(P=>g(P,B)))),q.onclick=()=>N(B),s.append(q)}s.classList.add("is-search"),j.length||s.append(r("p","fc-empty","暂无匹配路径"));return}s.classList.remove("is-search");let b=u,x=[],V=0;for(;b.length;){const j=r("div","fc-cascade-column");j.setAttribute("role","group"),j.ariaLabel="第"+(V+1)+"级";for(const q of b.filter(P=>!P.disabled)){const P=[...x,q.id],R=!!((A=q.children)!=null&&A.length),$=r("button","fc-option",q.label+(R?" ›":""));$.type="button",$.disabled=e.readonly,$.classList.toggle("selected",R?E[V]===q.id:m.some(U=>g(U,P))),$.setAttribute(R?"aria-expanded":"aria-pressed",String(R?E[V]===q.id:m.some(U=>g(U,P)))),$.onclick=()=>{var U,l;R?(E=P,S(),(l=(U=s.lastElementChild)==null?void 0:U.querySelector("button"))==null||l.focus()):N(P)},j.append($)}s.append(j);const B=b.find(q=>q.id===E[V]&&!q.disabled);if(!((z=B==null?void 0:B.children)!=null&&z.length))break;x=[...x,B.id],b=B.children,V++}u.length||s.append(r("p","fc-empty","暂无可选分类"))};if(i.oninput=()=>{a(),S()},i.onfocus=w,s.onkeydown=b=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(b.key))return;const x=b.target,A=[...(x.closest(".fc-cascade-column")||s).querySelectorAll("button:not(:disabled)")];if(!A.length)return;b.preventDefault();const z=A.indexOf(x);A[b.key==="Home"?0:b.key==="End"?A.length-1:(z+(b.key==="ArrowDown"?1:-1)+A.length)%A.length].focus()},n.append(o,i,c),f){const b=r("span","fc-field-chevron");b.setAttribute("aria-hidden","true"),n.append(b),n.addEventListener("click",()=>w())}else n.append(s);return S(),{element:n,content:f?s:void 0,read:()=>t?m.map(b=>[...b]):[...m[0]||[]],focus:()=>{i.focus(),w()},deactivate:()=>{i.value="",a(),D()},destroy:()=>D(),validate:()=>e.field.required&&!m.length?"请选择分类":void 0}}const se=t=>String(t).padStart(2,"0"),Me=t=>`${t.getFullYear()}-${se(t.getMonth()+1)}-${se(t.getDate())}`;function ye(t){if(!/^(\d{4})-(\d{2})-(\d{2})$/.exec(t))return!1;const n=new Date(`${t}T12:00:00`);return!Number.isNaN(n.getTime())&&Me(n)===t}const Qe=t=>{var e,n,o;return{time:((e=t.field.dateOptions)==null?void 0:e.showTime)??t.field.kind!=="date",range:((n=t.field.dateOptions)==null?void 0:n.showRange)??!1,seconds:((o=t.field.dateOptions)==null?void 0:o.showSeconds)??t.field.kind==="datetime"}};function Xe(t){const{time:e,range:n,seconds:o}=Qe(t),a=(Array.isArray(t.value)?t.value:[t.value]).slice(0,n?2:1).filter(Boolean).map(s=>e?String(s).slice(0,o?19:16).replace("T"," "):String(s).slice(0,10)).join(" 至 ");return r("div",`fc-value fc-${t.className||""}${a?"":" fc-empty"}`,a||"待填")}function It(t){var yt,wt,kt,Et;const{time:e,range:n,seconds:o}=Qe(t),i=r("div","fc-calendar"),a=Array.isArray(t.value)?t.value:[t.value],s=[0,1].map(v=>String(a[v]||"").slice(0,10)),c=[0,1].map(v=>(String(a[v]||"").slice(11,16)||"00:00")+(o?":"+(String(a[v]||"").slice(17,19)||"00"):""));let u=0,m=!1,E=ye(s[0])?new Date(`${s[0]}T12:00:00`):new Date;E=new Date(E.getFullYear(),E.getMonth(),1);const M=r("div","fc-calendar-panel"),p=n&&((yt=t.field.dateOptions)==null?void 0:yt.months)===2?r("div","fc-calendar-panel detail-node-second-month"):void 0;p&&i.classList.add("fc-calendar-two-months");const g=r("div","fc-calendar-inputs"),f=[],y=()=>i.dispatchEvent(new Event("change",{bubbles:!0})),D=r("div","fc-error");D.setAttribute("role","status");const w=()=>{if(s.some(v=>v&&!ye(v)))return"请输入有效日期,格式为 YYYY-MM-DD";if(t.field.required&&!s[0])return"请选择日期";if(n&&!!s[0]!=!!s[1])return"请选择完整的日期范围";if(e&&c.slice(0,n?2:1).some(v=>!(o?/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/:/^([01]\d|2[0-3]):[0-5]\d$/).test(v)))return"请输入有效时间";if(n&&s[0]&&`${s[0]}T${e?c[0]:""}`>`${s[1]}T${e?c[1]:""}`)return"结束日期时间不能早于开始日期时间"},C=()=>{D.textContent=w()||"",D.textContent||y()};for(let v=0;v<(n?2:1);v++){const T=r("input","fc-input fc-calendar-date");T.type="text",T.value=s[v],T.placeholder=n?((kt=(wt=t.field.dateOptions)==null?void 0:wt.rangeLabels)==null?void 0:kt[v])??(v?"结束日期":"开始日期"):"YYYY-MM-DD",T.ariaLabel=n?T.placeholder:t.field.label,T.disabled=t.readonly,T.onfocus=()=>{if(u=v,m=v===1,ye(s[v])){const F=new Date(`${s[v]}T12:00:00`);E=new Date(F.getFullYear(),F.getMonth(),1)}h()},T.addEventListener("change",F=>{if(F.stopPropagation(),s[v]=T.value.trim(),ye(s[v])){const O=new Date(`${s[v]}T12:00:00`);E=new Date(O.getFullYear(),O.getMonth(),1)}h(),C()}),g.append(T),f.push(T)}const N=r("div","fc-calendar-header"),S=r("button","fc-calendar-month");S.type="button",S.ariaLabel="选择年份和月份",S.setAttribute("aria-expanded","false"),S.setAttribute("aria-live","polite");const b=(v,T,F)=>{const O=r("button","fc-calendar-nav");return O.type="button",O.ariaLabel=v,O.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${F?"M10 6l-6 6 6 6M19 6l-6 6 6 6":"M15 6l-6 6 6 6"}"/></svg>`,T>0&&O.classList.add("next"),O.onclick=()=>{E=new Date(E.getFullYear(),E.getMonth()+T,1),h()},O};N.append(b("上一年",-12,!0),b("上个月",-1,!1),S,b("下个月",1,!1),b("下一年",12,!0));const x=r("div","fc-calendar-weekdays");for(const v of["日","一","二","三","四","五","六"])x.append(r("span","",v));const V=r("div","fc-calendar-days");V.setAttribute("role","group"),V.ariaLabel="选择日期";const A=r("div","fc-calendar-period");A.hidden=!0;const z=r("button","fc-calendar-back","‹ 返回选择日期");z.type="button";const j=r("div","fc-calendar-period-columns"),B=r("div","fc-calendar-period-list");B.setAttribute("role","group"),B.ariaLabel="年份";const q=r("div","fc-calendar-period-list");q.setAttribute("role","group"),q.ariaLabel="月份";const P=r("div","fc-calendar-period-list");P.ariaLabel="秒",P.hidden=!0,j.append(B,q,P),A.append(z,j);let R="period",$=0;const U=[],l=(v=!1)=>{const T=c[$].split(":").map(Number),F=R==="period"?[[B,E.getFullYear(),"年"],[q,E.getMonth()+1,"月"]]:[[B,T[0],"时"],[q,T[1],"分"],[P,T[2],"秒"]];for(const[O,G,Z]of F)for(const ne of O.querySelectorAll("button")){const le=Number(ne.dataset.value)===G;ne.classList.toggle("selected",le),ne.setAttribute("aria-pressed",String(le)),ne.textContent=`${R==="time"?se(Number(ne.dataset.value)):ne.dataset.value}${le?Z:""}`,le&&v&&(O.scrollTop=Math.max(0,ne.offsetTop-108))}},d=(v,T)=>{const F=r("button","fc-calendar-period-option",String(v));return F.type="button",F.dataset.value=String(v),F.ariaLabel=`${R==="time"?se(v):v}${R==="time"?T?"时":"分":T?"年":"月"}`,F.disabled=R==="time"&&t.readonly,F.onclick=()=>{if(R==="time"){const O=c[$].split(":");O[T?0:1]=se(v),c[$]=O.join(":"),U[$].textContent=c[$],l(),C();return}E.setFullYear(T?v:E.getFullYear(),T?E.getMonth():v-1,1),l(),h()},F},L=(v,T=0)=>{if(R=v,$=T,B.replaceChildren(),q.replaceChildren(),P.replaceChildren(),P.hidden=v!=="time"||!o,B.ariaLabel=v==="period"?"年份":"小时",q.ariaLabel=v==="period"?"月份":"分钟",v==="period"){for(let F=Math.max(1,E.getFullYear()-100);F<=Math.min(9999,E.getFullYear()+100);F++)B.append(d(F,!0));for(let F=1;F<=12;F++)q.append(d(F,!1))}else{for(let F=0;F<24;F++)B.append(d(F,!0));for(let F=0;F<60;F++)q.append(d(F,!1));if(o)for(let F=0;F<60;F++){const O=r("button","fc-calendar-period-option",se(F));O.type="button",O.dataset.value=String(F),O.ariaLabel=se(F)+"秒",O.disabled=t.readonly,O.onclick=()=>{const G=c[$].split(":");G[2]=se(F),c[$]=G.join(":"),U[$].textContent=c[$],l(),C()},P.append(O)}}i.classList.add("choosing-period"),A.hidden=!1,(v==="period"?S:U[T]).setAttribute("aria-expanded","true"),l(!0),z.focus()};S.onclick=()=>L("period"),z.onclick=()=>{i.classList.remove("choosing-period"),A.hidden=!0;const v=R==="period"?S:U[$];v.setAttribute("aria-expanded","false"),h(),v.focus()},A.addEventListener("keydown",v=>{if(v.key==="Escape"&&(v.preventDefault(),v.stopPropagation(),z.click()),!["ArrowUp","ArrowDown","Home","End"].includes(v.key))return;const T=v.target,F=T.closest(".fc-calendar-period-list");if(!F)return;const O=[...F.querySelectorAll("button")],G=O.indexOf(T),Z=v.key==="Home"?0:v.key==="End"?O.length-1:Math.max(0,Math.min(O.length-1,G+(v.key==="ArrowDown"?1:-1)));v.preventDefault(),O[Z].focus()});function h(){if(S.textContent=`${E.getFullYear()}年 ${E.getMonth()+1}月`,f.forEach((v,T)=>v.classList.toggle("active",T===u)),k(V,E),p){const v=new Date(E.getFullYear(),E.getMonth()+1,1),T=r("div","fc-calendar-header"),F=r("button","fc-calendar-month",`${v.getFullYear()}年 ${v.getMonth()+1}月`);F.type="button",F.ariaLabel="选择下月年份和月份",F.onclick=()=>{E=v,L("period"),h()},T.append(b("上一年",-12,!0),b("上个月",-1,!1),F,b("下个月",1,!1),b("下一年",12,!0));const O=r("div","fc-calendar-days");O.role="group",O.ariaLabel="选择下月日期",p.replaceChildren(T,x.cloneNode(!0),O),k(O,v),W.hidden=!s.some(Boolean)}}function k(v,T){v.replaceChildren();for(let O=0;O<T.getDay();O++)v.append(r("span","fc-calendar-blank"));const F=new Date(T.getFullYear(),T.getMonth()+1,0).getDate();for(let O=1;O<=F;O++){const G=Me(new Date(T.getFullYear(),T.getMonth(),O)),Z=r("button","fc-calendar-day",String(O));Z.type="button",Z.ariaLabel=G,Z.disabled=t.readonly;const ne=s[0]===G||n&&s[1]===G;Z.classList.toggle("selected",ne),Z.setAttribute("aria-pressed",String(ne)),Z.classList.toggle("in-range",n&&!!s[0]&&!!s[1]&&G>s[0]&&G<s[1]),G===Me(new Date)&&(Z.classList.add("today"),Z.setAttribute("aria-current","date")),Z.onclick=()=>{var le,Lt;n?m?(s[1]=G,s[0]&&s[1]<s[0]&&([s[0],s[1]]=[s[1],s[0]]),u=0,m=!1):(s[0]=G,s[1]="",u=1,m=!0):s[0]=G,f.forEach((Wt,Kt)=>Wt.value=s[Kt]),h(),!n||s[1]?C():D.textContent="",(le=i.querySelector(`[aria-label="${G}"]`))==null||le.focus(),(Lt=t.field.dateOptions)!=null&&Lt.collapseOnSelect&&(!n||s[1])&&!w()&&i.dispatchEvent(new Event("fc-collapse",{bubbles:!0}))},v.append(Z)}}M.append(N,x,V,A);const I=r("div","fc-calendar-time");if(e){for(let v=0;v<(n?2:1);v++){const T=r("div","fc-calendar-time-field"),F=n?v?"结束时间":"开始时间":"时间",O=r("button","fc-input fc-calendar-time-trigger",c[v]);O.type="button",O.disabled=t.readonly,O.ariaLabel=F,O.setAttribute("aria-expanded","false"),O.onclick=()=>L("time",v),U.push(O),T.append(r("span","",F),O),I.append(T)}M.append(I)}const W=r("button","fc-calendar-clear","清空");W.type="button",W.disabled=t.readonly,W.onclick=()=>{s.fill(""),f.forEach(v=>v.value=""),u=0,m=!1,h(),C()},i.append(g,M,...p?[p]:[],W,D);const _=()=>{const v=s.slice(0,n?2:1).map((T,F)=>T?T+(e?`T${c[F]}`:""):"");return n?v.some(Boolean)?v:[]:v[0]};if(t.layout==="compact"||t.readonly)return h(),{element:i,read:_,validate:w,focus:()=>{f[0].focus()},deactivate:()=>{i.classList.remove("choosing-period"),A.hidden=!0}};const oe=r("div","fc-date-mirror"),Q=()=>oe.replaceChildren(Xe({...t,value:_()})),te=r("span","fc-field-chevron");te.setAttribute("aria-hidden","true");const K=r("div","fc-date-trigger");K.tabIndex=0,K.setAttribute("role","button"),K.ariaLabel=`编辑${t.field.label}`,K.append(oe,te);let pe;const Ie=(v=!0)=>{const T=pe;pe=void 0;const F=!!T&&T.element.contains(document.activeElement);T==null||T.close(),te.classList.remove("is-open"),v&&F&&queueMicrotask(()=>{pe||!K.isConnected||K.dispatchEvent(new Event("fc-collapse",{bubbles:!0}))})},Pe=()=>{pe||t.readonly||(Q(),pe=ce({anchor:K,content:i,width:p?570:320,align:p?"end":"start",gap:4,onDismiss:()=>{pe=void 0,te.classList.remove("is-open")}}),te.classList.add("is-open"))};return K.onclick=()=>Pe(),K.onkeydown=v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),Pe())},i.addEventListener("focusout",v=>{const T=v.relatedTarget;if(T&&(i.contains(T)||K.contains(T)||ve(T)))return;const F=new Event("focusout",{bubbles:!0});T&&Object.defineProperty(F,"relatedTarget",{value:T}),K.dispatchEvent(F)}),i.addEventListener("change",()=>{Q(),K.dispatchEvent(new Event("change",{bubbles:!0}))}),(Et=t.field.dateOptions)!=null&&Et.collapseOnSelect&&i.addEventListener("fc-collapse",()=>{Ie(!1),K.dispatchEvent(new Event("fc-collapse",{bubbles:!0}))}),h(),Q(),{element:K,content:i,inputRoot:K,read:_,validate:w,focus:()=>{Pe(),f[0].focus()},deactivate:Ie,destroy:Ie}}function Ze(t){var f,y,D;let e=Array.isArray(t.value)?structuredClone(t.value):[];const n=r("div","fc-attachments"),o=r("div","fc-file-list"),i=r("label","fc-upload-zone","+ 上传附件"),a=r("input");a.type="file",a.multiple=!0,a.ariaLabel="上传"+t.field.label,a.accept=((f=t.field.attachmentOptions)==null?void 0:f.accept)||"",a.disabled=t.readonly||!((y=t.services)!=null&&y.upload);const s=r("p","fc-error");s.setAttribute("role","status");const c=r("button","fc-retry","重试上传");c.type="button",c.hidden=!0;let u=[],m=!1,E=!1,M;const p=()=>{o.replaceChildren(),e.forEach((w,C)=>{const N=r("div","fc-file-row"),S=De(w.url),b=S?r("a","fc-link",w.name):r("span","",w.name);if(b.tagName==="A"){const x=b;x.href=S,x.target="_blank",x.rel="noopener noreferrer"}if(N.append(r("span","fc-file-icon","▤"),b),w.size!=null&&N.append(r("small","fc-file-size",Math.ceil(w.size/1024)+" KB")),!t.readonly){const x=r("button","fc-file-remove","×");x.type="button",x.disabled=m,x.ariaLabel="移除"+w.name,x.onclick=()=>{e.splice(C,1),p(),re(n)},N.append(x)}o.append(N)}),e.length||o.append(r("span","fc-empty","暂无附件"))},g=async()=>{var N;if(!((N=t.services)!=null&&N.upload)||t.readonly||m||!u.length)return;const w=t.field.attachmentOptions;if(w!=null&&w.maxFiles&&e.length+u.length>w.maxFiles){s.textContent="最多上传 "+w.maxFiles+" 个文件";return}if(w!=null&&w.maxBytes&&u.some(S=>S.size>w.maxBytes)){s.textContent="文件大小超过限制";return}const C=((w==null?void 0:w.accept)||"").split(",").map(S=>S.trim().toLowerCase()).filter(Boolean);if(C.length&&u.some(S=>!C.some(b=>b.startsWith(".")?S.name.toLowerCase().endsWith(b):b.endsWith("/*")?S.type.toLowerCase().startsWith(b.slice(0,-1)):S.type.toLowerCase()===b))){s.textContent="文件类型不符合要求";return}M=new AbortController,m=!0,a.disabled=!0,c.hidden=!0,s.textContent="上传中…",n.setAttribute("aria-busy","true"),p();try{const S=await t.services.upload(t.field,u,M.signal);if(E)return;if(S.length!==u.length||S.some(b=>!b.id||!b.name))throw new Error("Invalid file references");e=[...e,...S],u=[],s.textContent="",a.value=""}catch{E||(s.textContent="上传失败,已保留原有附件",c.hidden=!1)}finally{E||(m=!1,a.disabled=!1,n.setAttribute("aria-busy","false"),p(),u.length||re(n))}};return a.onchange=w=>{w.stopPropagation(),u=Array.from(a.files||[]),g()},c.onclick=()=>void g(),i.append(a),n.append(o),t.readonly||(n.append(i),(D=t.services)!=null&&D.upload||n.append(r("p","fc-service-note","上传服务未接入"))),n.append(s,c),p(),{element:n,read:()=>structuredClone(e),focus:()=>a.focus(),validate:()=>m?"请等待上传完成":u.length?"请完成或重新选择上传文件":t.field.required&&!e.length?"请上传附件":void 0,destroy:()=>{E=!0,M==null||M.abort()}}}function Te(t){if(t&&typeof t=="object"&&!Array.isArray(t)){const e=t;return{selected:Array.isArray(e.selected)?[...e.selected]:[],counts:{...e.counts},total:e.total}}return{selected:[],counts:{}}}function et(t,e){var q,P;let n=Te(t.value),o=[...n.selected];const i=e==="attitude"?[{id:"like",label:"赞同"}]:ee(t.field),a=r("div","fc-vote"),s=r("button","fc-vote-trigger");s.type="button",s.setAttribute("aria-haspopup","dialog"),s.setAttribute("aria-expanded","false");const c=r("span","fc-vote-icon","+");c.ariaHidden="true";const u=r("span");s.append(c,u);const m=r("section","fc-vote-panel");m.setAttribute("role","dialog"),m.ariaLabel=t.field.label;const E=r("div","fc-vote-header"),M=r("span","fc-vote-total");E.append(r("strong","",e==="attitude"?"表态投票":e==="multi"?"投票-多选":"投票-单选"),M);const p=r("div","fc-vote-list");p.setAttribute("role",e==="multi"?"group":"radiogroup"),p.ariaLabel=t.field.label;const g=r("p","fc-error");g.setAttribute("role","status");const f=r("button","fc-vote-submit","确认投票");f.type="button";const y=r("button","fc-vote-withdraw","撤回投票");y.type="button";const D=r("button","fc-vote-withdraw","重新加载");D.type="button",D.hidden=!0;const w=r("div","fc-vote-actions");w.append(f,y);let C=!1,N=!1,S=!1,b=!((q=t.services)!=null&&q.loadVote),x,V;const A=()=>{var R,$,U;u.textContent=n.selected.length?"已投票":"投票",s.classList.toggle("is-voted",!!n.selected.length),s.ariaLabel=`${t.field.label},${u.textContent}`,M.textContent=N?"加载中…":b?`${n.total??Object.values(n.counts).reduce((l,d)=>l+d,0)}人已投`:"待加载",m.setAttribute("aria-busy",String(C||N)),p.replaceChildren();for(const l of i){const d=r("button","fc-vote-option");d.type="button",d.dataset.value=l.id,d.disabled=t.readonly||C||N||!b||!((R=t.services)!=null&&R.vote)||!!l.disabled;const L=o.includes(l.id);d.classList.toggle("selected",L),d.setAttribute("role",e==="multi"?"checkbox":"radio"),d.setAttribute("aria-checked",String(L));const h=r("span",e==="multi"?"fc-vote-check":"fc-radio-dot");h.ariaHidden="true",d.append(h,r("span","fc-vote-label",l.label)),b&&Object.keys(n.counts).length&&d.append(r("span","fc-vote-count",`${n.counts[l.id]??0} 票`)),d.onclick=()=>{var k;d.disabled||(o=e==="multi"?L?o.filter(I=>I!==l.id):[...o,l.id]:[l.id],A(),(k=p.querySelector(`[data-index="${i.indexOf(l)}"]`))==null||k.focus())},d.dataset.index=String(i.indexOf(l)),p.append(d)}i.length||p.append(r("p","fc-empty","暂无投票选项")),f.disabled=C||N||!b||!(($=t.services)!=null&&$.vote)||!o.length,f.textContent=C?"提交中…":n.selected.length?"确认改票":"确认投票",y.hidden=!n.selected.length,y.disabled=C||N||!b,w.hidden=t.readonly||!((U=t.services)!=null&&U.vote),V==null||V.reposition()};p.onkeydown=R=>{if(!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(R.key))return;const $=[...p.querySelectorAll("button:not(:disabled)")];if(!$.length)return;R.preventDefault(),R.stopPropagation();const U=$.indexOf(document.activeElement),l=R.key==="Home"?0:R.key==="End"?$.length-1:(U+(["ArrowUp","ArrowLeft"].includes(R.key)?-1:1)+$.length)%$.length;$[l].focus(),e!=="multi"&&$[l].click()};const z=()=>{V==null||V.close(),V=void 0},j=async()=>{var R;if(!(!((R=t.services)!=null&&R.loadVote)||N||C)){N=!0,g.textContent="",D.hidden=!0,x=new AbortController,A();try{const $=await t.services.loadVote(t.field,x.signal);if(S||x.signal.aborted)return;n=Te($),o=[...n.selected],b=!0}catch{S||(b=!1,g.textContent="加载失败,请重试",D.hidden=!1)}finally{S||(N=!1,A())}}},B=async R=>{var $;if(!(C||N||!b||t.readonly||!(($=t.services)!=null&&$.vote))){C=!0,g.textContent="",x=new AbortController,A();try{const U=await t.services.vote(t.field,[...R],x.signal);if(S||x.signal.aborted)return;n=Te(U),o=[...n.selected],C=!1,re(a),z(),s.focus()}catch{S||(g.textContent="投票失败,请重试")}finally{S||(C=!1,A())}}};return s.onclick=R=>{if(R.stopPropagation(),V){z();return}o=[...n.selected],g.textContent="",A(),V=ce({anchor:s,anchorMode:"element",content:m,width:360,onDismiss:()=>{V=void 0,s.setAttribute("aria-expanded","false"),C||(o=[...n.selected])},onEscape:()=>s.focus()}),s.setAttribute("aria-expanded","true"),m.tabIndex=-1,m.focus(),j()},f.onclick=()=>{o.length&&B(o)},y.onclick=()=>void B([]),D.onclick=()=>void j(),m.append(E,p,g,D,w),!t.readonly&&!((P=t.services)!=null&&P.vote)&&m.append(r("p","fc-service-note","创建工作项后可投票")),a.append(s),A(),{element:a,content:m,read:()=>structuredClone(n),focus:()=>s.focus(),validate:()=>C?"请等待投票完成":void 0,deactivate:z,destroy:()=>{S=!0,x==null||x.abort(),z()}}}function Pt(t){const e=t.value&&typeof t.value=="object"?t.value:{},n=r("div","fc-location"),i=[["address","地址","text"],["longitude","经度","number"],["latitude","纬度","number"]].map(([s,c,u])=>{const m=r("label","fc-location-part",c),E=r("input","fc-input");return E.type=u,E.value=ae(e[s]),E.disabled=t.readonly,E.ariaLabel=c,E.placeholder=c,u==="number"&&(E.step="any",E.min=s==="longitude"?"-180":"-90",E.max=s==="longitude"?"180":"90"),m.append(E),n.append(m),E}),a=()=>i.every(s=>!s.value)?null:{address:i[0].value,longitude:i[1].value?Number(i[1].value):null,latitude:i[2].value?Number(i[2].value):null};return{element:n,read:a,focus:()=>i[0].focus(),validate:()=>{if(!a())return t.field.required?"请填写位置":void 0;if(i.slice(1).some(s=>s.value===""||!s.checkValidity()))return"请填写有效的经纬度"}}}function qt(t){const e=t.value;return me({...t,value:e&&typeof e=="object"?ae(e.address)||[e.longitude,e.latitude].filter(n=>n!=null).join(", "):""})}function Bt(t,e){const n=r("div","fc-composite"),o=r("div","fc-composite-rows"),i=r("button","fc-composite-add","+ 添加一组");i.type="button";const a=t.field.compositeFields||[],s=[];let c=!1;const u=g=>({...g.value,...Object.fromEntries(g.editors.map(({field:f,editor:y})=>[f.key,y.read()]))}),m=g=>{g.editors.forEach(({editor:f})=>{var y;return(y=f.destroy)==null?void 0:y.call(f)}),g.remove&&(g.remove.onclick=null),g.element.remove()},E=r("p","fc-empty","暂无记录"),M=()=>{s.forEach((g,f)=>{g.legend.textContent="第 "+(f+1)+" 组"}),i.disabled=t.readonly||!a.length||s.length>=(t.field.maxRows||100),s.length?E.remove():o.append(E)},p=g=>{const f=r("fieldset","fc-composite-row"),y=r("legend");f.append(y);const D=a.map(C=>{const N=e(C),S=N.createEditor({...t,field:C,value:g[C.key],readonly:t.readonly||C.editable===!1||!!N.readonly,focusBoundary:void 0,onSelectedOptions:x=>{var V;(V=t.services)!=null&&V.searchOptions&&(C.choices=[...new Map([...ee(C),...x].map(A=>[A.id,A])).values()])}}),b=r("div","fc-composite-field");return b.append(r("label","",C.label+(C.required?" *":"")),S.element),f.append(b),{field:C,editor:S}}),w={value:g,element:f,legend:y,editors:D};if(!t.readonly){const C=r("button","fc-composite-remove","删除此组");C.type="button",C.onclick=()=>{if(c)return;const N=s.indexOf(w);N<0||(m(w),s.splice(N,1),M(),re(n))},w.remove=C,f.append(C)}s.push(w),o.append(f),M()};for(const g of Array.isArray(t.value)?t.value:[])p(structuredClone(g));return i.onclick=()=>{c||i.disabled||(p({}),re(n))},n.append(o),t.readonly||n.append(i),a.length||n.append(r("p","fc-service-note","请配置复合子字段")),M(),{element:n,read:()=>s.map(u),validate:()=>{var g;if(t.field.required&&!s.length)return"请至少添加一组";for(const[f,y]of s.entries())for(const{field:D,editor:w}of y.editors){const C=(g=w.validate)==null?void 0:g.call(w);if(C)return"第 "+(f+1)+" 组 · "+D.label+":"+C}},destroy:()=>{c||(c=!0,i.onclick=null,s.forEach(m))}}}class ie extends X{renderDisplay(e){return{element:Tt(e)}}renderEditing(e){return We("text",e)}}class tt extends ie{renderDisplay(e){return super.renderDisplay({...e,field:{...e.field,kind:"number"}})}renderEditing(e){return We("number",e)}}class nt extends ie{renderDisplay(e){return super.renderDisplay({...e,field:{...e.field,control:"richText"}})}renderEditing(e){return Mt(e)}}class it extends ie{renderDisplay(e){return{element:me(e)}}renderEditing(e){return ge(e,"textarea")}}class Fe extends ie{renderDisplay(e){return{element:Ft(e)}}renderEditing(e){return ge(e,"url")}}class ot extends ie{renderEditing(e){return ge(e,"email")}}class st extends ie{renderEditing(e){return ge(e,"tel")}}class ue extends X{constructor(){super(...arguments);Y(this,"multiple",!1);Y(this,"variant","choice")}renderDisplay(n){return{element:je(n,this.variant==="radio"?"choice":this.variant)}}renderEditing(n){return xe(this.multiple,n,this.variant)}}class at extends ue{constructor(){super(...arguments);Y(this,"multiple",!0)}}class rt extends ue{constructor(){super(...arguments);Y(this,"variant","radio")}renderDisplay(n){return n.layout==="compact"?{element:je(n)}:Ge({...n,readonly:!0})}renderEditing(n){if(n.layout!=="compact")return Ge(n);const o=xe(!1,n,"choice");return n.field.radioValueType!=="boolean"?o:{...o,read:()=>{const i=o.read();return i===""?null:i==="true"}}}}class Re extends ue{constructor(){super(...arguments);Y(this,"variant","person")}}class lt extends Re{constructor(){super(...arguments);Y(this,"multiple",!0)}}class Ne extends ue{constructor(){super(...arguments);Y(this,"variant","relation")}}class dt extends Ne{constructor(){super(...arguments);Y(this,"multiple",!0)}}class Ve extends X{constructor(){super(...arguments);Y(this,"multiple",!1)}renderDisplay(n){return{element:Ht(n)}}renderEditing(n){return $t(this.multiple,n)}}class ct extends Ve{constructor(){super(...arguments);Y(this,"multiple",!0)}}class Oe extends X{normalize(e){return e}renderDisplay(e){return{element:Xe(this.normalize(e))}}renderEditing(e){return It(this.normalize(e))}}class He extends Oe{constructor(){super(...arguments);Y(this,"range",!1)}normalize(n){return{...n,field:{...n.field,dateOptions:{showTime:!1,showRange:this.range,...n.field.dateOptions}}}}}class ut extends He{constructor(){super(...arguments);Y(this,"range",!0)}}class ft extends X{renderDisplay(e){return{element:Rt(e)}}renderEditing(e){return Ke(e)}}class pt extends X{renderDisplay(e){return Ze({...e,readonly:!0})}renderEditing(e){return Ze(e)}}class ht extends X{renderDisplay(e){return{element:qt(e)}}renderEditing(e){return Pt(e)}}class we extends X{constructor(){super(...arguments);Y(this,"mode","attitude")}renderDisplay(n){return et({...n,readonly:!0},this.mode)}renderEditing(n){return et(n,this.mode)}}class mt extends we{constructor(){super(...arguments);Y(this,"mode","single")}}class bt extends we{constructor(){super(...arguments);Y(this,"mode","multi")}}class fe extends X{isReadonly(){return!0}constructor(e){super({...e,readonly:!0})}renderDisplay(e){return{element:Vt(e)}}renderEditing(e){return Ot(e,n=>this.renderDisplay(n).element)}}class $e extends fe{renderDisplay(e){return{element:Nt(e)}}}class vt extends ie{renderDisplay(e){const n=document.createElement("button");return n.type="button",n.className="fc-detail-link",n.textContent=e.field.label,n.onclick=o=>{var i;o.stopPropagation(),(i=e.onAction)==null||i.call(e,{type:"open",value:e.value})},{element:n,destroy:()=>{n.onclick=null}}}}class gt extends X{constructor(e,n){super(e),this.resolve=n}renderDisplay(e){var i;if(e.layout==="compact")return{element:me({...e,value:Array.isArray(e.value)&&e.value.length?e.value.length+" 组记录":""})};const n=document.createElement("div");n.className="fc-composite";const o=[];for(const a of Array.isArray(e.value)?e.value:[]){const s=document.createElement("fieldset");s.className="fc-composite-row";for(const c of e.field.compositeFields??[]){const u=document.createElement("label");u.textContent=c.label;const m={...e,field:c,value:a[c.key],readonly:!0},E=this.resolve(c),M=((i=E.renderView)==null?void 0:i.call(E,m))??{element:E.render(m)};o.push(M),s.append(u,M.element)}n.append(s)}return{element:n,destroy:()=>o.forEach(a=>{var s;return(s=a.destroy)==null?void 0:s.call(a)})}}renderEditing(e){return Bt(e,this.resolve)}}const zt={textarea:"保留换行的纯文本,支持长度限制",radio:"平铺选项,一次选择一项",cascadeSingle:"逐级浏览分类,选择完整路径",cascadeMulti:"逐级浏览并选择多条路径",person:"按姓名搜索,以稳定人员 ID 保存",multiPerson:"按姓名搜索,以稳定人员 ID 保存",date:"日历选择和直接输入,支持清空",dateRange:"连续选择起止日期,校验完整范围",url:"填写网址并在新窗口安全打开",cloudDocument:"添加云文档链接,点击打开原文档",email:"邮箱输入与格式校验",phone:"支持国家区号的电话输入",switch:"以是或否记录布尔状态",attachment:"文件列表、上传与删除,支持上传失败重试",location:"填写地址和经纬度,校验坐标边界",relation:"按名称或编号搜索工作项,点击名称打开详情",multiRelation:"按名称或编号搜索工作项,点击名称打开详情",attitudeVote:"选择并提交投票,结果以宿主服务回读为准",singleVote:"选择并提交投票,结果以宿主服务回读为准",multiVote:"选择并提交投票,结果以宿主服务回读为准",externalSignal:"由外部系统更新,系统内只读",externalMultiSignal:"由外部系统更新,系统内只读",formula:"展示服务端计算结果,不可手工覆盖",aggregate:"展示服务端计算结果,不可手工覆盖",ai:"展示服务端计算结果,不可手工覆盖",system:"展示服务端计算结果,不可手工覆盖",composite:"可重复字段组,复用已注册子控件并逐组校验",multiPersonComposite:"可重复字段组,复用已注册子控件并逐组校验",text:"单行输入,支持清空和必填校验",richText:"紧凑编辑与全屏排版,支持标题、颜色、列表、表格和链接",select:"从字段配置中选择一个选项",multiSelect:"点击标签选择多项,保存为数组",number:"支持小数和负数,空值与零分别保存",dateTime:"日历、时间与日期范围",detail:"由调用方处理关联内容导航"},Yt={title:"text",longText:"richText",status:"select",richtext:"richText",single_select:"select",multi_select:"multiSelect",user:"person",multi_user:"multiPerson",multi_person:"multiPerson",cascade_select:"cascadeSingle",cascade_single:"cascadeSingle",cascade_multi:"cascadeMulti",daterange:"dateRange",date_range:"dateRange",datetime:"dateTime",multi_relation:"multiRelation",attitude_vote:"attitudeVote",single_vote:"singleVote",multi_vote:"multiVote",vote:"attitudeVote",external_signal:"externalSignal",external_multi_signal:"externalMultiSignal",multi_person_composite:"multiPersonComposite",cloud_document:"cloudDocument"},jt=[["text","单行文本",ie,"文本","T"],["richText","富文本",nt,"文本","¶"],["select","单选",ue,"选择","◉"],["multiSelect","多选",at,"选择","☑"],["number","数字",tt,"其他","#"],["dateTime","日期时间",Oe,"日期","◷"],["detail","详情页查看",vt,"关联工作项","↗"],["textarea","多行文本",it,"文本","≡"],["radio","单选按钮",rt,"选择","◉"],["cascadeSingle","级联单选",Ve,"选择","⑂"],["cascadeMulti","级联多选",ct,"选择","⑂"],["person","单选人员",Re,"人员","♙"],["multiPerson","多选人员",lt,"人员","♙"],["date","日期",He,"日期","▦"],["dateRange","日期区间",ut,"日期","▦"],["url","URL 链接",Fe,"其他","↗"],["cloudDocument","关联云文档",Fe,"其他","▤"],["email","邮箱",ot,"其他","@"],["phone","电话",st,"其他","☎"],["switch","开关",ft,"其他","◐"],["attachment","附件",pt,"其他","⌑"],["location","地理位置",ht,"其他","⌖"],["relation","单选关联工作项",Ne,"关联工作项","↗"],["multiRelation","多选关联工作项",dt,"关联工作项","↗"],["attitudeVote","表态投票",we,"投票","♡"],["singleVote","单选投票",mt,"投票","♡"],["multiVote","多选投票",bt,"投票","♡"],["externalSignal","系统外信号",$e,"系统","◌",!0],["externalMultiSignal","多值系统外信号",$e,"系统","◌",!0],["formula","公式计算",fe,"系统","ƒ",!0],["aggregate","聚合计算",fe,"系统","ƒ",!0],["ai","AI 字段",fe,"系统","ƒ",!0],["system","系统字段",fe,"系统","ƒ",!0]];function _t(t=[]){const e=new Map,n=s=>{if(!/^[A-Za-z][\w-]*$/.test(s.id))throw new Error("Invalid control id");if(e.has(s.id))throw new Error(`Control already registered: ${s.id}`);e.set(s.id,s)},o=s=>{const c=s.control||Yt[s.kind||"text"]||s.kind||"text",u=e.get(c);if(!u)throw new Error(`Unknown control: ${c}`);return u},i=s=>o(s.field).create(s),a=s=>{const c=o(s);return{...c,render:u=>c.create(u).render().element,renderView:u=>c.create(u).render(),createEditor:u=>c.create(u).createEditor()}};for(const[s,c,u,m,E,M]of jt)n({id:s,label:c,description:zt[s]||c,glyph:E,group:m,readonly:M,action:s==="detail"?"view":s==="select"||s==="multiSelect"?"select":void 0,create:p=>new u({...p,readonly:M||p.readonly})});for(const[s,c]of[["composite","复合字段"],["multiPersonComposite","多人复合字段"]])n({id:s,label:c,description:"组合多个已注册字段",glyph:"▦",group:"其他",create:u=>new gt(u,a)});return t.forEach(n),{register:n,resolve:o,create:i,list:()=>[...e.values()]}}class Ut extends X{constructor(e,n){super(e),this.control=n}renderDisplay(e){return{element:this.control.render(e)}}renderEditing(e){return this.control.createEditor(e)}}H.ActionField=vt,H.AttachmentField=pt,H.BaseField=X,H.CascadeField=Ve,H.ChoiceField=ue,H.CompositeField=gt,H.ComputedField=fe,H.CustomField=Ut,H.DateField=He,H.DateRangeField=ut,H.DateTimeField=Oe,H.EmailField=ot,H.LinkField=Fe,H.LocationField=ht,H.MultiCascadeField=ct,H.MultiChoiceField=at,H.MultiPersonField=lt,H.MultiRelationField=dt,H.MultiVoteField=bt,H.NumberField=tt,H.PersonField=Re,H.PhoneField=st,H.RadioField=rt,H.RelationField=Ne,H.RichTextField=nt,H.SignalField=$e,H.SingleVoteField=mt,H.SwitchField=ft,H.TextField=ie,H.TextareaField=it,H.VoteField=we,H.closeAllFieldPopups=qe,H.createFieldRegistry=_t,H.openFieldPopup=ce,H.renderContent=Ae,H.sanitizeRichText=he,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});