rowvia 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +29 -9
  2. package/dist/fields.css +1 -0
  3. package/dist/fields.es.js +1913 -0
  4. package/dist/fields.umd.cjs +1 -0
  5. package/dist/rowvia.css +1 -1
  6. package/dist/rowvia.es.js +10659 -10122
  7. package/dist/rowvia.umd.cjs +84 -103
  8. package/dist/types/api.d.ts +1 -1
  9. package/dist/types/components/cells.d.ts +25 -0
  10. package/dist/types/components/detailDialog.d.ts +7 -1
  11. package/dist/types/components/scrollbars.d.ts +10 -0
  12. package/dist/types/contracts/work-item.d.ts +335 -0
  13. package/dist/types/core/clientSideRowModel.d.ts +1 -2
  14. package/dist/types/core/columnModel.d.ts +2 -2
  15. package/dist/types/core/gridHost.d.ts +365 -0
  16. package/dist/types/core/remoteRowModels.d.ts +2 -10
  17. package/dist/types/core/rowNode.d.ts +1 -2
  18. package/dist/types/core/valueService.d.ts +1 -1
  19. package/dist/types/createGrid.d.ts +10 -0
  20. package/dist/types/features/chartService.d.ts +2 -11
  21. package/dist/types/features/columnMenu.d.ts +1 -1
  22. package/dist/types/features/contextMenu.d.ts +2 -13
  23. package/dist/types/features/editService.d.ts +3 -8
  24. package/dist/types/features/exportService.d.ts +3 -2
  25. package/dist/types/features/filterGui.d.ts +1 -1
  26. package/dist/types/features/filterService.d.ts +2 -14
  27. package/dist/types/features/findService.d.ts +1 -1
  28. package/dist/types/features/formulaEditor.d.ts +1 -1
  29. package/dist/types/features/notesService.d.ts +1 -5
  30. package/dist/types/features/overlays.d.ts +1 -1
  31. package/dist/types/features/paginationService.d.ts +1 -2
  32. package/dist/types/features/popupService.d.ts +1 -1
  33. package/dist/types/features/rangeSelection.d.ts +1 -8
  34. package/dist/types/features/rowDragService.d.ts +1 -1
  35. package/dist/types/features/rowGroupPanel.d.ts +1 -1
  36. package/dist/types/features/selectionService.d.ts +1 -1
  37. package/dist/types/features/sideBar.d.ts +2 -5
  38. package/dist/types/features/sortService.d.ts +1 -1
  39. package/dist/types/features/statusBar.d.ts +2 -3
  40. package/dist/types/features/undoRedoService.d.ts +2 -9
  41. package/dist/types/fields/attachment-control.d.ts +2 -0
  42. package/dist/types/fields/base-field.d.ts +62 -0
  43. package/dist/types/fields/cascade-control.d.ts +3 -0
  44. package/dist/types/fields/choice-control.d.ts +8 -0
  45. package/dist/types/fields/composite-control.d.ts +3 -0
  46. package/dist/types/fields/controls.d.ts +19 -0
  47. package/dist/types/{pages/work-items → fields}/date-control.d.ts +1 -1
  48. package/dist/types/fields/field-types.d.ts +114 -0
  49. package/dist/types/fields/index.d.ts +8 -0
  50. package/dist/types/fields/internal/dom.d.ts +1 -0
  51. package/dist/types/fields/internal/focus-boundary.d.ts +7 -0
  52. package/dist/types/fields/internal/interaction.d.ts +23 -0
  53. package/dist/types/fields/internal/lifecycle.d.ts +12 -0
  54. package/dist/types/fields/internal/textarea.d.ts +1 -0
  55. package/dist/types/fields/location-control.d.ts +3 -0
  56. package/dist/types/fields/popup.d.ts +38 -0
  57. package/dist/types/{pages/work-items → fields}/rich-control.d.ts +1 -1
  58. package/dist/types/fields/text-control.d.ts +3 -0
  59. package/dist/types/fields/types.d.ts +185 -0
  60. package/dist/types/fields/value-control.d.ts +12 -0
  61. package/dist/types/fields/vote-control.d.ts +2 -0
  62. package/dist/types/forms/form-conditions.d.ts +29 -0
  63. package/dist/types/forms/form-surface.d.ts +13 -0
  64. package/dist/types/gantt/component.d.ts +5 -4
  65. package/dist/types/gantt/ganttChart.d.ts +7 -7
  66. package/dist/types/gantt/index.d.ts +3 -3
  67. package/dist/types/gantt/scale.d.ts +18 -0
  68. package/dist/types/grid.d.ts +21 -17
  69. package/dist/types/index.d.ts +19 -20
  70. package/dist/types/node-flow/canvas.d.ts +26 -0
  71. package/dist/types/node-flow/card.d.ts +23 -0
  72. package/dist/types/node-flow/cardSections.d.ts +14 -0
  73. package/dist/types/node-flow/component.d.ts +9 -0
  74. package/dist/types/node-flow/contextBar.d.ts +20 -0
  75. package/dist/types/node-flow/demo.d.ts +6 -0
  76. package/dist/types/node-flow/index.d.ts +13 -0
  77. package/dist/types/node-flow/model.d.ts +48 -0
  78. package/dist/types/node-flow/timeline.d.ts +16 -0
  79. package/dist/types/node-flow/types.d.ts +220 -0
  80. package/dist/types/personnel/component.d.ts +3 -2
  81. package/dist/types/personnel/index.d.ts +1 -1
  82. package/dist/types/personnel/render.d.ts +22 -0
  83. package/dist/types/render/headerView.d.ts +1 -1
  84. package/dist/types/render/rowComponent.d.ts +29 -0
  85. package/dist/types/render/rowContext.d.ts +39 -0
  86. package/dist/types/render/rowRenderer.d.ts +6 -73
  87. package/dist/types/shared/dom.d.ts +1 -0
  88. package/dist/types/shared/interaction.d.ts +1 -0
  89. package/dist/types/shared/lifecycle.d.ts +1 -0
  90. package/dist/types/shared/markup.d.ts +5 -0
  91. package/dist/types/shared/state.d.ts +5 -0
  92. package/dist/types/types.d.ts +3 -2
  93. package/dist/types/work-items/action-surface.d.ts +17 -0
  94. package/dist/types/work-items/detail/detail-header.d.ts +23 -0
  95. package/dist/types/work-items/fields/control-base.d.ts +17 -0
  96. package/dist/types/work-items/fields/focus-editor.d.ts +3 -0
  97. package/dist/types/work-items/fields/registry.d.ts +5 -0
  98. package/dist/types/work-items/index.d.ts +19 -0
  99. package/dist/types/work-items/layers.d.ts +19 -0
  100. package/dist/types/work-items/model.d.ts +10 -0
  101. package/dist/types/work-items/selection-bar.d.ts +7 -0
  102. package/dist/types/work-items/style-scope.d.ts +1 -0
  103. package/dist/types/work-items/table/column-panels.d.ts +39 -0
  104. package/dist/types/work-items/table/columns.d.ts +28 -0
  105. package/dist/types/work-items/table/headers.d.ts +10 -0
  106. package/dist/types/work-items/table/table.d.ts +10 -0
  107. package/dist/types/work-items/tabs.d.ts +14 -0
  108. package/dist/types/work-items/toolbar.d.ts +11 -0
  109. package/dist/types/work-items/views/rule-panels.d.ts +28 -0
  110. package/package.json +24 -6
  111. package/dist/types/pages/finance/component.d.ts +0 -2
  112. package/dist/types/pages/finance/data.d.ts +0 -14
  113. package/dist/types/pages/hr/component.d.ts +0 -2
  114. package/dist/types/pages/hr/data.d.ts +0 -21
  115. package/dist/types/pages/index.d.ts +0 -12
  116. package/dist/types/pages/inventory/component.d.ts +0 -2
  117. package/dist/types/pages/inventory/data.d.ts +0 -26
  118. package/dist/types/pages/lifecycle.d.ts +0 -24
  119. package/dist/types/pages/performance/component.d.ts +0 -2
  120. package/dist/types/pages/performance/data.d.ts +0 -33
  121. package/dist/types/pages/server-side/component.d.ts +0 -2
  122. package/dist/types/pages/work-items/config.d.ts +0 -71
  123. package/dist/types/pages/work-items/controls.d.ts +0 -34
  124. package/dist/types/pages/work-items/model.d.ts +0 -72
  125. package/dist/types/pages/work-items/page.d.ts +0 -24
@@ -0,0 +1 @@
1
+ (function(F,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(F=typeof globalThis<"u"?globalThis:F||self,G(F.RowviaFields={}))})(this,function(F){"use strict";var Ht=Object.defineProperty;var Pt=(F,G,ae)=>G in F?Ht(F,G,{enumerable:!0,configurable:!0,writable:!0,value:ae}):F[G]=ae;var O=(F,G,ae)=>Pt(F,typeof G!="symbol"?G+"":G,ae);class G{constructor(){O(this,"cleanups",new Set);O(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,s,i){return e.addEventListener(n,s,i),this.add(()=>e.removeEventListener(n,s,i))}timeout(e,n){if(this.stopped)return 0;const s=window.setTimeout(()=>{i(),this.stopped||e()},n),i=this.add(()=>window.clearTimeout(s));return s}interval(e,n){if(this.stopped)return 0;const s=window.setInterval(()=>{this.stopped||e()},n);return this.add(()=>window.clearInterval(s)),s}destroy(){if(this.stopped)return;this.stopped=!0;const e=[...this.cleanups].reverse();this.cleanups.clear();let n;for(const s of e)try{s()}catch(i){n??(n=i)}if(n!==void 0)throw n}}function ae(t,e,n={},s=[]){const i=new G,a=new Set,o=h=>[...a].some(y=>y.contains(h)),c=new Set,f=new WeakMap,m=h=>{const y=h.target;if(!(y!=null&&y.closest))return;const p=y.closest('button,input,select,textarea,a,[data-action],[contenteditable],[role="button"],[role="tab"],[data-node-id],[data-rowid],[data-viewport],canvas');if(!p||!o(p))return;const E={};for(let u=p;u&&o(u);u=u.parentElement)for(const[L,V]of Object.entries(u.dataset))V!==void 0&&!(L in E)&&(E[L]=V);const D=p;f.has(h)||(f.set(h,{component:e,type:h.type,action:E.action??E.control,value:"value"in p?D.value:void 0,checked:D.type==="checkbox"||D.type==="radio"?D.checked:void 0,data:E,originalEvent:h}),queueMicrotask(()=>b(h)))},b=h=>{var E;const y=f.get(h);if(!y||i.destroyed)return;f.delete(h),(E=n.onInteraction)==null||E.call(n,y);for(const D of[...c])D(y);const p=t.ownerDocument.defaultView.CustomEvent;t.dispatchEvent(new p("rowvia:interaction",{detail:y,bubbles:!0}))},T=h=>{if(i.destroyed||a.has(h))return()=>{};a.add(h);const y=[];for(const p of["click","dblclick","contextmenu","input","change","submit","keydown","pointerdown","pointerup","wheel"])y.push(i.listen(h,p,m,{capture:!0,passive:!0}));return()=>{a.delete(h),y.forEach(p=>p())}};for(const h of[t,...s])T(h);return{addRoot:T,onInteraction(h){return i.destroyed?()=>{}:(c.add(h),()=>{c.delete(h)})},destroy(){i.destroy(),c.clear(),a.clear()}}}const re=new Map;function ve(t,e){if(!t)return!1;const n=e?[e]:[],s=new Set;for(let i=0;i<Math.max(1,n.length);i++)for(const[a,o]of re)if(!(s.has(a)||e&&!n[i].contains(o))){if(a.element.contains(t))return!0;s.add(a),n.push(a.element)}return!1}function Ie(t){for(const[e,n]of[...re])(!t||t.contains(n))&&e.close()}function pe(t){const{anchor:e,content:n,width:s="anchor",gap:i=4,onDismiss:a}=t,o=e.ownerDocument,c=o.defaultView||window,f=t.anchorMode==="element"?e:e.closest(".fc-focus-body")||e,m=o.createElement("div");m.className="rowvia-field-scope rowvia-field-popup-layer";const b=o.createElement("div");b.className="rowvia-field-popup",b.append(n),m.append(b),(o.body||o.documentElement).append(m);let T=!1;const h=()=>{if(T||!m.isConnected)return;const u=f.getBoundingClientRect(),L=o.documentElement.clientWidth||c.innerWidth,V=o.documentElement.clientHeight||c.innerHeight,R=s==="anchor"?u.width+2:s==="auto"?b.getBoundingClientRect().width:s;b.style.width=s==="auto"?"max-content":R+"px";const A=b.getBoundingClientRect().height;let x=u.bottom+i;const I=u.top-i-A;x+A>V-8&&I>=8&&(x=I),x=Math.max(8,Math.min(x,Math.max(8,V-A-8)));const S=Math.max(8,Math.min(t.align==="end"?u.right-R:u.left,Math.max(8,L-R-8)));m.style.top=Math.round(x)+"px",m.style.left=Math.round(S)+"px"},y=()=>{T||(T=!0,Ie(m),re.delete(D),o.removeEventListener("pointerdown",p,!0),o.removeEventListener("keydown",E,!0),c.removeEventListener("resize",h),c.removeEventListener("scroll",h,!0),m.remove(),a==null||a())},p=u=>{const L=u.target;L&&(m.contains(L)||f.contains(L)||e.contains(L)||ve(L,m))||y()},E=u=>{if(u.key!=="Escape"||[...re.keys()][re.size-1]!==D)return;if(u.preventDefault(),u.stopPropagation(),y(),t.onEscape){t.onEscape();return}const L=o.defaultView.CustomEvent;e.dispatchEvent(new L("fc-collapse",{bubbles:!0,detail:{reason:"escape"}}))},D={element:m,reposition:h,close:y};return re.set(D,e),o.addEventListener("pointerdown",p,!0),o.addEventListener("keydown",E,!0),c.addEventListener("resize",h),c.addEventListener("scroll",h,!0),h(),D}const ke=new WeakMap;function ht(t,e){let n=ke.get(t);if(!n){const i=new Set,a=o=>{for(const c of[...i])i.has(c)&&!c.contains(o.target,o)&&c.leave(o)};t.addEventListener("pointerdown",a,!0),t.addEventListener("focusin",a,!0),n={boundaries:i,stop:()=>{t.removeEventListener("pointerdown",a,!0),t.removeEventListener("focusin",a,!0)}},ke.set(t,n)}n.boundaries.add(e);const s=n;return()=>{!s.boundaries.delete(e)||s.boundaries.size||(s.stop(),ke.delete(t))}}class J{constructor(e){O(this,"root");O(this,"destroying",!1);O(this,"feedback");O(this,"options");O(this,"value");O(this,"committedValue");O(this,"state");O(this,"view");O(this,"viewLife",new G);O(this,"life",new G);O(this,"listeners",new Set);O(this,"interactions");O(this,"interactionListeners",new Set);O(this,"mounted",!1);O(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,s;if(this.life.destroyed||!this.element.isConnected||this.state!=="editing")return;const e=this.element.ownerDocument.activeElement;this.element.contains(e)||(s=(n=this.view)==null?void 0:n.content)!=null&&s.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",s){var c;if(this.life.destroyed||this.snapshot.readonly)return;const i=this.value,a=this.snapshot,o=this.beforeInput(e);this.value=(c=this.options.hooks)!=null&&c.beforeInput?this.options.hooks.beforeInput(o,a):o,(n==="api"||!Object.is(e,this.value))&&this.draw(),this.emit("input",n,{previousValue:i,originalEvent:s})}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 s,i,a,o;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=(s=this.view)==null?void 0:s.validate)==null?void 0:i.call(s))||((o=(a=this.options.hooks)==null?void 0:a.validate)==null?void 0:o.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 s=this.event("commit",e,{previousValue:this.committedValue});return!this.beforeCommit(s)||((a=(i=this.options.hooks)==null?void 0:i.beforeCommit)==null?void 0:a.call(i,s))===!1?!1:(this.value=this.read(),this.committedValue=this.value,this.element.removeAttribute("aria-invalid"),this.emit("commit",e,{previousValue:s.previousValue}),this.setState("display",e),!0)}cancel(e="api"){var i,a,o,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 s=this.event("state",e,{previousState:this.state,state:"display",value:this.committedValue});this.state!=="display"&&(!this.beforeStateChange(s)||((c=(o=this.options.hooks)==null?void 0:o.beforeStateChange)==null?void 0:c.call(o,s))===!1)||(this.value=this.committedValue,this.disposeView(),this.state="display",this.draw(),this.emit("cancel",e),s.previousState!=="display"&&this.publish(s))}edit(e="api"){var n,s;this.life.destroyed||(this.setState("editing",e),this.state==="editing"&&((s=(n=this.view)==null?void 0:n.focus)==null||s.call(n)))}setState(e,n="api"){var a,o,c,f;if(this.life.destroyed||e===this.state||e==="editing"&&this.snapshot.readonly)return;const s=this.event("state",n,{previousState:this.state});if(s.state=e,!this.beforeStateChange(s)||((o=(a=this.options.hooks)==null?void 0:a.beforeStateChange)==null?void 0:o.call(a,s))===!1)return;const i=this.state!=="editing"&&e!=="editing"&&!((c=this.options.renderers)!=null&&c.display)&&!((f=this.options.renderers)!=null&&f.hover)&&this.renderHover===J.prototype.renderHover;this.value=this.read(),this.state=e,i&&this.view?this.element.dataset.state=e:this.draw(),this.publish(s)}action(e,n){var i,a;if(this.life.destroyed)return;const s={type:e,value:n};(a=(i=this.options).onAction)==null||a.call(i,s),this.emit("action","api",{action:s})}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 b,T,h,y,p,E,D;if(!this.mounted||this.life.destroyed)return;const e=this.element.ownerDocument.activeElement,n=this.state==="editing"&&!!e&&(!!((b=this.view)!=null&&b.element.contains(e))||!!((h=(T=this.view)==null?void 0:T.content)!=null&&h.contains(e))),s=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,o=typeof a=="function"?a(i):a??{kind:"text",text:this.value==null?"":String(this.value)},c=this.context(),f=()=>this.state==="editing"?this.renderEditing(c):a?Ee(o):this.state==="hover"?this.renderHover(c):this.renderDisplay(c),m={...i,element:this.element,field:this.options.field,content:o,renderDefault:f,input:u=>this.input(u),commit:()=>this.commit(),cancel:()=>this.cancel(),edit:()=>this.edit(),action:(u,L)=>this.action(u,L)};if(this.view=((p=(y=this.options.renderers)==null?void 0:y[this.state])==null?void 0:p.call(y,m))??f(),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=(E=this.view).focus)==null||D.call(E);const u=this.element.ownerDocument.activeElement;if((s==null?void 0:s.start)!=null&&s.end!=null&&(u instanceof HTMLInputElement||u instanceof HTMLTextAreaElement))try{u.setSelectionRange(s.start,s.end)}catch{}}}watch(e){if(this.mounted&&this.state==="editing"){const s=()=>[this.element,e.content,this.options.focusBoundary].filter(i=>!!i);this.viewLife.add(ht(this.element.ownerDocument,{contains:(i,a)=>s().some(o=>a.composedPath().includes(o)||!!i&&o.contains(i)||ve(i,o)),leave:()=>{this.element.isConnected&&this.commit("user")}}))}this.interactions??(this.interactions=ae(this.mounted?this.element:e.element,`field:${this.options.field.key}`,{onInteraction:s=>{var i,a;(a=(i=this.options).onInteraction)==null||a.call(i,s);for(const o of this.interactionListeners)o(s)}}));const n=[...new Set([e.element,e.content].filter(s=>!!s))];for(const s of n)this.viewLife.add(this.interactions.addRoot(s));for(const s of e.inputRoot?[e.inputRoot]:n)for(const i of["input","change"])this.viewLife.listen(s,i,a=>{var o;this.handled.has(a)||(this.handled.add(a),this.input(((o=e.read)==null?void 0:o.call(e))??this.value,"user",a),i==="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,s={}){return{...this.snapshot,type:e,source:n,...s}}emit(e,n,s={}){this.publish(this.event(e,n,s))}publish(e){var i,a,o;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:(o=this.view)==null?void 0:o.element;if(!n)return;const s=n.ownerDocument.defaultView.CustomEvent;n.dispatchEvent(new s(`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(s=>s.element)),{element:e,destroy:()=>n.forEach(s=>{var i;return(i=s.destroy)==null?void 0:i.call(s)})}}function r(t,e="",n){const s=document.createElement(t);return s.className=e,n!==void 0&&(s.textContent=n),s}function He(t,e=312){t.rows=1,t.style.resize="none";const n=()=>{t.style.height="auto";const s=t.scrollHeight;s>0&&(t.style.height=Math.min(s,e)+"px"),t.style.overflowY=s>e?"auto":"hidden"};return t.addEventListener("input",n),t.addEventListener("focus",n),queueMicrotask(n),n}const X=t=>t.choices??(t.options||[]).map(e=>({id:e,label:e})),Pe=["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,s;return((n=X(t).find(i=>i.id===e))==null?void 0:n.color)||((s=t.colors)==null?void 0:s[e])||Pe[Math.max(0,X(t).findIndex(i=>i.id===e))%Pe.length]},$e=t=>(Array.isArray(t)?t:t==null||t===""?[]:[t]).map(String);function mt(t,e){var n;return((n=X(t).find(s=>s.id===e))==null?void 0:n.label)||e}function bt(t,e="choice"){const n=r("div","fc-tags");for(const s of $e(t.value)){const i=mt(t.field,s),a=r(e==="relation"?"button":"span","fc-tag fc-tag--"+e);e==="choice"&&(a.style.backgroundColor=Le(t.field,s)),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=o=>{var c;o.stopPropagation(),(c=t.onAction)==null||c.call(t,{type:"open",value:s})}),n.append(a)}return n.children.length||n.append(r("span","fc-empty","待填")),n}function Oe(t,e,n="choice"){var l;const s=r("div","fc-choice fc-choice--"+n);let i=$e(e.value).slice(0,t?void 0:1);const a=new Map(X(e.field).map(d=>[d.id,d]));let o=X(e.field);const c=t&&(e.field.maxSelections??0)>0?e.field.maxSelections:1/0,f=r("select","fc-select");f.hidden=!0,f.multiple=t,f.disabled=e.readonly,f.required=!!e.field.required,f.ariaLabel=e.field.label;const m=r("div","fc-choice-head"),b=r("div","fc-choice-selection"),T=r("span","fc-empty fc-choice-placeholder","待填"),h=r("input","fc-choice-search");h.placeholder="",h.autocomplete="off",h.ariaLabel="输入以搜索"+e.field.label,h.disabled=e.readonly;const y=()=>{h.size=Math.max(1,[...h.value].length+1)};y();const p=r("div","fc-option-list");p.setAttribute("role",n==="radio"?"radiogroup":"group"),p.ariaLabel=e.field.label;const E=r("div","fc-error fc-choice-feedback");E.setAttribute("role","status");const D=r("div","fc-picker-status");D.setAttribute("role","status");const u=r("button","fc-retry","重试");u.type="button",u.hidden=!0;let L,V=0,R=!1,A=!1;const x=n!=="radio"&&!!((l=e.services)!=null&&l.searchOptions),I=n!=="radio"&&e.layout!=="compact"&&!e.readonly;let S;const z=()=>{const d=S;S=void 0,d==null||d.close()},$=()=>{!I||R||S||e.readonly||(S=pe({anchor:m,content:p,width:"anchor",onDismiss:()=>{S=void 0}}))},B=()=>{!I||!S||(z(),s.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))},q=()=>{var d;(d=e.onSelectedOptions)==null||d.call(e,i.map(w=>a.get(w)).filter(w=>!!w)),s.dispatchEvent(new Event("change",{bubbles:!0}))},P=()=>{var d;if(f.replaceChildren(),!t){const w=r("option");w.value="",f.append(w)}for(const w of new Set([...o.map(v=>v.id),...i])){const v=r("option","",((d=a.get(w))==null?void 0:d.label)||w);v.value=w,v.selected=i.includes(w),f.append(v)}t||(f.value=i[0]||"")},j=()=>{b.replaceChildren(),p.replaceChildren(),P(),!i.length&&!h.value&&b.append(T);for(const v of i){const k=a.get(v),H=r("span","fc-tag fc-tag--"+n);(n==="choice"||n==="radio")&&(H.style.backgroundColor=Le(e.field,v)),n==="person"&&H.append(r("span","fc-avatar",((k==null?void 0:k.label)||v).slice(0,1))),H.append(r("span","fc-tag-label",((k==null?void 0:k.label)||v)+(k!=null&&k.disabled?"(已停用)":"")));const K=r("span","fc-tag-slot"),Y=r("button","fc-choice-remove","×");Y.type="button",Y.disabled=e.readonly,Y.ariaLabel="移除"+((k==null?void 0:k.label)||v),Y.onclick=Q=>{Q.stopPropagation(),i=i.filter(_=>_!==v),E.textContent="",j(),h.focus(),q()},K.append(Y),H.append(K),b.append(H)}const d=h.value.trim().toLocaleLowerCase(),w=o.filter(v=>!v.disabled&&(x||(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 H=i.includes(v.id);k.classList.toggle("selected",H),k.setAttribute(n==="radio"?"aria-checked":"aria-pressed",String(H)),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 Y=r("span","fc-option-copy");Y.append(K),v.description&&Y.append(r("small","fc-option-description",v.description)),k.append(Y,r("span","fc-option-mark",H?"✓":"")),k.onclick=Q=>{if(Q.stopPropagation(),!e.readonly){if(!t)i=[v.id];else if(H)i=i.filter(_=>_!==v.id);else{const _=v.exclusive?[]:i.filter(Z=>{var se;return!((se=a.get(Z))!=null&&se.exclusive)});if(_.length>=c){E.textContent="最多可选择 "+c+" 项";return}i=[..._,v.id]}E.textContent="",t||(h.value="",y()),j(),p.querySelectorAll("button").forEach(_=>{_.dataset.value===v.id&&_.focus()}),q(),!t&&I&&B()}},p.append(k)}!w.length&&!A&&p.append(r("p","fc-empty fc-choice-empty","暂无匹配选项"))},U=async()=>{L==null||L.abort();const d=++V;L=new AbortController,A=!0,u.hidden=!0,D.textContent="加载中…",s.setAttribute("aria-busy","true"),j();try{const w=await e.services.searchOptions(e.field,h.value.trim(),L.signal);if(R||d!==V)return;o=w,w.forEach(v=>a.set(v.id,v)),D.textContent=""}catch{if(R||d!==V)return;o=[],D.textContent="加载失败,请重试",u.hidden=!1}finally{!R&&d===V&&(A=!1,s.setAttribute("aria-busy","false"),j())}};h.oninput=()=>{y(),x?U():j()},h.onfocus=()=>$(),m.onclick=d=>{d.target.closest("button")||h.focus()},u.onclick=()=>void U();const W=d=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Home","End"].includes(d.key))return;const w=[...p.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(p.onkeydown=W,h.onkeydown=d=>{d.key==="ArrowDown"&&($(),W(d))},f.onchange=()=>{i=[...f.selectedOptions].map(d=>d.value).filter(Boolean),j()},m.append(b),n!=="radio"&&m.append(h),I){const d=r("span","fc-field-chevron");d.setAttribute("aria-hidden","true"),m.append(d),s.append(f,m,D,u,E)}else s.append(f,m,D,p,u,E);return j(),x&&!e.readonly&&U(),{element:s,content:I?p: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=p.querySelector("button"))==null||d.focus();return}h.focus(),$()},deactivate:()=>{h.value="",y(),z()},destroy:()=>{R=!0,++V,L==null||L.abort(),z()}}}const vt=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(" ")),qe=t=>/^(https?:\/\/|mailto:)/i.test(t.trim());function he(t){const e=document.createElement("template");e.innerHTML=String(t??"");const n=s=>{for(const i of[...s.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),!vt.has(a.tagName)){a.replaceWith(...a.childNodes);continue}if(a.tagName==="INPUT"&&a.getAttribute("type")!=="checkbox"){a.remove();continue}const o=a.getAttribute("href")||"",c=a.getAttribute("src")||"",f=a.getAttribute("alt")||"",m=a.getAttribute("data-person-id"),b=a.hasAttribute("checked"),T=a.getAttribute("data-task")==="true",h=["color","background-color","text-align","margin-left","font-weight","font-style","text-decoration-line"].map(p=>[p,a.style.getPropertyValue(p)]),y=a.tagName==="FONT"?a.getAttribute("color"):null;for(const p of[...a.attributes])a.removeAttribute(p.name);for(const[p,E]of h)(p==="color"||p==="background-color"?/^(#[a-f\d]{3,8}|rgba?\([\d.,%\s]+\)|[a-z]+)$/i.test(E):p==="text-align"?/^(left|center|right|justify)$/.test(E):p==="margin-left"?/^\d{1,3}px$/.test(E):/^(bold|normal|italic|underline|line-through|[1-9]00)$/.test(E))&&a.style.setProperty(p,E);if(y&&/^(#[a-f\d]{3,8}|[a-z]+)$/i.test(y)&&(a.style.color=y),a.tagName==="A"&&qe(o)&&(a.setAttribute("href",o.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",f),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"),b&&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 gt(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 s=r("div","fc-rich-tools");n.append(s);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 o=null,c=!1,f=[i.innerHTML],m=0,b=!1,T=null,h,y;const p=()=>{const l=window.getSelection();l!=null&&l.rangeCount&&i.contains(l.anchorNode)&&i.contains(l.focusNode)&&(o=l.getRangeAt(0).cloneRange())},E=()=>{i.focus();const l=window.getSelection();if(!l)return;const d=o&&i.contains(o.commonAncestorContainer)?o:document.createRange();d!==o&&(d.selectNodeContents(i),d.collapse(!1)),l.removeAllRanges(),l.addRange(d),o=d},D=()=>{var d;const l=y;y=void 0,l==null||l.close(),(d=h==null?void 0:h.destroy)==null||d.call(h),h=void 0,a.hidden=!0,a.replaceChildren()},u=new Map,L=()=>{var l;u.get("撤销").disabled=t.readonly||m===0,u.get("重做").disabled=t.readonly||m===f.length-1;for(const[d,w]of[["加粗","bold"],["斜体","italic"],["下划线","underline"],["删除线","strikeThrough"],["有序列表","insertOrderedList"],["无序列表","insertUnorderedList"]]){const v=u.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))}},V=()=>{b||(i.innerHTML!==f[m]&&(f=f.slice(0,m+1),f.push(i.innerHTML),f.length>100&&f.shift(),m=f.length-1),p(),L())},R=()=>{V(),i.dispatchEvent(new Event("change",{bubbles:!0}))},A=l=>{const d=m+l;d<0||d>=f.length||(m=d,b=!0,i.innerHTML=f[m],o=null,E(),b=!1,L(),i.dispatchEvent(new Event("change",{bubbles:!0})))},x=(l,d)=>{t.readonly||(E(),document.execCommand(l,!1,d),p(),D(),R())},I=l=>{if(t.readonly)return;E();const d=window.getSelection().getRangeAt(0);d.deleteContents(),d.insertNode(l),d.setStartAfter(l),d.collapse(!0),o=d.cloneRange(),D(),R()},S=(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=H=>{H.preventDefault(),p()},k.onclick=H=>{H.stopPropagation(),w()},s.append(k),u.set(l,k),k},z=(l,d)=>{if(!t.readonly){if(p(),!a.hidden&&a.ariaLabel===l){D();return}D(),a.className="fc-rich-menu",a.ariaLabel=l,a.hidden=!1,y=pe({anchor:u.get(l),anchorMode:"element",content:a,width:"auto",onDismiss:D,onEscape:E}),d(),y==null||y.reposition()}},$=(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};S("撤销","undo",()=>A(-1),!1),S("重做","redo",()=>A(1),!1),S("格式刷","paint",()=>{p();const l=o==null?void 0:o.startContainer,d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;!d||!i.contains(d)||(T={tag:/^(B|STRONG|I|EM|U|S)$/.test(d.tagName)?d.tagName.toLowerCase():"span",css:d.getAttribute("style")||""},u.get("格式刷").classList.add("active"))}),S("正文样式","Aa⌄",()=>z("正文样式",()=>{for(const[l,d]of[["正文","p"],["标题 1","h1"],["标题 2","h2"],["标题 3","h3"],["标题 4","h4"],["标题 5","h5"]])$(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,w]of[["文字颜色","A⌄","foreColor"],["背景高亮","▰⌄","hiliteColor"]])S(l,d,()=>z(l,()=>{a.classList.add("fc-rich-colors");for(const v of B){const k=$(v,()=>x(w,v));k.textContent="",k.style.backgroundColor=v,k.ariaLabel=`${l} ${v}`}$("清除",()=>x(w,w==="foreColor"?"#1f2329":"transparent"))}));for(const[l,d,w]of[["加粗","B","bold"],["斜体","I","italic"],["下划线","U","underline"],["删除线","S","strikeThrough"]])S(l,d,()=>x(w));S("对齐","☰⌄",()=>z("对齐",()=>{for(const[l,d]of[["左对齐","justifyLeft"],["居中对齐","justifyCenter"],["右对齐","justifyRight"],["两端对齐","justifyFull"]])$(l,()=>x(d))})),S("有序列表","1≡",()=>x("insertOrderedList")),S("无序列表","•≡",()=>x("insertUnorderedList")),S("任务列表","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),I(d)}),S("引用","quote",()=>x("formatBlock","blockquote")),S("缩进","indent",()=>z("缩进",()=>{$("增加缩进",()=>x("indent")),$("减少缩进",()=>x("outdent"))})),S("分隔线","line",()=>I(r("hr"))),S("表格","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=H=>H.preventDefault(),k.onmouseenter=()=>{l.textContent=`${w} × ${v}`,d.querySelectorAll("button").forEach(H=>H.classList.toggle("active",Number(H.dataset.row)<=w&&Number(H.dataset.col)<=v))},k.onclick=()=>{const H=r("table"),K=r("tbody");for(let Q=0;Q<w;Q++){const _=r("tr");for(let Z=0;Z<v;Z++){const se=r("td");se.append(r("br")),_.append(se)}K.append(_)}H.append(K),I(H);const Y=document.createRange();Y.selectNodeContents(H.querySelector("td")),Y.collapse(!0),o=Y,E()},d.append(k)}}));const q=()=>z("链接",()=>{const l=r("input","fc-input");l.ariaLabel="链接文本",l.placeholder="输入文本",l.value=(o==null?void 0:o.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(!qe(k)){w.textContent="请输入 http、https 或 mailto 链接";return}const H=r("a","",l.value||k);H.href=k,H.target="_blank",H.rel="noopener noreferrer",I(H)},a.append(r("span","","文本"),l,r("span","","链接"),d,w,v),l.focus()});S("链接","link",q),S("插入图片","▧",()=>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",I(k)},a.append(l,d,w,v),l.focus()})),S("提及人员","@",()=>z("提及人员",()=>{var d;const l=Oe(!1,{...t,value:"",field:{...t.field,label:"人员"}},"person");h=l,a.append(l.element),l.element.addEventListener("change",w=>{var H,K;w.stopPropagation();const v=String(l.read());if(!v)return;const k=r("span","","@"+(((H=X(t.field).find(Y=>Y.id===v))==null?void 0:H.label)||((K=l.element.querySelector("option:checked"))==null?void 0:K.textContent)||v));k.dataset.personId=v,k.contentEditable="false",I(k)}),(d=l.focus)==null||d.call(l)})),S("代码块","{ }",()=>x("formatBlock","pre")),S("表情","☺",()=>z("表情",()=>{a.classList.add("fc-rich-emojis");for(const l of["😀","😊","😂","👍","👏","🎉","❤️","🔥","✅","💡","🚀","👀","🤔","🙏","💪","⭐"])$(l,()=>I(document.createTextNode(l)))}));const P=S("全屏编辑","expand",()=>{p(),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">${Ce[c?"collapse":"expand"]}</svg>`,E()},!1);P.disabled=!1,P.classList.add("fc-rich-expand"),n.append(P);const j=()=>{for(const l of s.children)l.inert=l.offsetTop>=s.clientHeight},U=typeof ResizeObserver>"u"?void 0:new ResizeObserver(j);U==null||U.observe(s);const W=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)&&E())};return e.addEventListener("mousedown",W),a.addEventListener("mousedown",W),i.addEventListener("input",V),i.addEventListener("mouseup",()=>{if(p(),L(),T&&o&&!o.collapsed){const l=o,d=r(T.tag);d.style.cssText=T.css,d.append(l.extractContents()),l.insertNode(d),T=null,u.get("格式刷").classList.remove("active"),R()}}),i.addEventListener("keyup",()=>{p(),L()}),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),R()}D()}),i.addEventListener("drop",l=>l.preventDefault()),i.addEventListener("paste",l=>{var w,v;if(t.readonly){l.preventDefault();return}l.preventDefault(),p();const d=(w=l.clipboardData)==null?void 0:w.getData("text/html");if(d){const k=document.createElement("template");k.innerHTML=he(d);const H=k.content,K=document.createTextNode("");H.append(K),E();const Y=window.getSelection().getRangeAt(0);Y.deleteContents(),Y.insertNode(H),Y.setStartAfter(K),Y.collapse(!0),o=Y.cloneRange(),R()}else I(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(),D(),E()):l.key==="Escape"&&c?(l.preventDefault(),l.stopPropagation(),P.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(),p(),q())}),e.append(n,i),L(),{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:()=>{U==null||U.disconnect(),D()}}}const Be=t=>t==null?"":String(t);function yt(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 s=t.field.numberOptions;e.textContent=t.value.toLocaleString("zh-CN",{useGrouping:(s==null?void 0:s.thousandsSeparator)??!1,maximumFractionDigits:(s==null?void 0:s.decimals)??10})+((s==null?void 0:s.suffix)||""),e.classList.add("fc-plain")}else e.textContent=Be(t.value),e.classList.add("fc-plain");return(n=e.textContent)!=null&&n.trim()||(e.textContent="待填",e.classList.add("fc-empty")),e}function je(t,e){const s=t==="text"&&e.layout!=="compact"?r("textarea","fc-input fc-textarea"):r("input","fc-input");if(s instanceof HTMLInputElement&&(s.type=t),s.value=Be(e.value),s.disabled=e.readonly,s.required=!!e.field.required,s.ariaLabel=e.field.label,s.placeholder=e.field.placeholder||(e.layout!=="compact"?"待填":`请输入${e.field.label}`),e.field.maxLength!==void 0&&(s.maxLength=e.field.maxLength),t==="number"&&s instanceof HTMLInputElement){const i=e.field.numberOptions;s.step=String((i==null?void 0:i.step)??"any"),(i==null?void 0:i.min)!==void 0&&(s.min=String(i.min)),(i==null?void 0:i.max)!==void 0&&(s.max=String(i.max))}return s instanceof HTMLTextAreaElement&&He(s),t==="text"&&e.layout!=="compact"&&s.addEventListener("keydown",i=>{i.key==="Enter"&&(i.preventDefault(),s.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))}),{element:s,read:()=>t==="number"?s.value===""?null:Number(s.value):s.value,validate:()=>e.field.required&&!s.value.trim()?"此项必填":s.checkValidity()?void 0:s.validationMessage||"请填写有效值",focus:()=>s.focus()}}const _e=t=>!Array.isArray(t)||!t.length?[]:Array.isArray(t[0])?t.map(e=>e.map(String)):[t.map(String)];function me(t,e){const n=[];for(const s of e){const i=t.find(a=>a.id===s);n.push((i==null?void 0:i.label)||s),t=(i==null?void 0:i.children)||[]}return n.join(" / ")}function wt(t){const e=r("div","fc-tags");for(const n of _e(t.value)){const s=r("span","fc-tag");s.append(r("span","fc-tag-label",me(X(t.field),n))),e.append(s)}return e.children.length||e.append(r("span","fc-empty","待填")),e}function kt(t,e){const n=r("div","fc-cascade"),s=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 o=r("div","fc-cascade-columns"),c=r("div","fc-error");c.setAttribute("role","status");const f=X(e.field);let m=_e(e.value),b=[];const T=[],h=(A,x,I=!1)=>A.forEach(S=>{var z;(z=S.children)!=null&&z.length?h(S.children,[...x,S.id],I||!!S.disabled):T.push({path:[...x,S.id],disabled:I||!!S.disabled})});h(f,[]);const y=(A,x)=>JSON.stringify(A)===JSON.stringify(x),p=e.layout!=="compact"&&!e.readonly;let E;const D=()=>{const A=E;E=void 0,A==null||A.close()},u=()=>{!p||E||e.readonly||(E=pe({anchor:i.parentElement||n,content:o,width:"anchor",gap:4,onDismiss:()=>{E=void 0}}))},L=()=>{!p||!E||(D(),n.dispatchEvent(new Event("fc-collapse",{bubbles:!0})))},V=A=>{if(e.readonly)return;const x=m.findIndex(I=>y(I,A));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,A]:[A]}c.textContent="",R(),n.dispatchEvent(new Event("change",{bubbles:!0})),t||L()},R=()=>{var S,z;if(s.replaceChildren(),o.replaceChildren(),m.forEach($=>{const B=r("span","fc-tag");B.append(r("span","fc-tag-label",me(f,$)));const q=r("span","fc-tag-slot"),P=r("button","fc-choice-remove","×");P.type="button",P.disabled=e.readonly,P.ariaLabel="移除"+me(f,$),P.onclick=()=>{m=m.filter(j=>!y($,j)),R(),n.dispatchEvent(new Event("change",{bubbles:!0}))},q.append(P),B.append(q),s.append(B)}),i.value.trim()){const $=T.filter(B=>!B.disabled&&me(f,B.path).toLocaleLowerCase().includes(i.value.trim().toLocaleLowerCase()));for(const{path:B}of $){const q=r("button","fc-option",me(f,B));q.type="button",q.disabled=e.readonly,q.setAttribute("aria-pressed",String(m.some(P=>y(P,B)))),q.onclick=()=>V(B),o.append(q)}o.classList.add("is-search"),$.length||o.append(r("p","fc-empty","暂无匹配路径"));return}o.classList.remove("is-search");let A=f,x=[],I=0;for(;A.length;){const $=r("div","fc-cascade-column");$.setAttribute("role","group"),$.ariaLabel="第"+(I+1)+"级";for(const q of A.filter(P=>!P.disabled)){const P=[...x,q.id],j=!!((S=q.children)!=null&&S.length),U=r("button","fc-option",q.label+(j?" ›":""));U.type="button",U.disabled=e.readonly,U.classList.toggle("selected",j?b[I]===q.id:m.some(W=>y(W,P))),U.setAttribute(j?"aria-expanded":"aria-pressed",String(j?b[I]===q.id:m.some(W=>y(W,P)))),U.onclick=()=>{var W,l;j?(b=P,R(),(l=(W=o.lastElementChild)==null?void 0:W.querySelector("button"))==null||l.focus()):V(P)},$.append(U)}o.append($);const B=A.find(q=>q.id===b[I]&&!q.disabled);if(!((z=B==null?void 0:B.children)!=null&&z.length))break;x=[...x,B.id],A=B.children,I++}f.length||o.append(r("p","fc-empty","暂无可选分类"))};if(i.oninput=()=>{a(),R()},i.onfocus=u,o.onkeydown=A=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(A.key))return;const x=A.target,S=[...(x.closest(".fc-cascade-column")||o).querySelectorAll("button:not(:disabled)")];if(!S.length)return;A.preventDefault();const z=S.indexOf(x);S[A.key==="Home"?0:A.key==="End"?S.length-1:(z+(A.key==="ArrowDown"?1:-1)+S.length)%S.length].focus()},n.append(s,i,c),p){const A=r("span","fc-field-chevron");A.setAttribute("aria-hidden","true"),n.append(A),n.addEventListener("click",()=>u())}else n.append(o);return R(),{element:n,content:p?o:void 0,read:()=>t?m.map(A=>[...A]):[...m[0]||[]],focus:()=>{i.focus(),u()},deactivate:()=>{i.value="",a(),D()},destroy:()=>D(),validate:()=>e.field.required&&!m.length?"请选择分类":void 0}}const ie=t=>String(t).padStart(2,"0"),Ae=t=>`${t.getFullYear()}-${ie(t.getMonth()+1)}-${ie(t.getDate())}`;function ge(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())&&Ae(n)===t}const ze=t=>{var e,n,s;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:((s=t.field.dateOptions)==null?void 0:s.showSeconds)??t.field.kind==="datetime"}};function Ye(t){const{time:e,range:n,seconds:s}=ze(t),a=(Array.isArray(t.value)?t.value:[t.value]).slice(0,n?2:1).filter(Boolean).map(o=>e?String(o).slice(0,s?19:16).replace("T"," "):String(o).slice(0,10)).join(" 至 ");return r("div",`fc-value fc-${t.className||""}${a?"":" fc-empty"}`,a||"待填")}function Et(t){const{time:e,range:n,seconds:s}=ze(t),i=r("div","fc-calendar"),a=Array.isArray(t.value)?t.value:[t.value],o=[0,1].map(g=>String(a[g]||"").slice(0,10)),c=[0,1].map(g=>(String(a[g]||"").slice(11,16)||"00:00")+(s?":"+(String(a[g]||"").slice(17,19)||"00"):""));let f=0,m=!1,b=ge(o[0])?new Date(`${o[0]}T12:00:00`):new Date;b=new Date(b.getFullYear(),b.getMonth(),1);const T=r("div","fc-calendar-panel"),h=r("div","fc-calendar-inputs"),y=[],p=()=>i.dispatchEvent(new Event("change",{bubbles:!0})),E=r("div","fc-error");E.setAttribute("role","status");const D=()=>{if(o.some(g=>g&&!ge(g)))return"请输入有效日期,格式为 YYYY-MM-DD";if(t.field.required&&!o[0])return"请选择日期";if(n&&!!o[0]!=!!o[1])return"请选择完整的日期范围";if(e&&c.slice(0,n?2:1).some(g=>!(s?/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/:/^([01]\d|2[0-3]):[0-5]\d$/).test(g)))return"请输入有效时间";if(n&&o[0]&&`${o[0]}T${e?c[0]:""}`>`${o[1]}T${e?c[1]:""}`)return"结束日期时间不能早于开始日期时间"},u=()=>{E.textContent=D()||"",E.textContent||p()};for(let g=0;g<(n?2:1);g++){const M=r("input","fc-input fc-calendar-date");M.type="text",M.value=o[g],M.placeholder=n?g?"结束日期":"开始日期":"YYYY-MM-DD",M.ariaLabel=n?M.placeholder:t.field.label,M.disabled=t.readonly,M.onfocus=()=>{if(f=g,m=g===1,ge(o[g])){const C=new Date(`${o[g]}T12:00:00`);b=new Date(C.getFullYear(),C.getMonth(),1)}w()},M.addEventListener("change",C=>{if(C.stopPropagation(),o[g]=M.value.trim(),ge(o[g])){const N=new Date(`${o[g]}T12:00:00`);b=new Date(N.getFullYear(),N.getMonth(),1)}w(),u()}),h.append(M),y.push(M)}const L=r("div","fc-calendar-header"),V=r("button","fc-calendar-month");V.type="button",V.ariaLabel="选择年份和月份",V.setAttribute("aria-expanded","false"),V.setAttribute("aria-live","polite");const R=(g,M,C)=>{const N=r("button","fc-calendar-nav");return N.type="button",N.ariaLabel=g,N.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${C?"M10 6l-6 6 6 6M19 6l-6 6 6 6":"M15 6l-6 6 6 6"}"/></svg>`,M>0&&N.classList.add("next"),N.onclick=()=>{b=new Date(b.getFullYear(),b.getMonth()+M,1),w()},N};L.append(R("上一年",-12,!0),R("上个月",-1,!1),V,R("下个月",1,!1),R("下一年",12,!0));const A=r("div","fc-calendar-weekdays");for(const g of["日","一","二","三","四","五","六"])A.append(r("span","",g));const x=r("div","fc-calendar-days");x.setAttribute("role","group"),x.ariaLabel="选择日期";const I=r("div","fc-calendar-period");I.hidden=!0;const S=r("button","fc-calendar-back","‹ 返回选择日期");S.type="button";const z=r("div","fc-calendar-period-columns"),$=r("div","fc-calendar-period-list");$.setAttribute("role","group"),$.ariaLabel="年份";const B=r("div","fc-calendar-period-list");B.setAttribute("role","group"),B.ariaLabel="月份";const q=r("div","fc-calendar-period-list");q.ariaLabel="秒",q.hidden=!0,z.append($,B,q),I.append(S,z);let P="period",j=0;const U=[],W=(g=!1)=>{const M=c[j].split(":").map(Number),C=P==="period"?[[$,b.getFullYear(),"年"],[B,b.getMonth()+1,"月"]]:[[$,M[0],"时"],[B,M[1],"分"],[q,M[2],"秒"]];for(const[N,te,ue]of C)for(const ne of N.querySelectorAll("button")){const fe=Number(ne.dataset.value)===te;ne.classList.toggle("selected",fe),ne.setAttribute("aria-pressed",String(fe)),ne.textContent=`${P==="time"?ie(Number(ne.dataset.value)):ne.dataset.value}${fe?ue:""}`,fe&&g&&(N.scrollTop=Math.max(0,ne.offsetTop-108))}},l=(g,M)=>{const C=r("button","fc-calendar-period-option",String(g));return C.type="button",C.dataset.value=String(g),C.ariaLabel=`${P==="time"?ie(g):g}${P==="time"?M?"时":"分":M?"年":"月"}`,C.disabled=P==="time"&&t.readonly,C.onclick=()=>{if(P==="time"){const N=c[j].split(":");N[M?0:1]=ie(g),c[j]=N.join(":"),U[j].textContent=c[j],W(),u();return}b.setFullYear(M?g:b.getFullYear(),M?b.getMonth():g-1,1),W(),w()},C},d=(g,M=0)=>{if(P=g,j=M,$.replaceChildren(),B.replaceChildren(),q.replaceChildren(),q.hidden=g!=="time"||!s,$.ariaLabel=g==="period"?"年份":"小时",B.ariaLabel=g==="period"?"月份":"分钟",g==="period"){for(let C=Math.max(1,b.getFullYear()-100);C<=Math.min(9999,b.getFullYear()+100);C++)$.append(l(C,!0));for(let C=1;C<=12;C++)B.append(l(C,!1))}else{for(let C=0;C<24;C++)$.append(l(C,!0));for(let C=0;C<60;C++)B.append(l(C,!1));if(s)for(let C=0;C<60;C++){const N=r("button","fc-calendar-period-option",ie(C));N.type="button",N.dataset.value=String(C),N.ariaLabel=ie(C)+"秒",N.disabled=t.readonly,N.onclick=()=>{const te=c[j].split(":");te[2]=ie(C),c[j]=te.join(":"),U[j].textContent=c[j],W(),u()},q.append(N)}}i.classList.add("choosing-period"),I.hidden=!1,(g==="period"?V:U[M]).setAttribute("aria-expanded","true"),W(!0),S.focus()};V.onclick=()=>d("period"),S.onclick=()=>{i.classList.remove("choosing-period"),I.hidden=!0;const g=P==="period"?V:U[j];g.setAttribute("aria-expanded","false"),w(),g.focus()},I.addEventListener("keydown",g=>{if(g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),S.click()),!["ArrowUp","ArrowDown","Home","End"].includes(g.key))return;const M=g.target,C=M.closest(".fc-calendar-period-list");if(!C)return;const N=[...C.querySelectorAll("button")],te=N.indexOf(M),ue=g.key==="Home"?0:g.key==="End"?N.length-1:Math.max(0,Math.min(N.length-1,te+(g.key==="ArrowDown"?1:-1)));g.preventDefault(),N[ue].focus()});function w(){V.textContent=`${b.getFullYear()}年 ${b.getMonth()+1}月`,y.forEach((M,C)=>M.classList.toggle("active",C===f)),x.replaceChildren();for(let M=0;M<b.getDay();M++)x.append(r("span","fc-calendar-blank"));const g=new Date(b.getFullYear(),b.getMonth()+1,0).getDate();for(let M=1;M<=g;M++){const C=Ae(new Date(b.getFullYear(),b.getMonth(),M)),N=r("button","fc-calendar-day",String(M));N.type="button",N.ariaLabel=C,N.disabled=t.readonly;const te=o[0]===C||n&&o[1]===C;N.classList.toggle("selected",te),N.setAttribute("aria-pressed",String(te)),N.classList.toggle("in-range",n&&!!o[0]&&!!o[1]&&C>o[0]&&C<o[1]),C===Ae(new Date)&&(N.classList.add("today"),N.setAttribute("aria-current","date")),N.onclick=()=>{var ue;n?m?(o[1]=C,o[0]&&o[1]<o[0]&&([o[0],o[1]]=[o[1],o[0]]),f=0,m=!1):(o[0]=C,o[1]="",f=1,m=!0):o[0]=C,y.forEach((ne,fe)=>ne.value=o[fe]),w(),!n||o[1]?u():E.textContent="",(ue=x.querySelector(`[aria-label="${C}"]`))==null||ue.focus(),(!n||o[1])&&i.dispatchEvent(new Event("fc-collapse",{bubbles:!0}))},x.append(N)}}T.append(L,A,x,I);const v=r("div","fc-calendar-time");if(e){for(let g=0;g<(n?2:1);g++){const M=r("div","fc-calendar-time-field"),C=n?g?"结束时间":"开始时间":"时间",N=r("button","fc-input fc-calendar-time-trigger",c[g]);N.type="button",N.disabled=t.readonly,N.ariaLabel=C,N.setAttribute("aria-expanded","false"),N.onclick=()=>d("time",g),U.push(N),M.append(r("span","",C),N),v.append(M)}T.append(v)}const k=r("button","fc-calendar-clear","清空");k.type="button",k.disabled=t.readonly,k.onclick=()=>{o.fill(""),y.forEach(g=>g.value=""),f=0,m=!1,w(),u()},i.append(h,T,k,E);const H=()=>{const g=o.slice(0,n?2:1).map((M,C)=>M?M+(e?`T${c[C]}`:""):"");return n?g.some(Boolean)?g:[]:g[0]};if(t.layout==="compact"||t.readonly)return w(),{element:i,read:H,validate:D,focus:()=>{y[0].focus()},deactivate:()=>{i.classList.remove("choosing-period"),I.hidden=!0}};const K=r("div","fc-date-mirror"),Y=()=>K.replaceChildren(Ye({...t,value:H()})),Q=r("span","fc-field-chevron");Q.setAttribute("aria-hidden","true");const _=r("div","fc-date-trigger");_.tabIndex=0,_.setAttribute("role","button"),_.ariaLabel=`编辑${t.field.label}`,_.append(K,Q);let Z;const se=()=>{const g=Z;Z=void 0;const M=!!g&&g.element.contains(document.activeElement);g==null||g.close(),Q.classList.remove("is-open"),M&&queueMicrotask(()=>{Z||!_.isConnected||_.dispatchEvent(new Event("fc-collapse",{bubbles:!0}))})},Ve=()=>{Z||t.readonly||(Y(),Z=pe({anchor:_,content:i,width:320,gap:4,onDismiss:()=>{Z=void 0,Q.classList.remove("is-open")}}),Q.classList.add("is-open"))};return _.onclick=()=>Ve(),_.onkeydown=g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),Ve())},i.addEventListener("focusout",g=>{const M=g.relatedTarget;if(M&&(i.contains(M)||_.contains(M)||ve(M)))return;const C=new Event("focusout",{bubbles:!0});M&&Object.defineProperty(C,"relatedTarget",{value:M}),_.dispatchEvent(C)}),i.addEventListener("change",()=>_.dispatchEvent(new Event("change",{bubbles:!0}))),w(),Y(),{element:_,content:i,inputRoot:_,read:H,validate:D,focus:()=>{Ve(),y[0].focus()},deactivate:se,destroy:se}}const oe=t=>t==null?"":String(t),le=t=>t.dispatchEvent(new Event("change",{bubbles:!0}));function xe(t){try{const e=new URL(oe(t));return["http:","https:"].includes(e.protocol)?e.href:void 0}catch{return}}function be(t){return r("div","fc-value fc-plain fc-"+(t.className||"")+(t.value==null||t.value===""?" fc-empty":""),oe(t.value)||"待填")}function ye(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&&He(n),n.value=oe(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 Lt(t){const e=r("div","fc-link-value"),n=xe(t.value);if(!n)return be(t);const s=r("a","fc-link",oe(t.value));return s.href=n,s.target="_blank",s.rel="noopener noreferrer",s.onclick=i=>i.stopPropagation(),e.append(r("span","fc-link-icon","↗"),s),e}function Ue(t){let e=t.value===!0;const n=r("div","fc-switch-field"),s=r("button","fc-switch");s.type="button",s.setAttribute("role","switch"),s.ariaLabel=t.field.label,s.disabled=t.readonly;const i=r("span"),a=()=>{s.setAttribute("aria-checked",String(e)),i.textContent=e?"是":"否"};return s.onclick=()=>{t.readonly||(e=!e,a(),le(n))},n.append(s,i),a(),{element:n,read:()=>e,focus:()=>s.focus()}}function Ct(t){return Ue({...t,readonly:!0}).element}function At(t){const e=r("div","fc-signals"),n=Array.isArray(t.value)?t.value:[t.value];for(const s of n.filter(i=>i!=null&&i!=="")){const i=typeof s=="object"?s:{status:s},a=i.status??i.value,o=a===!0||a==="passed"||a==="success",c=r("span","fc-signal "+(o?"is-success":"is-pending"),(o?"● ":"○ ")+oe(i.label||i.name||(o?"已满足":a===!1?"未满足":a||"等待信号")));e.append(c)}return e.children.length||e.append(r("span","fc-empty","等待外部信号")),e}function xt(t){const e=t.value&&typeof t.value=="object"?t.value.display??t.value.value:t.value;return be({...t,value:e!=null&&typeof e!="object"?e:""})}function St(t,e){const n=r("div","fc-readonly");return n.append(e(t),r("small","fc-service-note","由系统更新 · 只读")),{element:n,read:()=>t.value}}function We(t){var p,E,D;let e=Array.isArray(t.value)?structuredClone(t.value):[];const n=r("div","fc-attachments"),s=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=((p=t.field.attachmentOptions)==null?void 0:p.accept)||"",a.disabled=t.readonly||!((E=t.services)!=null&&E.upload);const o=r("p","fc-error");o.setAttribute("role","status");const c=r("button","fc-retry","重试上传");c.type="button",c.hidden=!0;let f=[],m=!1,b=!1,T;const h=()=>{s.replaceChildren(),e.forEach((u,L)=>{const V=r("div","fc-file-row"),R=xe(u.url),A=R?r("a","fc-link",u.name):r("span","",u.name);if(A.tagName==="A"){const x=A;x.href=R,x.target="_blank",x.rel="noopener noreferrer"}if(V.append(r("span","fc-file-icon","▤"),A),u.size!=null&&V.append(r("small","fc-file-size",Math.ceil(u.size/1024)+" KB")),!t.readonly){const x=r("button","fc-file-remove","×");x.type="button",x.disabled=m,x.ariaLabel="移除"+u.name,x.onclick=()=>{e.splice(L,1),h(),le(n)},V.append(x)}s.append(V)}),e.length||s.append(r("span","fc-empty","暂无附件"))},y=async()=>{var V;if(!((V=t.services)!=null&&V.upload)||t.readonly||m||!f.length)return;const u=t.field.attachmentOptions;if(u!=null&&u.maxFiles&&e.length+f.length>u.maxFiles){o.textContent="最多上传 "+u.maxFiles+" 个文件";return}if(u!=null&&u.maxBytes&&f.some(R=>R.size>u.maxBytes)){o.textContent="文件大小超过限制";return}const L=((u==null?void 0:u.accept)||"").split(",").map(R=>R.trim().toLowerCase()).filter(Boolean);if(L.length&&f.some(R=>!L.some(A=>A.startsWith(".")?R.name.toLowerCase().endsWith(A):A.endsWith("/*")?R.type.toLowerCase().startsWith(A.slice(0,-1)):R.type.toLowerCase()===A))){o.textContent="文件类型不符合要求";return}T=new AbortController,m=!0,a.disabled=!0,c.hidden=!0,o.textContent="上传中…",n.setAttribute("aria-busy","true"),h();try{const R=await t.services.upload(t.field,f,T.signal);if(b)return;if(R.length!==f.length||R.some(A=>!A.id||!A.name))throw new Error("Invalid file references");e=[...e,...R],f=[],o.textContent="",a.value=""}catch{b||(o.textContent="上传失败,已保留原有附件",c.hidden=!1)}finally{b||(m=!1,a.disabled=!1,n.setAttribute("aria-busy","false"),h(),f.length||le(n))}};return a.onchange=u=>{u.stopPropagation(),f=Array.from(a.files||[]),y()},c.onclick=()=>void y(),i.append(a),n.append(s),t.readonly||(n.append(i),(D=t.services)!=null&&D.upload||n.append(r("p","fc-service-note","上传服务未接入"))),n.append(o,c),h(),{element:n,read:()=>structuredClone(e),focus:()=>a.focus(),validate:()=>m?"请等待上传完成":f.length?"请完成或重新选择上传文件":t.field.required&&!e.length?"请上传附件":void 0,destroy:()=>{b=!0,T==null||T.abort()}}}function Ke(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 Ge(t,e){var y;let n=Ke(t.value),s=[...n.selected];const i=e==="attitude"?[{id:"like",label:"赞同"}]:X(t.field),a=r("div","fc-vote"),o=r("div","fc-vote-list"),c=r("p","fc-error");c.setAttribute("role","status");const f=r("button","fc-vote-submit","提交投票");f.type="button";let m=!1,b=!1,T;const h=()=>{var E,D;o.replaceChildren();const p=Math.max(1,...Object.values(n.counts));for(const u of i){const L=r("button","fc-vote-option");L.type="button",L.disabled=t.readonly||m||!((E=t.services)!=null&&E.vote)||!!u.disabled,L.classList.toggle("selected",s.includes(u.id)),L.setAttribute("aria-pressed",String(s.includes(u.id)));const V=r("span","fc-vote-bar");V.style.width=(n.counts[u.id]||0)/p*100+"%",L.append(V,r("span","",(e==="attitude"?"♡ ":"")+u.label),r("strong","",String(n.counts[u.id]||0))),L.onclick=()=>{s=s.includes(u.id)?s.filter(R=>R!==u.id):e==="multi"?[...s,u.id]:[u.id],h()},o.append(L)}i.length||o.append(r("p","fc-empty","暂无投票选项")),f.disabled=m||!((D=t.services)!=null&&D.vote)||!i.length,f.textContent=m?"提交中…":"提交投票"};return f.onclick=async()=>{var p;if(!(m||t.readonly||!((p=t.services)!=null&&p.vote))){m=!0,c.textContent="",T=new AbortController,a.setAttribute("aria-busy","true"),h();try{const E=await t.services.vote(t.field,s,T.signal);if(b)return;n=Ke(E),s=[...n.selected]}catch{b||(c.textContent="投票失败,请重试")}finally{b||(m=!1,a.setAttribute("aria-busy","false"),h(),c.textContent||le(a))}}},a.append(o),t.readonly||(a.append(f),(y=t.services)!=null&&y.vote||a.append(r("p","fc-service-note","投票服务未接入"))),a.append(c),h(),{element:a,read:()=>structuredClone(n),validate:()=>m?"请等待投票完成":void 0,destroy:()=>{b=!0,T==null||T.abort()}}}function Mt(t){const e=t.value&&typeof t.value=="object"?t.value:{},n=r("div","fc-location"),i=[["address","地址","text"],["longitude","经度","number"],["latitude","纬度","number"]].map(([o,c,f])=>{const m=r("label","fc-location-part",c),b=r("input","fc-input");return b.type=f,b.value=oe(e[o]),b.disabled=t.readonly,b.ariaLabel=c,b.placeholder=c,f==="number"&&(b.step="any",b.min=o==="longitude"?"-180":"-90",b.max=o==="longitude"?"180":"90"),m.append(b),n.append(m),b}),a=()=>i.every(o=>!o.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(o=>o.value===""||!o.checkValidity()))return"请填写有效的经纬度"}}}function Dt(t){const e=t.value;return be({...t,value:e&&typeof e=="object"?oe(e.address)||[e.longitude,e.latitude].filter(n=>n!=null).join(", "):""})}function Tt(t,e){const n=r("div","fc-composite"),s=r("div","fc-composite-rows"),i=r("button","fc-composite-add","+ 添加一组");i.type="button";const a=t.field.compositeFields||[],o=[];let c=!1;const f=y=>({...y.value,...Object.fromEntries(y.editors.map(({field:p,editor:E})=>[p.key,E.read()]))}),m=y=>{y.editors.forEach(({editor:p})=>{var E;return(E=p.destroy)==null?void 0:E.call(p)}),y.remove&&(y.remove.onclick=null),y.element.remove()},b=r("p","fc-empty","暂无记录"),T=()=>{o.forEach((y,p)=>{y.legend.textContent="第 "+(p+1)+" 组"}),i.disabled=t.readonly||!a.length||o.length>=(t.field.maxRows||100),o.length?b.remove():s.append(b)},h=y=>{const p=r("fieldset","fc-composite-row"),E=r("legend");p.append(E);const D=a.map(L=>{const V=e(L),R=V.createEditor({...t,field:L,value:y[L.key],readonly:t.readonly||L.editable===!1||!!V.readonly,focusBoundary:void 0,onSelectedOptions:x=>{var I;(I=t.services)!=null&&I.searchOptions&&(L.choices=[...new Map([...X(L),...x].map(S=>[S.id,S])).values()])}}),A=r("div","fc-composite-field");return A.append(r("label","",L.label+(L.required?" *":"")),R.element),p.append(A),{field:L,editor:R}}),u={value:y,element:p,legend:E,editors:D};if(!t.readonly){const L=r("button","fc-composite-remove","删除此组");L.type="button",L.onclick=()=>{if(c)return;const V=o.indexOf(u);V<0||(m(u),o.splice(V,1),T(),le(n))},u.remove=L,p.append(L)}o.push(u),s.append(p),T()};for(const y of Array.isArray(t.value)?t.value:[])h(structuredClone(y));return i.onclick=()=>{c||i.disabled||(h({}),le(n))},n.append(s),t.readonly||n.append(i),a.length||n.append(r("p","fc-service-note","请配置复合子字段")),T(),{element:n,read:()=>o.map(f),validate:()=>{var y;if(t.field.required&&!o.length)return"请至少添加一组";for(const[p,E]of o.entries())for(const{field:D,editor:u}of E.editors){const L=(y=u.validate)==null?void 0:y.call(u);if(L)return"第 "+(p+1)+" 组 · "+D.label+":"+L}},destroy:()=>{c||(c=!0,i.onclick=null,o.forEach(m))}}}class ee extends J{renderDisplay(e){return{element:yt(e)}}renderEditing(e){return je("text",e)}}class Je extends ee{renderDisplay(e){return super.renderDisplay({...e,field:{...e.field,kind:"number"}})}renderEditing(e){return je("number",e)}}class Qe extends ee{renderDisplay(e){return super.renderDisplay({...e,field:{...e.field,control:"richText"}})}renderEditing(e){return gt(e)}}class Ze extends ee{renderDisplay(e){return{element:be(e)}}renderEditing(e){return ye(e,"textarea")}}class Se extends ee{renderDisplay(e){return{element:Lt(e)}}renderEditing(e){return ye(e,"url")}}class Xe extends ee{renderEditing(e){return ye(e,"email")}}class et extends ee{renderEditing(e){return ye(e,"tel")}}class de extends J{constructor(){super(...arguments);O(this,"multiple",!1);O(this,"variant","choice")}renderDisplay(n){return{element:bt(n,this.variant==="radio"?"choice":this.variant)}}renderEditing(n){return Oe(this.multiple,n,this.variant)}}class tt extends de{constructor(){super(...arguments);O(this,"multiple",!0)}}class nt extends de{constructor(){super(...arguments);O(this,"variant","radio")}}class Me extends de{constructor(){super(...arguments);O(this,"variant","person")}}class it extends Me{constructor(){super(...arguments);O(this,"multiple",!0)}}class De extends de{constructor(){super(...arguments);O(this,"variant","relation")}}class st extends De{constructor(){super(...arguments);O(this,"multiple",!0)}}class Te extends J{constructor(){super(...arguments);O(this,"multiple",!1)}renderDisplay(n){return{element:wt(n)}}renderEditing(n){return kt(this.multiple,n)}}class ot extends Te{constructor(){super(...arguments);O(this,"multiple",!0)}}class Fe extends J{normalize(e){return e}renderDisplay(e){return{element:Ye(this.normalize(e))}}renderEditing(e){return Et(this.normalize(e))}}class Re extends Fe{constructor(){super(...arguments);O(this,"range",!1)}normalize(n){return{...n,field:{...n.field,dateOptions:{showTime:!1,showRange:this.range,...n.field.dateOptions}}}}}class at extends Re{constructor(){super(...arguments);O(this,"range",!0)}}class rt extends J{renderDisplay(e){return{element:Ct(e)}}renderEditing(e){return Ue(e)}}class lt extends J{renderDisplay(e){return We({...e,readonly:!0})}renderEditing(e){return We(e)}}class dt extends J{renderDisplay(e){return{element:Dt(e)}}renderEditing(e){return Mt(e)}}class we extends J{constructor(){super(...arguments);O(this,"mode","attitude")}renderDisplay(n){return Ge({...n,readonly:!0},this.mode)}renderEditing(n){return Ge(n,this.mode)}}class ct extends we{constructor(){super(...arguments);O(this,"mode","single")}}class ut extends we{constructor(){super(...arguments);O(this,"mode","multi")}}class ce extends J{isReadonly(){return!0}constructor(e){super({...e,readonly:!0})}renderDisplay(e){return{element:xt(e)}}renderEditing(e){return St(e,n=>this.renderDisplay(n).element)}}class Ne extends ce{renderDisplay(e){return{element:At(e)}}}class ft 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=s=>{var i;s.stopPropagation(),(i=e.onAction)==null||i.call(e,{type:"open",value:e.value})},{element:n,destroy:()=>{n.onclick=null}}}}class pt extends J{constructor(e,n){super(e),this.resolve=n}renderDisplay(e){var i;if(e.layout==="compact")return{element:be({...e,value:Array.isArray(e.value)&&e.value.length?e.value.length+" 组记录":""})};const n=document.createElement("div");n.className="fc-composite";const s=[];for(const a of Array.isArray(e.value)?e.value:[]){const o=document.createElement("fieldset");o.className="fc-composite-row";for(const c of e.field.compositeFields??[]){const f=document.createElement("label");f.textContent=c.label;const m={...e,field:c,value:a[c.key],readonly:!0},b=this.resolve(c),T=((i=b.renderView)==null?void 0:i.call(b,m))??{element:b.render(m)};s.push(T),o.append(f,T.element)}n.append(o)}return{element:n,destroy:()=>s.forEach(a=>{var o;return(o=a.destroy)==null?void 0:o.call(a)})}}renderEditing(e){return Tt(e,this.resolve)}}const Ft={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:"由调用方处理关联内容导航"},Rt={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"},Nt=[["text","单行文本",ee,"文本","T"],["richText","富文本",Qe,"文本","¶"],["select","单选",de,"选择","◉"],["multiSelect","多选",tt,"选择","☑"],["number","数字",Je,"其他","#"],["dateTime","日期时间",Fe,"日期","◷"],["detail","详情页查看",ft,"关联工作项","↗"],["textarea","多行文本",Ze,"文本","≡"],["radio","单选按钮",nt,"选择","◉"],["cascadeSingle","级联单选",Te,"选择","⑂"],["cascadeMulti","级联多选",ot,"选择","⑂"],["person","单选人员",Me,"人员","♙"],["multiPerson","多选人员",it,"人员","♙"],["date","日期",Re,"日期","▦"],["dateRange","日期区间",at,"日期","▦"],["url","URL 链接",Se,"其他","↗"],["cloudDocument","关联云文档",Se,"其他","▤"],["email","邮箱",Xe,"其他","@"],["phone","电话",et,"其他","☎"],["switch","开关",rt,"其他","◐"],["attachment","附件",lt,"其他","⌑"],["location","地理位置",dt,"其他","⌖"],["relation","单选关联工作项",De,"关联工作项","↗"],["multiRelation","多选关联工作项",st,"关联工作项","↗"],["attitudeVote","表态投票",we,"投票","♡"],["singleVote","单选投票",ct,"投票","♡"],["multiVote","多选投票",ut,"投票","♡"],["externalSignal","系统外信号",Ne,"系统","◌",!0],["externalMultiSignal","多值系统外信号",Ne,"系统","◌",!0],["formula","公式计算",ce,"系统","ƒ",!0],["aggregate","聚合计算",ce,"系统","ƒ",!0],["ai","AI 字段",ce,"系统","ƒ",!0],["system","系统字段",ce,"系统","ƒ",!0]];function Vt(t=[]){const e=new Map,n=o=>{if(!/^[A-Za-z][\w-]*$/.test(o.id))throw new Error("Invalid control id");if(e.has(o.id))throw new Error(`Control already registered: ${o.id}`);e.set(o.id,o)},s=o=>{const c=o.control||Rt[o.kind||"text"]||o.kind||"text",f=e.get(c);if(!f)throw new Error(`Unknown control: ${c}`);return f},i=o=>s(o.field).create(o),a=o=>{const c=s(o);return{...c,render:f=>c.create(f).render().element,renderView:f=>c.create(f).render(),createEditor:f=>c.create(f).createEditor()}};for(const[o,c,f,m,b,T]of Nt)n({id:o,label:c,description:Ft[o]||c,glyph:b,group:m,readonly:T,action:o==="detail"?"view":o==="select"||o==="multiSelect"?"select":void 0,create:h=>new f({...h,readonly:T||h.readonly})});for(const[o,c]of[["composite","复合字段"],["multiPersonComposite","多人复合字段"]])n({id:o,label:c,description:"组合多个已注册字段",glyph:"▦",group:"其他",create:f=>new pt(f,a)});return t.forEach(n),{register:n,resolve:s,create:i,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)}}F.ActionField=ft,F.AttachmentField=lt,F.BaseField=J,F.CascadeField=Te,F.ChoiceField=de,F.CompositeField=pt,F.ComputedField=ce,F.CustomField=It,F.DateField=Re,F.DateRangeField=at,F.DateTimeField=Fe,F.EmailField=Xe,F.LinkField=Se,F.LocationField=dt,F.MultiCascadeField=ot,F.MultiChoiceField=tt,F.MultiPersonField=it,F.MultiRelationField=st,F.MultiVoteField=ut,F.NumberField=Je,F.PersonField=Me,F.PhoneField=et,F.RadioField=nt,F.RelationField=De,F.RichTextField=Qe,F.SignalField=Ne,F.SingleVoteField=ct,F.SwitchField=rt,F.TextField=ee,F.TextareaField=Ze,F.VoteField=we,F.closeAllFieldPopups=Ie,F.createFieldRegistry=Vt,F.openFieldPopup=pe,F.renderContent=Ee,F.sanitizeRichText=he,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});