@qxs-bns/components-wc 0.0.28 → 0.0.29

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.
@@ -1,20 +1,20 @@
1
- import{html as t,css as e,LitElement as i}from"lit";import{property as s,state as r}from"lit/decorators.js";import{safeCustomElement as o}from"../base/define.mjs";import{trimText as a,SubjectError as n}from"./single.mjs";import{sortingCardStyles as l,renderSortingCard as d}from"./sorting-card.mjs";import{SubjectType as h,SubjectTypeLabel as p}from"./types.mjs";var c=Object.defineProperty,u=Object.getOwnPropertyDescriptor,x=(t,e,i,s)=>{for(var r,o=s>1?void 0:s?u(e,i):e,a=t.length-1;a>=0;a--)(r=t[a])&&(o=(s?r(e,i,o):r(o))||o);return s&&o&&c(e,i,o),o};function w(){return{title:""}}function m(){return Array.from({length:5},w)}function y(t){const e={...t,title:a(t?.title??t?.answer??"")},i=t?.answerId??t?.examAnswerId;return void 0!==i&&(e.answerId=i),delete e.answer,delete e.examAnswerId,e}function f(t,e){const i={...y(t),orderIndex:e+1,answer:a(t?.title??t?.answer??"")};return i.title=a(i.title??""),void 0!==i.answerId&&(i.examAnswerId=i.answerId),void 0===i.answerId&&delete i.answerId,void 0===i.isCorrect&&delete i.isCorrect,i}const g=t`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>`,b=t`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>`;let v=class extends i{constructor(){super(...arguments),this["order-index"]=0,this.title="",this["custom-id"]="",this["is-edit"]=!1,this["is-save"]=!1,this["is-set"]=!1,this["show-action"]=!0,this["show-add"]=!0,this.sorting=!1,this.analysis="",this["rich-text-content"]="",this["exam-answer-relation-type"]=0,this["upload-image"]=async t=>new Promise((e,i)=>{const s=new FileReader;s.onload=t=>e(t.target?.result),s.onerror=i,s.readAsDataURL(t)}),this._answers=m(),this._scaleQuestions=[],this._rowTitle="",this._title="",this._showRichText=!1,this._richText="",this["model-value"]="",this["use-model"]=!1,this.TITLE_MAX=200}get"answer-list"(){return this._answers}set"answer-list"(t){const e=function(t){return Array.isArray(t)?t.slice(0,5).map(y):[]}(t);this._answers=e.length?e:m(),this.requestUpdate("answer-list")}get"scale-question-list"(){return this._scaleQuestions}set"scale-question-list"(t){this._scaleQuestions=function(t){return Array.isArray(t)?t.map(t=>String(t??"").trim()).filter(Boolean):[]}(t),this.requestUpdate("scale-question-list")}get"scale-questions"(){return this._scaleQuestions}set"scale-questions"(t){this["scale-question-list"]=t,this.requestUpdate("scale-questions")}willUpdate(t){const e=t.has("title")||t.has("answer-list")||t.has("rich-text-content")||t.has("scale-question-list")||t.has("scale-questions");(t.has("is-edit")&&this["is-edit"]||!this["is-edit"]&&e)&&this._syncProps(),t.has("model-value")&&this["use-model"]&&(this._title=this["model-value"])}_syncProps(){this._title=this.title||"",this._rowTitle=this._scaleQuestions.join("\n"),this._richText=this["rich-text-content"]||"",this._showRichText=!!this["rich-text-content"]}_emit(t,e){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e??null}))}_onTitleInput(t){const e=t.target;e.value.length>this.TITLE_MAX&&(e.value=e.value.slice(0,this.TITLE_MAX)),this._title=e.value,this["use-model"]&&this.dispatchEvent(new CustomEvent("update:modelValue",{bubbles:!0,composed:!0,detail:this._title}))}_resolvedQuestions(){const t=this["is-edit"]?this._rowTitle:this._scaleQuestions.join("\n");return t.split("\n").map(t=>t.trim()).filter(Boolean)}async toJSON(){return new Promise((t,e)=>{const i={customId:this["custom-id"]||void 0,answerType:h.SCALE,orderIndex:this["order-index"]},s=a(this["is-edit"]?this._title:this.title||""),r=this["is-edit"]?this._answers:this["answer-list"],o=this._resolvedQuestions(),l=this["is-edit"]?this._richText:this["rich-text-content"]||"",d=this["is-edit"]?this._showRichText:!!this["rich-text-content"];if(!s)return void e(new n("题目标题不能为空!","EMPTY_TITLE","title",i));for(let t=0;t<r.length;t++)if(!r[t].title)return void e(new n(`选项${String.fromCharCode(65+t)}未填写。`,"ANSWER_EMPTY","answers",i));if(0===o.length)return void e(new n("行标题不能为空!","EMPTY_ROW_TITLE","rowTitle",i));const p={answerType:h.SCALE,examTypeEnum:h.SCALE,title:s,answers:r.map(f),scaleQuestionList:o,analysis:a(this.analysis||""),examRichTextContent:d?l:"",isSetCorrectAnswer:!1};this["custom-id"]&&(p.customId=this["custom-id"]),t(p)})}async _save(t){t?.stopImmediatePropagation();try{const t=await this.toJSON();this._emit("save",t)}catch(t){!function(t){const e=document.createElement("div");e.textContent=t,Object.assign(e.style,{position:"fixed",top:"20px",left:"50%",transform:"translateX(-50%)",padding:"10px 20px",borderRadius:"4px",fontSize:"13px",color:"#fff",background:"#f56c6c",zIndex:"99999",boxShadow:"0 4px 12px rgba(0,0,0,.15)",transition:"opacity .3s",opacity:"1"}),document.body.appendChild(e),setTimeout(()=>{e.style.opacity="0",setTimeout(()=>e.remove(),300)},2500)}(t.message)}}validate(){const t=[],e={customId:this["custom-id"]||void 0,answerType:h.SCALE,orderIndex:this["order-index"]},i=a(this["is-edit"]?this._title:this.title||""),s=this["is-edit"]?this._answers:this["answer-list"],r=this._resolvedQuestions();return i||t.push(new n("题目标题不能为空!","EMPTY_TITLE","title",e)),s.forEach((i,s)=>{i.title||t.push(new n(`选项${String.fromCharCode(65+s)}未填写`,"ANSWER_EMPTY","answers",e))}),0===r.length&&t.push(new n("行标题不能为空!","EMPTY_ROW_TITLE","rowTitle",e)),t}_renderPreview(){const e=Math.floor(100/((this._answers.length||1)+1));return t`
1
+ import{html as t,css as e,LitElement as i}from"lit";import{property as s,state as o}from"lit/decorators.js";import{safeCustomElement as r}from"../base/define.mjs";import{SubjectError as a,trimText as n}from"./single.mjs";import{sortingCardStyles as l,renderSortingCard as h}from"./sorting-card.mjs";import{SubjectType as d,SubjectTypeLabel as p}from"./types.mjs";var c=Object.defineProperty,u=Object.getOwnPropertyDescriptor,x=(t,e,i,s)=>{for(var o,r=s>1?void 0:s?u(e,i):e,a=t.length-1;a>=0;a--)(o=t[a])&&(r=(s?o(e,i,r):o(r))||r);return s&&r&&c(e,i,r),r};function w(){return{title:""}}function y(){return Array.from({length:5},w)}function m(t){const e={...t,title:n(t?.title??t?.answer??"")},i=t?.answerId??t?.examAnswerId;return void 0!==i&&(e.answerId=i),delete e.answer,delete e.examAnswerId,delete e.isCorrect,e}function v(t,e){const i={...m(t),orderIndex:e+1,answer:n(t?.title??t?.answer??"")};return i.title=n(i.title??""),void 0!==i.answerId&&(i.examAnswerId=i.answerId),void 0===i.answerId&&delete i.answerId,delete i.isCorrect,i}const f=t`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>`,g=t`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>`;let b=class extends i{constructor(){super(...arguments),this["order-index"]=0,this.title="",this["custom-id"]="",this["is-edit"]=!1,this["is-save"]=!1,this["is-set"]=!1,this["show-action"]=!0,this["show-add"]=!0,this["hide-add-rich-text"]=!1,this["show-rich-text"]=!1,this["show-delete-action"]=!0,this["show-save-action"]=!0,this.sorting=!1,this["show-analysis"]=!1,this.analysis="",this["rich-text-content"]="",this["exam-answer-relation-type"]=0,this["upload-image"]=async t=>new Promise((e,i)=>{const s=new FileReader;s.onload=t=>e(t.target?.result),s.onerror=i,s.readAsDataURL(t)}),this._answers=y(),this._scaleQuestions=[],this._rowTitle="",this._title="",this._analysis="",this._showRichText=!1,this._richText="",this["model-value"]="",this["use-model"]=!1,this.TITLE_MAX=200}get"answer-list"(){return this._answers}set"answer-list"(t){const e=function(t){return Array.isArray(t)?t.map(m):[]}(t);this._answers=e.length?e:y(),this.requestUpdate("answer-list")}get"scale-question-list"(){return this._scaleQuestions}set"scale-question-list"(t){this._scaleQuestions=function(t){return Array.isArray(t)?t.map(t=>String(t??"").trim()).filter(Boolean):[]}(t),this.requestUpdate("scale-question-list")}get"scale-questions"(){return this._scaleQuestions}set"scale-questions"(t){this["scale-question-list"]=t,this.requestUpdate("scale-questions")}willUpdate(t){const e=t.has("title")||t.has("answer-list")||t.has("rich-text-content")||t.has("scale-question-list")||t.has("scale-questions");(t.has("is-edit")&&this["is-edit"]||!this["is-edit"]&&e)&&this._syncProps(),t.has("model-value")&&this["use-model"]&&(this._title=this["model-value"])}_syncProps(){this._title=this.title||"",this._analysis=this.analysis||"",this._rowTitle=this._scaleQuestions.join("\n"),this._richText=this["rich-text-content"]||"",this._showRichText=!!this["rich-text-content"]}_emit(t,e){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e??null}))}_onTitleInput(t){const e=t.target;e.value.length>this.TITLE_MAX&&(e.value=e.value.slice(0,this.TITLE_MAX)),this._title=e.value,this["use-model"]&&this.dispatchEvent(new CustomEvent("update:modelValue",{bubbles:!0,composed:!0,detail:this._title}))}_resolvedQuestions(){const t=this["is-edit"]?this._rowTitle:this._scaleQuestions.join("\n");return t.split("\n").map(t=>t.trim()).filter(Boolean)}_resolvedAnswers(){const t=this["is-edit"]?this._answers:this["answer-list"];return Array.isArray(t)?t.map(m):[]}_createAnswerCountError(t){return new a("量表题选项数量必须在 3-5 个之间!","ANSWER_COUNT_INVALID","answers",t)}async toJSON(){return new Promise((t,e)=>{const i={customId:this["custom-id"]||void 0,answerType:d.SCALE,orderIndex:this["order-index"]},s=n(this["is-edit"]?this._title:this.title||""),o=this._resolvedAnswers(),r=this._resolvedQuestions(),l=this["is-edit"]?this._richText:this["rich-text-content"]||"",h=this["show-rich-text"]&&(this["is-edit"]?this._showRichText:!!this["rich-text-content"]);if(!s)return void e(new a("题目标题不能为空!","EMPTY_TITLE","title",i));if(o.length<3||o.length>5)return void e(this._createAnswerCountError(i));for(let t=0;t<o.length;t++)if(!o[t].title)return void e(new a(`选项${String.fromCharCode(65+t)}未填写。`,"ANSWER_EMPTY","answers",i));if(0===r.length)return void e(new a("行标题不能为空!","EMPTY_ROW_TITLE","rowTitle",i));const p={answerType:d.SCALE,examTypeEnum:d.SCALE,title:s,answers:o.map(v),scaleQuestionList:r,analysis:n(this["is-edit"]?this._analysis:this.analysis||""),examRichTextContent:h?l:"",isSetCorrectAnswer:!1};this["custom-id"]&&(p.customId=this["custom-id"]),this["exam-answer-relation-type"]&&(p.examAnswerRelationType=this["exam-answer-relation-type"]),t(p)})}async _save(t){t?.stopImmediatePropagation();try{const t=await this.toJSON();this._emit("save",t)}catch(t){!function(t){const e=document.createElement("div");e.textContent=t,Object.assign(e.style,{position:"fixed",top:"20px",left:"50%",transform:"translateX(-50%)",padding:"10px 20px",borderRadius:"4px",fontSize:"13px",color:"#fff",background:"#f56c6c",zIndex:"99999",boxShadow:"0 4px 12px rgba(0,0,0,.15)",transition:"opacity .3s",opacity:"1"}),document.body.appendChild(e),setTimeout(()=>{e.style.opacity="0",setTimeout(()=>e.remove(),300)},2500)}(t.message)}}validate(){const t=[],e={customId:this["custom-id"]||void 0,answerType:d.SCALE,orderIndex:this["order-index"]},i=n(this["is-edit"]?this._title:this.title||""),s=this._resolvedAnswers(),o=this._resolvedQuestions();return i||t.push(new a("题目标题不能为空!","EMPTY_TITLE","title",e)),s.length<3||s.length>5?(t.push(this._createAnswerCountError(e)),t):(s.forEach((i,s)=>{i.title||t.push(new a(`选项${String.fromCharCode(65+s)}未填写`,"ANSWER_EMPTY","answers",e))}),0===o.length&&t.push(new a("行标题不能为空!","EMPTY_ROW_TITLE","rowTitle",e)),t)}_renderPreview(){const e=this._resolvedAnswers(),i=this._resolvedQuestions(),s=Math.floor(100/((e.length||1)+1));return t`
2
2
  <div class="preview">
3
3
  <span class="title">${this["order-index"]+1}.${this.title}(量表题)</span>
4
- ${this["rich-text-content"]?t`<div class="rich-text" .innerHTML=${this["rich-text-content"]}></div>`:""}
4
+ ${this["show-rich-text"]&&this["rich-text-content"]?t`<div class="rich-text" .innerHTML=${this["rich-text-content"]}></div>`:""}
5
5
  <div class="scale-table-wrap">
6
6
  <table class="scale-table">
7
7
  <thead>
8
8
  <tr>
9
- <th style="width:${e}%">问题 \ 选项</th>
10
- ${this._answers.map(i=>t`<th style="width:${e}%">${i.title}</th>`)}
9
+ <th style="width:${s}%">问题 \ 选项</th>
10
+ ${e.map(e=>t`<th style="width:${s}%">${e.title}</th>`)}
11
11
  </tr>
12
12
  </thead>
13
13
  <tbody>
14
- ${this._scaleQuestions.map(e=>t`
14
+ ${i.map(i=>t`
15
15
  <tr>
16
- <td>${e}</td>
17
- ${this._answers.map(()=>t`<td><input type="radio" disabled /></td>`)}
16
+ <td>${i}</td>
17
+ ${e.map(()=>t`<td><input type="radio" disabled /></td>`)}
18
18
  </tr>
19
19
  `)}
20
20
  </tbody>
@@ -68,18 +68,18 @@ import{html as t,css as e,LitElement as i}from"lit";import{property as s,state a
68
68
  <span
69
69
  class="icon"
70
70
  @click=${()=>{this._answers.length<5&&(this._answers=[...this._answers,{title:""}])}}
71
- >${g}</span>
71
+ >${f}</span>
72
72
  <span
73
73
  class="icon ${this._answers.length<3?"disabled":""}"
74
74
  @click=${()=>{this._answers.length>3&&(this._answers=this._answers.filter((t,e)=>e!==i))}}
75
- >${b}</span>
75
+ >${g}</span>
76
76
  </div>
77
77
  `)}
78
78
  </div>
79
79
  </div>
80
80
  </div>
81
81
 
82
- ${this._showRichText?t`
82
+ ${this["show-rich-text"]&&this._showRichText?t`
83
83
  <div class="flex-items-start" style="margin-top:12px">
84
84
  <div class="label"><span>副文本:</span></div>
85
85
  <div style="flex:1">
@@ -102,7 +102,23 @@ import{html as t,css as e,LitElement as i}from"lit";import{property as s,state a
102
102
  </div>
103
103
  </div>
104
104
  `:""}
105
- `}_renderSorting(){const t=a(this["is-edit"]?this._title:this.title||"")||"未命名题目",e=`${this["order-index"]+1}. ${t}`;return d(e,p[h.SCALE]||h.SCALE)}render(){if(this.sorting)return this._renderSorting();const e=this["is-edit"]?t`<div slot="edit">${this._renderEdit()}</div>`:t`<div slot="preview">${this._renderPreview()}</div>`;return t`
105
+
106
+ ${this["show-analysis"]?t`
107
+ <div class="flex-items-start" style="margin-top:12px">
108
+ <div class="label"><span>解析:</span></div>
109
+ <div style="flex:1">
110
+ <div class="el-input">
111
+ <textarea
112
+ rows="2"
113
+ .value=${this._analysis}
114
+ @input=${t=>{this._analysis=t.target.value}}
115
+ placeholder="请输入题目解析"
116
+ ></textarea>
117
+ </div>
118
+ </div>
119
+ </div>
120
+ `:""}
121
+ `}_renderSorting(){const t=n(this["is-edit"]?this._title:this.title||"")||"未命名题目",e=`${this["order-index"]+1}. ${t}`;return h(e,p[d.SCALE]||d.SCALE)}render(){if(this.sorting)return this._renderSorting();const e=this["is-edit"]?t`<div slot="edit">${this._renderEdit()}</div>`:t`<div slot="preview">${this._renderPreview()}</div>`;return t`
106
122
  <qxs-subject-layout .show-edit=${this["is-edit"]}>
107
123
  ${e}
108
124
  ${this["show-action"]?t`
@@ -110,7 +126,10 @@ import{html as t,css as e,LitElement as i}from"lit";import{property as s,state a
110
126
  .is-edit=${this["is-edit"]}
111
127
  .is-set=${this["is-set"]}
112
128
  .show-add=${this["show-add"]}
113
- .show-rich-text=${this._showRichText}
129
+ .show-rich-text=${this["show-rich-text"]&&this._showRichText}
130
+ .hide-add-rich-text=${!this["show-rich-text"]||this["hide-add-rich-text"]}
131
+ .show-delete-action=${this["show-delete-action"]}
132
+ .show-save-action=${this["show-save-action"]}
114
133
  .show-other-option=${!1}
115
134
  exam-answer-relation-type=${this["exam-answer-relation-type"]}
116
135
  @delete=${()=>this._emit("delete")}
@@ -120,8 +139,9 @@ import{html as t,css as e,LitElement as i}from"lit";import{property as s,state a
120
139
  @on-show-rich-text=${()=>{this._showRichText=!this._showRichText,this._showRichText||(this._richText="")}}
121
140
  ></qxs-subject-action>
122
141
  `:""}
142
+ <slot name="action"></slot>
123
143
  </qxs-subject-layout>
124
- `}};v.styles=[l,e`
144
+ `}};b.styles=[l,e`
125
145
  :host { display: block; font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 12px; color: #5a5a5a; }
126
146
  *, ::before, ::after { box-sizing: border-box; }
127
147
 
@@ -195,5 +215,5 @@ import{html as t,css as e,LitElement as i}from"lit";import{property as s,state a
195
215
  .answer-item .icon.disabled { color: #e4e7ed; border-color: #e4e7ed; cursor: not-allowed; }
196
216
 
197
217
  .row-title-textarea { height: 200px; }
198
- `],x([s({type:Number,attribute:"order-index"})],v.prototype,"order-index",2),x([s({type:String})],v.prototype,"title",2),x([s({type:String,attribute:"custom-id"})],v.prototype,"custom-id",2),x([s({type:Boolean,attribute:"is-edit"})],v.prototype,"is-edit",2),x([s({type:Boolean,attribute:"is-save"})],v.prototype,"is-save",2),x([s({type:Boolean,attribute:"is-set"})],v.prototype,"is-set",2),x([s({type:Boolean,attribute:"show-action"})],v.prototype,"show-action",2),x([s({type:Boolean,attribute:"show-add"})],v.prototype,"show-add",2),x([s({type:Boolean,reflect:!0})],v.prototype,"sorting",2),x([s({type:String})],v.prototype,"analysis",2),x([s({type:String,attribute:"rich-text-content"})],v.prototype,"rich-text-content",2),x([s({type:Number,attribute:"exam-answer-relation-type"})],v.prototype,"exam-answer-relation-type",2),x([s({type:Object,attribute:"upload-image"})],v.prototype,"upload-image",2),x([s({type:Array,attribute:"answer-list"})],v.prototype,"answer-list",1),x([s({type:Array,attribute:"scale-question-list"})],v.prototype,"scale-question-list",1),x([s({type:Array,attribute:"scale-questions"})],v.prototype,"scale-questions",1),x([r()],v.prototype,"_answers",2),x([r()],v.prototype,"_scaleQuestions",2),x([r()],v.prototype,"_rowTitle",2),x([r()],v.prototype,"_title",2),x([r()],v.prototype,"_showRichText",2),x([r()],v.prototype,"_richText",2),x([s({type:String,attribute:"model-value"})],v.prototype,"model-value",2),x([s({type:Boolean,attribute:"use-model"})],v.prototype,"use-model",2),v=x([o("qxs-scale")],v);export{v as QxsScale};
218
+ `],x([s({type:Number,attribute:"order-index"})],b.prototype,"order-index",2),x([s({type:String})],b.prototype,"title",2),x([s({type:String,attribute:"custom-id"})],b.prototype,"custom-id",2),x([s({type:Boolean,attribute:"is-edit"})],b.prototype,"is-edit",2),x([s({type:Boolean,attribute:"is-save"})],b.prototype,"is-save",2),x([s({type:Boolean,attribute:"is-set"})],b.prototype,"is-set",2),x([s({type:Boolean,attribute:"show-action"})],b.prototype,"show-action",2),x([s({type:Boolean,attribute:"show-add"})],b.prototype,"show-add",2),x([s({type:Boolean,attribute:"hide-add-rich-text"})],b.prototype,"hide-add-rich-text",2),x([s({type:Boolean,attribute:"show-rich-text"})],b.prototype,"show-rich-text",2),x([s({type:Boolean,attribute:"show-delete-action"})],b.prototype,"show-delete-action",2),x([s({type:Boolean,attribute:"show-save-action"})],b.prototype,"show-save-action",2),x([s({type:Boolean,reflect:!0})],b.prototype,"sorting",2),x([s({type:Boolean,attribute:"show-analysis"})],b.prototype,"show-analysis",2),x([s({type:String})],b.prototype,"analysis",2),x([s({type:String,attribute:"rich-text-content"})],b.prototype,"rich-text-content",2),x([s({type:Number,attribute:"exam-answer-relation-type"})],b.prototype,"exam-answer-relation-type",2),x([s({type:Object,attribute:"upload-image"})],b.prototype,"upload-image",2),x([s({type:Array,attribute:"answer-list"})],b.prototype,"answer-list",1),x([s({type:Array,attribute:"scale-question-list"})],b.prototype,"scale-question-list",1),x([s({type:Array,attribute:"scale-questions"})],b.prototype,"scale-questions",1),x([o()],b.prototype,"_answers",2),x([o()],b.prototype,"_scaleQuestions",2),x([o()],b.prototype,"_rowTitle",2),x([o()],b.prototype,"_title",2),x([o()],b.prototype,"_analysis",2),x([o()],b.prototype,"_showRichText",2),x([o()],b.prototype,"_richText",2),x([s({type:String,attribute:"model-value"})],b.prototype,"model-value",2),x([s({type:Boolean,attribute:"use-model"})],b.prototype,"use-model",2),b=x([r("qxs-scale")],b);export{b as QxsScale};
199
219
  //# sourceMappingURL=scale.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"scale.mjs","sources":["../../../../packages/components-wc/src/subject/scale.ts"],"sourcesContent":["import { css, html, LitElement } from 'lit'\nimport { property, state } from 'lit/decorators.js'\nimport { safeCustomElement } from '../base/define'\nimport { SubjectError, trimText } from './single'\nimport { renderSortingCard, sortingCardStyles } from './sorting-card'\nimport { SubjectType, SubjectTypeLabel } from './types'\n\ninterface ScaleAnswer {\n title: string\n answerId?: string | number\n orderIndex?: number\n isCorrect?: boolean\n [key: string]: any\n}\n\nfunction createEmptyScaleAnswer(): ScaleAnswer {\n return { title: '' }\n}\n\nfunction createDefaultScaleAnswers(): ScaleAnswer[] {\n return Array.from({ length: 5 }, createEmptyScaleAnswer)\n}\n\nfunction normalizeScaleAnswer(answer: any): ScaleAnswer {\n const next: ScaleAnswer = {\n ...answer,\n title: trimText(answer?.title ?? answer?.answer ?? ''),\n }\n const answerId = answer?.answerId ?? answer?.examAnswerId\n if (answerId !== undefined) {\n next.answerId = answerId\n }\n delete next.answer\n delete next.examAnswerId\n return next\n}\n\nfunction normalizeScaleAnswers(value: any): ScaleAnswer[] {\n return Array.isArray(value) ? value.slice(0, 5).map(normalizeScaleAnswer) : []\n}\n\nfunction normalizeScaleQuestionList(value: any): string[] {\n if (!Array.isArray(value)) {\n return []\n }\n return value\n .map(item => String(item ?? '').trim())\n .filter(Boolean)\n}\n\nfunction splitScaleQuestionLines(value: string): string[] {\n return value\n .split('\\n')\n .map(item => item.trim())\n .filter(Boolean)\n}\n\nfunction serializeScaleAnswer(answer: any, index: number): ScaleAnswer {\n const next: ScaleAnswer = {\n ...normalizeScaleAnswer(answer),\n orderIndex: index + 1,\n answer: trimText(answer?.title ?? answer?.answer ?? ''),\n }\n next.title = trimText(next.title ?? '')\n if (next.answerId !== undefined) {\n next.examAnswerId = next.answerId\n }\n if (next.answerId === undefined) {\n delete next.answerId\n }\n if (next.isCorrect === undefined) {\n delete next.isCorrect\n }\n return next\n}\n\nconst iconPlus = html`<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><line x1=\"12\" y1=\"5\" x2=\"12\" y2=\"19\"/><line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/></svg>`\nconst iconRemove = html`<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/></svg>`\n\nfunction showToast(msg: string) {\n const el = document.createElement('div')\n el.textContent = msg\n Object.assign(el.style, {\n position: 'fixed', top: '20px', left: '50%', transform: 'translateX(-50%)',\n padding: '10px 20px', borderRadius: '4px', fontSize: '13px', color: '#fff',\n background: '#f56c6c', zIndex: '99999', boxShadow: '0 4px 12px rgba(0,0,0,.15)',\n transition: 'opacity .3s', opacity: '1',\n })\n document.body.appendChild(el)\n setTimeout(() => {\n el.style.opacity = '0'\n setTimeout(() => el.remove(), 300)\n }, 2500)\n}\n\n@safeCustomElement('qxs-scale')\nexport class QxsScale extends LitElement {\n static styles = [sortingCardStyles, css`\n :host { display: block; font-family: system-ui, -apple-system, \"PingFang SC\", \"Microsoft YaHei\", sans-serif; font-size: 12px; color: #5a5a5a; }\n *, ::before, ::after { box-sizing: border-box; }\n\n .preview { padding: 12px 0; }\n .preview .title { font-size: 14px; color: #303133; }\n .preview .rich-text { margin-top: 8px; }\n .preview .rich-text img { max-width: 100%; }\n .preview .rich-text img[data-align=\"left\"] { display: block !important; margin: 0 auto 0 0 !important; }\n .preview .rich-text img[data-align=\"center\"] { display: block !important; margin: 0 auto !important; }\n .preview .rich-text img[data-align=\"right\"] { display: block !important; margin: 0 0 0 auto !important; }\n .scale-table-wrap {\n margin-top: 12px;\n background: #fff;\n overflow: hidden;\n }\n .scale-table { width: 100%; border-collapse: collapse; font-size: 12px; }\n .scale-table th, .scale-table td { border: 1px solid #e4e7ed; padding: 8px 6px; text-align: center; }\n .scale-table th { background: #f5f7fa; color: #909399; }\n .scale-table td:first-child,\n .scale-table th:first-child {\n background: #fbfcff;\n color: #606266;\n font-weight: 600;\n }\n .scale-table input[type=\"radio\"] {\n accent-color: #3D61E3;\n }\n\n .flex { display: flex; }\n .flex-items-start { display: flex; align-items: flex-start; }\n .flex-justify-end { display: flex; justify-content: flex-end; }\n .label { min-width: 60px; font-size: 13px; color: #606266; }\n\n textarea, input[type=\"text\"] {\n border: 1px solid #dcdfe6; border-radius: 3px; padding: 5px 11px;\n font-size: 13px; font-family: inherit; width: 100%; resize: none; transition: border-color .2s;\n line-height: 1.5; display: block; box-sizing: border-box; white-space: pre-wrap;\n }\n textarea:focus, input[type=\"text\"]:focus { border-color: #3D61E3; outline: none; }\n textarea:disabled, input[type=\"text\"]:disabled { background: #f5f7fa; color: #c0c4cc; cursor: not-allowed; }\n\n .el-input { position: relative; display: block; }\n .el-input textarea { padding-bottom: 24px; }\n .el-input .char-counter {\n position: absolute; right: 12px; bottom: 8px;\n font-size: 12px; color: #909399; line-height: 1; pointer-events: none;\n }\n\n .el-link { color: #3D61E3; cursor: pointer; font-size: 12px; }\n .el-link.danger { color: #f56c6c; }\n\n .answer-item { display: flex; align-items: center; margin-top: 6px; }\n .answer-item .label { min-width: 60px; font-size: 13px; color: #909399; }\n .answer-item .input { flex: 1; max-width: 200px; }\n .answer-item .input input {\n height: 32px; padding: 0 8px;\n font-size: 13px; line-height: 32px;\n border: 1px solid #dcdfe6; border-radius: 3px; width: 100%;\n transition: border-color .2s; box-sizing: border-box;\n }\n .answer-item .input input:focus { border-color: #3D61E3; outline: none; }\n\n .answer-item .icon {\n margin-left: 6px; cursor: pointer; display: inline-flex;\n align-items: center; justify-content: center;\n width: 24px; height: 24px; border-radius: 4px;\n border: 1px solid #dcdfe6; background: #fff; color: #909399;\n transition: all 0.2s;\n }\n .answer-item .icon:hover { color: #3D61E3; border-color: #3D61E3; background: #ecf5ff; }\n .answer-item .icon.disabled { color: #e4e7ed; border-color: #e4e7ed; cursor: not-allowed; }\n\n .row-title-textarea { height: 200px; }\n `]\n\n @property({ type: Number, attribute: 'order-index' }) 'order-index' = 0\n @property({ type: String }) title = ''\n @property({ type: String, attribute: 'custom-id' }) 'custom-id' = ''\n @property({ type: Boolean, attribute: 'is-edit' }) 'is-edit' = false\n @property({ type: Boolean, attribute: 'is-save' }) 'is-save' = false\n @property({ type: Boolean, attribute: 'is-set' }) 'is-set' = false\n @property({ type: Boolean, attribute: 'show-action' }) 'show-action' = true\n @property({ type: Boolean, attribute: 'show-add' }) 'show-add' = true\n @property({ type: Boolean, reflect: true }) sorting = false\n @property({ type: String }) analysis = ''\n @property({ type: String, attribute: 'rich-text-content' }) 'rich-text-content' = ''\n @property({ type: Number, attribute: 'exam-answer-relation-type' }) 'exam-answer-relation-type' = 0\n @property({ type: Object, attribute: 'upload-image' })\n 'upload-image': (file: File) => Promise<string> = async (file: File) => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader()\n reader.onload = e => resolve(e.target?.result as string)\n reader.onerror = reject\n reader.readAsDataURL(file)\n })\n }\n\n @property({ type: Array, attribute: 'answer-list' })\n get 'answer-list'() { return this._answers }\n\n set 'answer-list'(value: any) {\n const answers = normalizeScaleAnswers(value)\n this._answers = answers.length ? answers : createDefaultScaleAnswers()\n this.requestUpdate('answer-list')\n }\n\n @property({ type: Array, attribute: 'scale-question-list' })\n get 'scale-question-list'() { return this._scaleQuestions }\n\n set 'scale-question-list'(value: any) {\n this._scaleQuestions = normalizeScaleQuestionList(value)\n this.requestUpdate('scale-question-list')\n }\n\n @property({ type: Array, attribute: 'scale-questions' })\n get 'scale-questions'() { return this._scaleQuestions }\n\n set 'scale-questions'(value: any) {\n this['scale-question-list'] = value\n this.requestUpdate('scale-questions')\n }\n\n @state() private _answers: ScaleAnswer[] = createDefaultScaleAnswers()\n @state() private _scaleQuestions: string[] = []\n @state() private _rowTitle = ''\n @state() private _title = ''\n @state() private _showRichText = false\n @state() private _richText = ''\n\n @property({ type: String, attribute: 'model-value' }) 'model-value' = ''\n @property({ type: Boolean, attribute: 'use-model' }) 'use-model' = false\n\n private readonly TITLE_MAX = 200\n\n willUpdate(changed: Map<string, unknown>) {\n const shouldSyncProps = changed.has('title')\n || changed.has('answer-list')\n || changed.has('rich-text-content')\n || changed.has('scale-question-list')\n || changed.has('scale-questions')\n\n if ((changed.has('is-edit') && this['is-edit']) || (!this['is-edit'] && shouldSyncProps)) {\n this._syncProps()\n }\n\n if (changed.has('model-value') && this['use-model']) {\n this._title = this['model-value']\n }\n }\n\n private _syncProps() {\n this._title = this.title || ''\n this._rowTitle = this._scaleQuestions.join('\\n')\n this._richText = this['rich-text-content'] || ''\n this._showRichText = !!this['rich-text-content']\n }\n\n private _emit(name: string, detail?: unknown) {\n this.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true, detail: detail ?? null }))\n }\n\n private _onTitleInput(e: Event) {\n const el = e.target as HTMLTextAreaElement\n if (el.value.length > this.TITLE_MAX) {\n el.value = el.value.slice(0, this.TITLE_MAX)\n }\n this._title = el.value\n if (this['use-model']) {\n this.dispatchEvent(new CustomEvent('update:modelValue', {\n bubbles: true,\n composed: true,\n detail: this._title,\n }))\n }\n }\n\n private _resolvedQuestions(): string[] {\n const rowTitle = this['is-edit'] ? this._rowTitle : this._scaleQuestions.join('\\n')\n return splitScaleQuestionLines(rowTitle)\n }\n\n async toJSON(): Promise<any> {\n return new Promise((resolve, reject) => {\n const row = {\n customId: this['custom-id'] || undefined,\n answerType: SubjectType.SCALE,\n orderIndex: this['order-index'],\n }\n\n const title = trimText(this['is-edit'] ? this._title : this.title || '')\n const answers = this['is-edit'] ? this._answers : this['answer-list']\n const questions = this._resolvedQuestions()\n const richText = this['is-edit'] ? this._richText : this['rich-text-content'] || ''\n const showRichText = this['is-edit'] ? this._showRichText : !!this['rich-text-content']\n\n if (!title) {\n reject(new SubjectError('题目标题不能为空!', 'EMPTY_TITLE', 'title', row))\n return\n }\n\n for (let i = 0; i < answers.length; i++) {\n if (!answers[i].title) {\n reject(new SubjectError(`选项${String.fromCharCode(65 + i)}未填写。`, 'ANSWER_EMPTY', 'answers', row))\n return\n }\n }\n\n if (questions.length === 0) {\n reject(new SubjectError('行标题不能为空!', 'EMPTY_ROW_TITLE', 'rowTitle', row))\n return\n }\n\n const result: any = {\n answerType: SubjectType.SCALE,\n examTypeEnum: SubjectType.SCALE,\n title,\n answers: answers.map(serializeScaleAnswer),\n scaleQuestionList: questions,\n analysis: trimText(this.analysis || ''),\n examRichTextContent: showRichText ? richText : '',\n isSetCorrectAnswer: false,\n }\n\n if (this['custom-id']) {\n result.customId = this['custom-id']\n }\n\n resolve(result)\n })\n }\n\n private async _save(e?: Event) {\n e?.stopImmediatePropagation()\n try {\n const data = await this.toJSON()\n this._emit('save', data)\n }\n catch (err: any) {\n showToast(err.message)\n }\n }\n\n validate(): SubjectError[] {\n const errors: SubjectError[] = []\n const row = {\n customId: this['custom-id'] || undefined,\n answerType: SubjectType.SCALE,\n orderIndex: this['order-index'],\n }\n\n const title = trimText(this['is-edit'] ? this._title : this.title || '')\n const answers = this['is-edit'] ? this._answers : this['answer-list']\n const questions = this._resolvedQuestions()\n\n if (!title) {\n errors.push(new SubjectError('题目标题不能为空!', 'EMPTY_TITLE', 'title', row))\n }\n\n answers.forEach((answer: ScaleAnswer, index: number) => {\n if (!answer.title) {\n errors.push(new SubjectError(`选项${String.fromCharCode(65 + index)}未填写`, 'ANSWER_EMPTY', 'answers', row))\n }\n })\n\n if (questions.length === 0) {\n errors.push(new SubjectError('行标题不能为空!', 'EMPTY_ROW_TITLE', 'rowTitle', row))\n }\n\n return errors\n }\n\n private _renderPreview() {\n const colWidth = Math.floor(100 / ((this._answers.length || 1) + 1))\n\n return html`\n <div class=\"preview\">\n <span class=\"title\">${this['order-index'] + 1}.${this.title}(量表题)</span>\n ${this['rich-text-content'] ? html`<div class=\"rich-text\" .innerHTML=${this['rich-text-content']}></div>` : ''}\n <div class=\"scale-table-wrap\">\n <table class=\"scale-table\">\n <thead>\n <tr>\n <th style=\"width:${colWidth}%\">问题 \\ 选项</th>\n ${this._answers.map(answer => html`<th style=\"width:${colWidth}%\">${answer.title}</th>`)}\n </tr>\n </thead>\n <tbody>\n ${this._scaleQuestions.map(question => html`\n <tr>\n <td>${question}</td>\n ${this._answers.map(() => html`<td><input type=\"radio\" disabled /></td>`)}\n </tr>\n `)}\n </tbody>\n </table>\n </div>\n </div>\n `\n }\n\n private _renderEdit() {\n return html`\n <div class=\"flex-items-start\">\n <div class=\"label\"><span>题目:</span></div>\n <div style=\"flex:1\">\n <div class=\"el-input\">\n <textarea\n rows=\"2\"\n .value=${this._title}\n maxlength=${this.TITLE_MAX}\n @input=${(e: Event) => this._onTitleInput(e)}\n placeholder=\"【量表题】请输入问题\"\n ></textarea>\n <span class=\"char-counter\">${this._title.length}/${this.TITLE_MAX}</span>\n </div>\n </div>\n </div>\n\n <slot name=\"business-tag\"></slot>\n\n <div class=\"flex-items-start\" style=\"margin-top:12px\">\n <div class=\"label\"><span>行标题:</span></div>\n <div class=\"flex\" style=\"flex:1\">\n <div class=\"el-input\" style=\"width:160px\">\n <textarea\n class=\"row-title-textarea\"\n .value=${this._rowTitle}\n @input=${(e: Event) => { this._rowTitle = (e.target as HTMLTextAreaElement).value }}\n @keydown=${(e: KeyboardEvent) => { e.stopPropagation() }}\n placeholder=\"请输入行标题\"\n ></textarea>\n </div>\n <div style=\"flex:1;margin-left:12px\">\n ${this._answers.map((answer, index) => html`\n <div class=\"answer-item\">\n <span class=\"label\">${String.fromCharCode(65 + index)}.</span>\n <div class=\"input\">\n <input\n type=\"text\"\n .value=${answer.title}\n maxlength=\"10\"\n @input=${(e: Event) => {\n const value = (e.target as HTMLInputElement).value\n this._answers = this._answers.map((item, currentIndex) =>\n currentIndex === index ? { ...item, title: value } : item,\n )\n }}\n placeholder=\"选项${index + 1}\"\n />\n </div>\n <span\n class=\"icon\"\n @click=${() => {\n if (this._answers.length < 5) {\n this._answers = [...this._answers, createEmptyScaleAnswer()]\n }\n }}\n >${iconPlus}</span>\n <span\n class=\"icon ${this._answers.length < 3 ? 'disabled' : ''}\"\n @click=${() => {\n if (this._answers.length > 3) {\n this._answers = this._answers.filter((_, currentIndex) => currentIndex !== index)\n }\n }}\n >${iconRemove}</span>\n </div>\n `)}\n </div>\n </div>\n </div>\n\n ${this._showRichText\n ? html`\n <div class=\"flex-items-start\" style=\"margin-top:12px\">\n <div class=\"label\"><span>副文本:</span></div>\n <div style=\"flex:1\">\n <slot name=\"sub-text\">\n <qxs-blocksuite-editor\n .content=${this._richText}\n .upload-image=${this['upload-image']}\n ?is-edit=${true}\n @input=${(e: CustomEvent) => { this._richText = (e.target as any).getContent() }}\n ></qxs-blocksuite-editor>\n </slot>\n ${!this['show-action']\n ? html`\n <div class=\"flex-justify-end\" style=\"margin-top:8px\">\n <span\n class=\"el-link danger\"\n @click=${() => {\n this._showRichText = false\n this._richText = ''\n }}\n >删除富文本</span>\n </div>\n `\n : ''}\n </div>\n </div>\n `\n : ''}\n `\n }\n\n private _renderSorting() {\n const title = trimText(this['is-edit'] ? this._title : this.title || '') || '未命名题目'\n const orderText = `${this['order-index'] + 1}. ${title}`\n return renderSortingCard(orderText, SubjectTypeLabel[SubjectType.SCALE] || SubjectType.SCALE)\n }\n\n render() {\n if (this.sorting) {\n return this._renderSorting()\n }\n\n const content = this['is-edit']\n ? html`<div slot=\"edit\">${this._renderEdit()}</div>`\n : html`<div slot=\"preview\">${this._renderPreview()}</div>`\n\n return html`\n <qxs-subject-layout .show-edit=${this['is-edit']}>\n ${content}\n ${this['show-action']\n ? html`\n <qxs-subject-action\n .is-edit=${this['is-edit']}\n .is-set=${this['is-set']}\n .show-add=${this['show-add']}\n .show-rich-text=${this._showRichText}\n .show-other-option=${false}\n exam-answer-relation-type=${this['exam-answer-relation-type']}\n @delete=${() => this._emit('delete')}\n @save=${this._save}\n @edit=${() => this._emit('edit')}\n @add=${(e: CustomEvent) => this._emit('add', e.detail)}\n @on-show-rich-text=${() => {\n this._showRichText = !this._showRichText\n if (!this._showRichText) {\n this._richText = ''\n }\n }}\n ></qxs-subject-action>\n `\n : ''}\n </qxs-subject-layout>\n `\n }\n}\n\nexport function register() {}\n"],"names":["createEmptyScaleAnswer","title","createDefaultScaleAnswers","Array","from","length","normalizeScaleAnswer","answer","next","trimText","answerId","examAnswerId","serializeScaleAnswer","index","orderIndex","isCorrect","iconPlus","html","iconRemove","QxsScale","LitElement","constructor","super","arguments","this","sorting","analysis","async","Promise","resolve","reject","reader","FileReader","onload","e","target","result","onerror","readAsDataURL","file","_answers","_scaleQuestions","_rowTitle","_title","_showRichText","_richText","TITLE_MAX","value","answers","isArray","slice","map","normalizeScaleAnswers","requestUpdate","item","String","trim","filter","Boolean","normalizeScaleQuestionList","willUpdate","changed","shouldSyncProps","has","_syncProps","join","_emit","name","detail","dispatchEvent","CustomEvent","bubbles","composed","_onTitleInput","el","_resolvedQuestions","rowTitle","split","toJSON","row","customId","answerType","SubjectType","SCALE","questions","richText","showRichText","SubjectError","i","fromCharCode","examTypeEnum","scaleQuestionList","examRichTextContent","isSetCorrectAnswer","_save","stopImmediatePropagation","data","err","msg","document","createElement","textContent","Object","assign","style","position","top","left","transform","padding","borderRadius","fontSize","color","background","zIndex","boxShadow","transition","opacity","body","appendChild","setTimeout","remove","showToast","message","validate","errors","push","forEach","_renderPreview","colWidth","Math","floor","question","_renderEdit","stopPropagation","currentIndex","_","getContent","_renderSorting","orderText","renderSortingCard","SubjectTypeLabel","render","content","styles","sortingCardStyles","css","__decorateClass","property","type","Number","attribute","prototype","reflect","state","safeCustomElement"],"mappings":"2iBAeA,SAASA,IACP,MAAO,CAAEC,MAAO,GAClB,CAEA,SAASC,IACP,OAAOC,MAAMC,KAAK,CAA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AA,CADCC,EAAS,CAAEC,KAAM/C,OAAQiD,UAAW,kBAzF1BpI,EA0FXqI,UAAA,eAAA,GAUIL,EAAA,CADHC,EAAS,CAAEC,KAAMlJ,MAAOoJ,UAAW,iBAnGzBpI,EAoGPqI,UAAA,cAAA,GASAL,EAAA,CADHC,EAAS,CAAEC,KAAMlJ,MAAOoJ,UAAW,yBA5GzBpI,EA6GPqI,UAAA,sBAAA,GAQAL,EAAA,CADHC,EAAS,CAAEC,KAAMlJ,MAAOoJ,UAAW,qBApHzBpI,EAqHPqI,UAAA,kBAAA,GAOaL,EAAA,CAAhBO,KA5HUvI,EA4HMqI,UAAA,WAAA,GACAL,EAAA,CAAhBO,KA7HUvI,EA6HMqI,UAAA,kBAAA,GACAL,EAAA,CAAhBO,KA9HUvI,EA8HMqI,UAAA,YAAA,GACAL,EAAA,CAAhBO,KA/HUvI,EA+HMqI,UAAA,SAAA,GACAL,EAAA,CAAhBO,KAhIUvI,EAgIMqI,UAAA,gBAAA,GACAL,EAAA,CAAhBO,KAjIUvI,EAiIMqI,UAAA,YAAA,GAEqCL,EAAA,CAArDC,EAAS,CAAEC,KAAM9F,OAAQgG,UAAW,iBAnI1BpI,EAmI2CqI,UAAA,cAAA,GACDL,EAAA,CAApDC,EAAS,CAAEC,KAAM3F,QAAS6F,UAAW,eApI3BpI,EAoI0CqI,UAAA,YAAA,GApI1CrI,EAANgI,EAAA,CADNQ,EAAkB,cACNxI"}
1
+ {"version":3,"file":"scale.mjs","sources":["../../../../packages/components-wc/src/subject/scale.ts"],"sourcesContent":["import { css, html, LitElement } from 'lit'\nimport { property, state } from 'lit/decorators.js'\nimport { safeCustomElement } from '../base/define'\nimport { SubjectError, trimText } from './single'\nimport { renderSortingCard, sortingCardStyles } from './sorting-card'\nimport { SubjectType, SubjectTypeLabel } from './types'\n\ninterface ScaleAnswer {\n title: string\n answerId?: string | number\n orderIndex?: number\n isCorrect?: boolean\n [key: string]: any\n}\n\nfunction createEmptyScaleAnswer(): ScaleAnswer {\n return { title: '' }\n}\n\nfunction createDefaultScaleAnswers(): ScaleAnswer[] {\n return Array.from({ length: 5 }, createEmptyScaleAnswer)\n}\n\nfunction normalizeScaleAnswer(answer: any): ScaleAnswer {\n const next: ScaleAnswer = {\n ...answer,\n title: trimText(answer?.title ?? answer?.answer ?? ''),\n }\n const answerId = answer?.answerId ?? answer?.examAnswerId\n if (answerId !== undefined) {\n next.answerId = answerId\n }\n delete next.answer\n delete next.examAnswerId\n delete next.isCorrect\n return next\n}\n\nfunction normalizeScaleAnswers(value: any): ScaleAnswer[] {\n return Array.isArray(value) ? value.map(normalizeScaleAnswer) : []\n}\n\nfunction normalizeScaleQuestionList(value: any): string[] {\n if (!Array.isArray(value)) {\n return []\n }\n return value\n .map(item => String(item ?? '').trim())\n .filter(Boolean)\n}\n\nfunction splitScaleQuestionLines(value: string): string[] {\n return value\n .split('\\n')\n .map(item => item.trim())\n .filter(Boolean)\n}\n\nfunction serializeScaleAnswer(answer: any, index: number): ScaleAnswer {\n const next: ScaleAnswer = {\n ...normalizeScaleAnswer(answer),\n orderIndex: index + 1,\n answer: trimText(answer?.title ?? answer?.answer ?? ''),\n }\n next.title = trimText(next.title ?? '')\n if (next.answerId !== undefined) {\n next.examAnswerId = next.answerId\n }\n if (next.answerId === undefined) {\n delete next.answerId\n }\n delete next.isCorrect\n return next\n}\n\nconst iconPlus = html`<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><line x1=\"12\" y1=\"5\" x2=\"12\" y2=\"19\"/><line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/></svg>`\nconst iconRemove = html`<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/></svg>`\n\nfunction showToast(msg: string) {\n const el = document.createElement('div')\n el.textContent = msg\n Object.assign(el.style, {\n position: 'fixed', top: '20px', left: '50%', transform: 'translateX(-50%)',\n padding: '10px 20px', borderRadius: '4px', fontSize: '13px', color: '#fff',\n background: '#f56c6c', zIndex: '99999', boxShadow: '0 4px 12px rgba(0,0,0,.15)',\n transition: 'opacity .3s', opacity: '1',\n })\n document.body.appendChild(el)\n setTimeout(() => {\n el.style.opacity = '0'\n setTimeout(() => el.remove(), 300)\n }, 2500)\n}\n\n@safeCustomElement('qxs-scale')\nexport class QxsScale extends LitElement {\n static styles = [sortingCardStyles, css`\n :host { display: block; font-family: system-ui, -apple-system, \"PingFang SC\", \"Microsoft YaHei\", sans-serif; font-size: 12px; color: #5a5a5a; }\n *, ::before, ::after { box-sizing: border-box; }\n\n .preview { padding: 12px 0; }\n .preview .title { font-size: 14px; color: #303133; }\n .preview .rich-text { margin-top: 8px; }\n .preview .rich-text img { max-width: 100%; }\n .preview .rich-text img[data-align=\"left\"] { display: block !important; margin: 0 auto 0 0 !important; }\n .preview .rich-text img[data-align=\"center\"] { display: block !important; margin: 0 auto !important; }\n .preview .rich-text img[data-align=\"right\"] { display: block !important; margin: 0 0 0 auto !important; }\n .scale-table-wrap {\n margin-top: 12px;\n background: #fff;\n overflow: hidden;\n }\n .scale-table { width: 100%; border-collapse: collapse; font-size: 12px; }\n .scale-table th, .scale-table td { border: 1px solid #e4e7ed; padding: 8px 6px; text-align: center; }\n .scale-table th { background: #f5f7fa; color: #909399; }\n .scale-table td:first-child,\n .scale-table th:first-child {\n background: #fbfcff;\n color: #606266;\n font-weight: 600;\n }\n .scale-table input[type=\"radio\"] {\n accent-color: #3D61E3;\n }\n\n .flex { display: flex; }\n .flex-items-start { display: flex; align-items: flex-start; }\n .flex-justify-end { display: flex; justify-content: flex-end; }\n .label { min-width: 60px; font-size: 13px; color: #606266; }\n\n textarea, input[type=\"text\"] {\n border: 1px solid #dcdfe6; border-radius: 3px; padding: 5px 11px;\n font-size: 13px; font-family: inherit; width: 100%; resize: none; transition: border-color .2s;\n line-height: 1.5; display: block; box-sizing: border-box; white-space: pre-wrap;\n }\n textarea:focus, input[type=\"text\"]:focus { border-color: #3D61E3; outline: none; }\n textarea:disabled, input[type=\"text\"]:disabled { background: #f5f7fa; color: #c0c4cc; cursor: not-allowed; }\n\n .el-input { position: relative; display: block; }\n .el-input textarea { padding-bottom: 24px; }\n .el-input .char-counter {\n position: absolute; right: 12px; bottom: 8px;\n font-size: 12px; color: #909399; line-height: 1; pointer-events: none;\n }\n\n .el-link { color: #3D61E3; cursor: pointer; font-size: 12px; }\n .el-link.danger { color: #f56c6c; }\n\n .answer-item { display: flex; align-items: center; margin-top: 6px; }\n .answer-item .label { min-width: 60px; font-size: 13px; color: #909399; }\n .answer-item .input { flex: 1; max-width: 200px; }\n .answer-item .input input {\n height: 32px; padding: 0 8px;\n font-size: 13px; line-height: 32px;\n border: 1px solid #dcdfe6; border-radius: 3px; width: 100%;\n transition: border-color .2s; box-sizing: border-box;\n }\n .answer-item .input input:focus { border-color: #3D61E3; outline: none; }\n\n .answer-item .icon {\n margin-left: 6px; cursor: pointer; display: inline-flex;\n align-items: center; justify-content: center;\n width: 24px; height: 24px; border-radius: 4px;\n border: 1px solid #dcdfe6; background: #fff; color: #909399;\n transition: all 0.2s;\n }\n .answer-item .icon:hover { color: #3D61E3; border-color: #3D61E3; background: #ecf5ff; }\n .answer-item .icon.disabled { color: #e4e7ed; border-color: #e4e7ed; cursor: not-allowed; }\n\n .row-title-textarea { height: 200px; }\n `]\n\n @property({ type: Number, attribute: 'order-index' }) 'order-index' = 0\n @property({ type: String }) title = ''\n @property({ type: String, attribute: 'custom-id' }) 'custom-id' = ''\n @property({ type: Boolean, attribute: 'is-edit' }) 'is-edit' = false\n @property({ type: Boolean, attribute: 'is-save' }) 'is-save' = false\n @property({ type: Boolean, attribute: 'is-set' }) 'is-set' = false\n @property({ type: Boolean, attribute: 'show-action' }) 'show-action' = true\n @property({ type: Boolean, attribute: 'show-add' }) 'show-add' = true\n @property({ type: Boolean, attribute: 'hide-add-rich-text' }) 'hide-add-rich-text' = false\n @property({ type: Boolean, attribute: 'show-rich-text' }) 'show-rich-text' = false\n @property({ type: Boolean, attribute: 'show-delete-action' }) 'show-delete-action' = true\n @property({ type: Boolean, attribute: 'show-save-action' }) 'show-save-action' = true\n @property({ type: Boolean, reflect: true }) sorting = false\n @property({ type: Boolean, attribute: 'show-analysis' }) 'show-analysis' = false\n @property({ type: String }) analysis = ''\n @property({ type: String, attribute: 'rich-text-content' }) 'rich-text-content' = ''\n @property({ type: Number, attribute: 'exam-answer-relation-type' }) 'exam-answer-relation-type' = 0\n @property({ type: Object, attribute: 'upload-image' })\n 'upload-image': (file: File) => Promise<string> = async (file: File) => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader()\n reader.onload = e => resolve(e.target?.result as string)\n reader.onerror = reject\n reader.readAsDataURL(file)\n })\n }\n\n @property({ type: Array, attribute: 'answer-list' })\n get 'answer-list'() { return this._answers }\n\n set 'answer-list'(value: any) {\n const answers = normalizeScaleAnswers(value)\n this._answers = answers.length ? answers : createDefaultScaleAnswers()\n this.requestUpdate('answer-list')\n }\n\n @property({ type: Array, attribute: 'scale-question-list' })\n get 'scale-question-list'() { return this._scaleQuestions }\n\n set 'scale-question-list'(value: any) {\n this._scaleQuestions = normalizeScaleQuestionList(value)\n this.requestUpdate('scale-question-list')\n }\n\n @property({ type: Array, attribute: 'scale-questions' })\n get 'scale-questions'() { return this._scaleQuestions }\n\n set 'scale-questions'(value: any) {\n this['scale-question-list'] = value\n this.requestUpdate('scale-questions')\n }\n\n @state() private _answers: ScaleAnswer[] = createDefaultScaleAnswers()\n @state() private _scaleQuestions: string[] = []\n @state() private _rowTitle = ''\n @state() private _title = ''\n @state() private _analysis = ''\n @state() private _showRichText = false\n @state() private _richText = ''\n\n @property({ type: String, attribute: 'model-value' }) 'model-value' = ''\n @property({ type: Boolean, attribute: 'use-model' }) 'use-model' = false\n\n private readonly TITLE_MAX = 200\n\n willUpdate(changed: Map<string, unknown>) {\n const shouldSyncProps = changed.has('title')\n || changed.has('answer-list')\n || changed.has('rich-text-content')\n || changed.has('scale-question-list')\n || changed.has('scale-questions')\n\n if ((changed.has('is-edit') && this['is-edit']) || (!this['is-edit'] && shouldSyncProps)) {\n this._syncProps()\n }\n\n if (changed.has('model-value') && this['use-model']) {\n this._title = this['model-value']\n }\n }\n\n private _syncProps() {\n this._title = this.title || ''\n this._analysis = this.analysis || ''\n this._rowTitle = this._scaleQuestions.join('\\n')\n this._richText = this['rich-text-content'] || ''\n this._showRichText = !!this['rich-text-content']\n }\n\n private _emit(name: string, detail?: unknown) {\n this.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true, detail: detail ?? null }))\n }\n\n private _onTitleInput(e: Event) {\n const el = e.target as HTMLTextAreaElement\n if (el.value.length > this.TITLE_MAX) {\n el.value = el.value.slice(0, this.TITLE_MAX)\n }\n this._title = el.value\n if (this['use-model']) {\n this.dispatchEvent(new CustomEvent('update:modelValue', {\n bubbles: true,\n composed: true,\n detail: this._title,\n }))\n }\n }\n\n private _resolvedQuestions(): string[] {\n const rowTitle = this['is-edit'] ? this._rowTitle : this._scaleQuestions.join('\\n')\n return splitScaleQuestionLines(rowTitle)\n }\n\n private _resolvedAnswers(): ScaleAnswer[] {\n const answers = this['is-edit'] ? this._answers : this['answer-list']\n return Array.isArray(answers) ? answers.map(normalizeScaleAnswer) : []\n }\n\n private _createAnswerCountError(row: Record<string, unknown>) {\n return new SubjectError('量表题选项数量必须在 3-5 个之间!', 'ANSWER_COUNT_INVALID', 'answers', row)\n }\n\n async toJSON(): Promise<any> {\n return new Promise((resolve, reject) => {\n const row = {\n customId: this['custom-id'] || undefined,\n answerType: SubjectType.SCALE,\n orderIndex: this['order-index'],\n }\n\n const title = trimText(this['is-edit'] ? this._title : this.title || '')\n const answers = this._resolvedAnswers()\n const questions = this._resolvedQuestions()\n const richText = this['is-edit'] ? this._richText : this['rich-text-content'] || ''\n const showRichText = this['show-rich-text'] && (this['is-edit'] ? this._showRichText : !!this['rich-text-content'])\n\n if (!title) {\n reject(new SubjectError('题目标题不能为空!', 'EMPTY_TITLE', 'title', row))\n return\n }\n\n if (answers.length < 3 || answers.length > 5) {\n reject(this._createAnswerCountError(row))\n return\n }\n\n for (let i = 0; i < answers.length; i++) {\n if (!answers[i].title) {\n reject(new SubjectError(`选项${String.fromCharCode(65 + i)}未填写。`, 'ANSWER_EMPTY', 'answers', row))\n return\n }\n }\n\n if (questions.length === 0) {\n reject(new SubjectError('行标题不能为空!', 'EMPTY_ROW_TITLE', 'rowTitle', row))\n return\n }\n\n const result: any = {\n answerType: SubjectType.SCALE,\n examTypeEnum: SubjectType.SCALE,\n title,\n answers: answers.map(serializeScaleAnswer),\n scaleQuestionList: questions,\n analysis: trimText(this['is-edit'] ? this._analysis : this.analysis || ''),\n examRichTextContent: showRichText ? richText : '',\n isSetCorrectAnswer: false,\n }\n\n if (this['custom-id']) {\n result.customId = this['custom-id']\n }\n if (this['exam-answer-relation-type']) {\n result.examAnswerRelationType = this['exam-answer-relation-type']\n }\n\n resolve(result)\n })\n }\n\n private async _save(e?: Event) {\n e?.stopImmediatePropagation()\n try {\n const data = await this.toJSON()\n this._emit('save', data)\n }\n catch (err: any) {\n showToast(err.message)\n }\n }\n\n validate(): SubjectError[] {\n const errors: SubjectError[] = []\n const row = {\n customId: this['custom-id'] || undefined,\n answerType: SubjectType.SCALE,\n orderIndex: this['order-index'],\n }\n\n const title = trimText(this['is-edit'] ? this._title : this.title || '')\n const answers = this._resolvedAnswers()\n const questions = this._resolvedQuestions()\n\n if (!title) {\n errors.push(new SubjectError('题目标题不能为空!', 'EMPTY_TITLE', 'title', row))\n }\n\n if (answers.length < 3 || answers.length > 5) {\n errors.push(this._createAnswerCountError(row))\n return errors\n }\n\n answers.forEach((answer: ScaleAnswer, index: number) => {\n if (!answer.title) {\n errors.push(new SubjectError(`选项${String.fromCharCode(65 + index)}未填写`, 'ANSWER_EMPTY', 'answers', row))\n }\n })\n\n if (questions.length === 0) {\n errors.push(new SubjectError('行标题不能为空!', 'EMPTY_ROW_TITLE', 'rowTitle', row))\n }\n\n return errors\n }\n\n private _renderPreview() {\n const answers = this._resolvedAnswers()\n const questions = this._resolvedQuestions()\n const colWidth = Math.floor(100 / ((answers.length || 1) + 1))\n\n return html`\n <div class=\"preview\">\n <span class=\"title\">${this['order-index'] + 1}.${this.title}(量表题)</span>\n ${this['show-rich-text'] && this['rich-text-content'] ? html`<div class=\"rich-text\" .innerHTML=${this['rich-text-content']}></div>` : ''}\n <div class=\"scale-table-wrap\">\n <table class=\"scale-table\">\n <thead>\n <tr>\n <th style=\"width:${colWidth}%\">问题 \\ 选项</th>\n ${answers.map(answer => html`<th style=\"width:${colWidth}%\">${answer.title}</th>`)}\n </tr>\n </thead>\n <tbody>\n ${questions.map(question => html`\n <tr>\n <td>${question}</td>\n ${answers.map(() => html`<td><input type=\"radio\" disabled /></td>`)}\n </tr>\n `)}\n </tbody>\n </table>\n </div>\n </div>\n `\n }\n\n private _renderEdit() {\n return html`\n <div class=\"flex-items-start\">\n <div class=\"label\"><span>题目:</span></div>\n <div style=\"flex:1\">\n <div class=\"el-input\">\n <textarea\n rows=\"2\"\n .value=${this._title}\n maxlength=${this.TITLE_MAX}\n @input=${(e: Event) => this._onTitleInput(e)}\n placeholder=\"【量表题】请输入问题\"\n ></textarea>\n <span class=\"char-counter\">${this._title.length}/${this.TITLE_MAX}</span>\n </div>\n </div>\n </div>\n\n <slot name=\"business-tag\"></slot>\n\n <div class=\"flex-items-start\" style=\"margin-top:12px\">\n <div class=\"label\"><span>行标题:</span></div>\n <div class=\"flex\" style=\"flex:1\">\n <div class=\"el-input\" style=\"width:160px\">\n <textarea\n class=\"row-title-textarea\"\n .value=${this._rowTitle}\n @input=${(e: Event) => { this._rowTitle = (e.target as HTMLTextAreaElement).value }}\n @keydown=${(e: KeyboardEvent) => { e.stopPropagation() }}\n placeholder=\"请输入行标题\"\n ></textarea>\n </div>\n <div style=\"flex:1;margin-left:12px\">\n ${this._answers.map((answer, index) => html`\n <div class=\"answer-item\">\n <span class=\"label\">${String.fromCharCode(65 + index)}.</span>\n <div class=\"input\">\n <input\n type=\"text\"\n .value=${answer.title}\n maxlength=\"10\"\n @input=${(e: Event) => {\n const value = (e.target as HTMLInputElement).value\n this._answers = this._answers.map((item, currentIndex) =>\n currentIndex === index ? { ...item, title: value } : item,\n )\n }}\n placeholder=\"选项${index + 1}\"\n />\n </div>\n <span\n class=\"icon\"\n @click=${() => {\n if (this._answers.length < 5) {\n this._answers = [...this._answers, createEmptyScaleAnswer()]\n }\n }}\n >${iconPlus}</span>\n <span\n class=\"icon ${this._answers.length < 3 ? 'disabled' : ''}\"\n @click=${() => {\n if (this._answers.length > 3) {\n this._answers = this._answers.filter((_, currentIndex) => currentIndex !== index)\n }\n }}\n >${iconRemove}</span>\n </div>\n `)}\n </div>\n </div>\n </div>\n\n ${this['show-rich-text'] && this._showRichText\n ? html`\n <div class=\"flex-items-start\" style=\"margin-top:12px\">\n <div class=\"label\"><span>副文本:</span></div>\n <div style=\"flex:1\">\n <slot name=\"sub-text\">\n <qxs-blocksuite-editor\n .content=${this._richText}\n .upload-image=${this['upload-image']}\n ?is-edit=${true}\n @input=${(e: CustomEvent) => { this._richText = (e.target as any).getContent() }}\n ></qxs-blocksuite-editor>\n </slot>\n ${!this['show-action']\n ? html`\n <div class=\"flex-justify-end\" style=\"margin-top:8px\">\n <span\n class=\"el-link danger\"\n @click=${() => {\n this._showRichText = false\n this._richText = ''\n }}\n >删除富文本</span>\n </div>\n `\n : ''}\n </div>\n </div>\n `\n : ''}\n\n ${this['show-analysis']\n ? html`\n <div class=\"flex-items-start\" style=\"margin-top:12px\">\n <div class=\"label\"><span>解析:</span></div>\n <div style=\"flex:1\">\n <div class=\"el-input\">\n <textarea\n rows=\"2\"\n .value=${this._analysis}\n @input=${(e: Event) => { this._analysis = (e.target as HTMLTextAreaElement).value }}\n placeholder=\"请输入题目解析\"\n ></textarea>\n </div>\n </div>\n </div>\n `\n : ''}\n `\n }\n\n private _renderSorting() {\n const title = trimText(this['is-edit'] ? this._title : this.title || '') || '未命名题目'\n const orderText = `${this['order-index'] + 1}. ${title}`\n return renderSortingCard(orderText, SubjectTypeLabel[SubjectType.SCALE] || SubjectType.SCALE)\n }\n\n render() {\n if (this.sorting) {\n return this._renderSorting()\n }\n\n const content = this['is-edit']\n ? html`<div slot=\"edit\">${this._renderEdit()}</div>`\n : html`<div slot=\"preview\">${this._renderPreview()}</div>`\n\n return html`\n <qxs-subject-layout .show-edit=${this['is-edit']}>\n ${content}\n ${this['show-action']\n ? html`\n <qxs-subject-action\n .is-edit=${this['is-edit']}\n .is-set=${this['is-set']}\n .show-add=${this['show-add']}\n .show-rich-text=${this['show-rich-text'] && this._showRichText}\n .hide-add-rich-text=${!this['show-rich-text'] || this['hide-add-rich-text']}\n .show-delete-action=${this['show-delete-action']}\n .show-save-action=${this['show-save-action']}\n .show-other-option=${false}\n exam-answer-relation-type=${this['exam-answer-relation-type']}\n @delete=${() => this._emit('delete')}\n @save=${this._save}\n @edit=${() => this._emit('edit')}\n @add=${(e: CustomEvent) => this._emit('add', e.detail)}\n @on-show-rich-text=${() => {\n this._showRichText = !this._showRichText\n if (!this._showRichText) {\n this._richText = ''\n }\n }}\n ></qxs-subject-action>\n `\n : ''}\n <slot name=\"action\"></slot>\n </qxs-subject-layout>\n `\n }\n}\n\nexport function register() {}\n"],"names":["createEmptyScaleAnswer","title","createDefaultScaleAnswers","Array","from","length","normalizeScaleAnswer","answer","next","trimText","answerId","examAnswerId","isCorrect","serializeScaleAnswer","index","orderIndex","iconPlus","html","iconRemove","QxsScale","LitElement","constructor","super","arguments","this","sorting","analysis","async","Promise","resolve","reject","reader","FileReader","onload","e","target","result","onerror","readAsDataURL","file","_answers","_scaleQuestions","_rowTitle","_title","_analysis","_showRichText","_richText","TITLE_MAX","value","answers","isArray","map","normalizeScaleAnswers","requestUpdate","item","String","trim","filter","Boolean","normalizeScaleQuestionList","willUpdate","changed","shouldSyncProps","has","_syncProps","join","_emit","name","detail","dispatchEvent","CustomEvent","bubbles","composed","_onTitleInput","el","slice","_resolvedQuestions","rowTitle","split","_resolvedAnswers","_createAnswerCountError","row","SubjectError","toJSON","customId","answerType","SubjectType","SCALE","questions","richText","showRichText","i","fromCharCode","examTypeEnum","scaleQuestionList","examRichTextContent","isSetCorrectAnswer","examAnswerRelationType","_save","stopImmediatePropagation","data","err","msg","document","createElement","textContent","Object","assign","style","position","top","left","transform","padding","borderRadius","fontSize","color","background","zIndex","boxShadow","transition","opacity","body","appendChild","setTimeout","remove","showToast","message","validate","errors","push","forEach","_renderPreview","colWidth","Math","floor","question","_renderEdit","stopPropagation","currentIndex","_","getContent","_renderSorting","orderText","renderSortingCard","SubjectTypeLabel","render","content","styles","sortingCardStyles","css","__decorateClass","property","type","Number","attribute","prototype","reflect","state","safeCustomElement"],"mappings":"2iBAeA,SAASA,IACP,MAAO,CAAEC,MAAO,GAClB,CAEA,SAASC,IACP,OAAOC,MAAMC,KAAK,CAAEC,OAAQ,GAAKL,EACnC,CAEA,SAASM,EAAqBC,GAC5B,MAAMC,EAAoB,IACrBD,EACHN,MAAOQ,EAASF,GAAQN,OAASM,GAAQA,QAAU,KAE/CG,EAAWH,GAAQG,UAAYH,GAAQI,aAO7C,YANiB,IAAbD,IACFF,EAAKE,SAAWA,UAEXF,EAAKD,cACLC,EAAKG,oBACLH,EAAKI,UACLJ,CACT,CAsBA,SAASK,EAAqBN,EAAaO,GACzC,MAAMN,EAAoB,IACrBF,EAAqBC,GACxBQ,WAAYD,EAAQ,EACpBP,OAAQE,EAASF,GAAQN,OAASM,GAAQA,QAAU,KAUtD,OARAC,EAAKP,MAAQQ,EAASD,EAAKP,OAAS,SACd,IAAlBO,EAAKE,WACPF,EAAKG,aAAeH,EAAKE,eAEL,IAAlBF,EAAKE,iBACAF,EAAKE,gBAEPF,EAAKI,UACLJ,CACT,CAEA,MAAMQ,EAAWC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L,EAAA,CAAhBO,KApIU3I,EAoIMyI,UAAA,SAAA,GACAL,EAAA,CAAhBO,KArIU3I,EAqIMyI,UAAA,YAAA,GACAL,EAAA,CAAhBO,KAtIU3I,EAsIMyI,UAAA,gBAAA,GACAL,EAAA,CAAhBO,KAvIU3I,EAuIMyI,UAAA,YAAA,GAEqCL,EAAA,CAArDC,EAAS,CAAEC,KAAMlG,OAAQoG,UAAW,iBAzI1BxI,EAyI2CyI,UAAA,cAAA,GACDL,EAAA,CAApDC,EAAS,CAAEC,KAAM/F,QAASiG,UAAW,eA1I3BxI,EA0I0CyI,UAAA,YAAA,GA1I1CzI,EAANoI,EAAA,CADNQ,EAAkB,cACN5I"}
@@ -1,4 +1,4 @@
1
- import{html as e,css as t,LitElement as s}from"lit";import{property as i,state as r}from"lit/decorators.js";import{safeCustomElement as o}from"../base/define.mjs";import{uid as a}from"../base/uid.mjs";import{sortingCardStyles as n,renderSortingCard as l}from"./sorting-card.mjs";import{SubjectTypeLabel as c}from"./types.mjs";var h=Object.defineProperty,d=Object.getOwnPropertyDescriptor,p=(e,t,s,i)=>{for(var r,o=i>1?void 0:i?d(t,s):t,a=e.length-1;a>=0;a--)(r=e[a])&&(o=(i?r(t,s,o):r(o))||o);return i&&o&&h(t,s,o),o};class u extends Error{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"VALIDATION_ERROR",s=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0;super(e),this.code=t,this.field=s,this.row=i,this.name="SubjectError"}static from(e){return new u(e.message,e.code,e.field,e.row)}}const m=e`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>`,g=e`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>`,w=e`<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>`;function x(e){return e.replace(/^\d+\.\s*/,"").replace(/[\s,,。.!!??;;::、'"“”‘’()()[\]【】\-_/\\]+/g,"").toLowerCase()}function y(e){return String(e??"").trim()}function _(e){return String(e??"").split(",").map(e=>e.trim()).filter(Boolean).join(",")}function v(e){const t=document.createElement("div");t.textContent=e,Object.assign(t.style,{position:"fixed",top:"20px",left:"50%",transform:"translateX(-50%)",padding:"10px 20px",borderRadius:"4px",fontSize:"13px",color:"#fff",background:"#f56c6c",zIndex:"99999",boxShadow:"0 4px 12px rgba(0,0,0,.15)",transition:"opacity .3s",opacity:"1"}),document.body.appendChild(t),setTimeout(()=>{t.style.opacity="0",setTimeout(()=>t.remove(),300)},2500)}let f=class extends s{constructor(){super(...arguments),this["order-index"]=0,this["is-edit"]=!1,this["is-save"]=!1,this["is-set"]=!1,this["is-set-correct-answer"]=!1,this.lockAnswerKey=!1,this["is-key"]=!1,this["show-action"]=!0,this["show-add"]=!0,this.sorting=!1,this["show-answer-setting"]=!1,this["show-key"]=!1,this["show-analysis"]=!0,this.type="single",this["answer-check-type"]=1,this["exam-answer-relation-type"]=0,this["rich-text-content"]="",this.analysis="",this["least-answer-count"]=null,this["exam-expand"]="",this["custom-id"]="",this["exam-id"]=0,this["category-id"]="",this["upload-image"]=async e=>new Promise((t,s)=>{const i=new FileReader;i.onload=e=>t(e.target?.result),i.onerror=s,i.readAsDataURL(e)}),this["tag-list"]=[],this["category-list"]=[],this["ai-answer"]="",this["resource-list"]=[],this["show-tag"]=!1,this["show-category"]=!1,this["show-ai"]=!1,this["show-resource"]=!1,this["show-jump"]=!1,this["has-jump"]=!1,this["search-api"]="",this["model-value"]="",this["use-model"]=!1,this._answers=[{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1}],this.title="",this._title="",this._analysis="",this._richText="",this._showRichText=!1,this._leastAnswerCount=null,this._answerCheckType=1,this._isKey=!1,this._orderList=[],this._selectedTagList=[],this._categoryId="",this._searchResults=[],this._searchOpen=!1,this._searchLoading=!1,this._sortDropdownOpen=!1,this._imageViewerOpen=!1,this._imageViewerIndex=0,this._videoViewerOpen=!1,this._correctHintDialogOpen=!1,this._hasShownCorrectHint=!1,this._changeTypeDialogOpen=!1,this._searchTimer=null,this._searchToken=0,this.TITLE_MAX=200,this.ANSWER_MAX=100,this._handleDocumentClick=e=>{const t=e.composedPath(),s=this.shadowRoot?.querySelector(".multi-select-wrapper"),i=this.shadowRoot?.querySelector(".search-wrap");s&&!t.includes(s)&&(this._sortDropdownOpen=!1),i&&!t.includes(i)&&(this._searchOpen=!1),this.requestUpdate()}}get"answer-list"(){return this._answers}set"answer-list"(e){if(this["is-edit"])return;const t=Array.isArray(e)?e:[];this._answers=t.length?t.map(e=>this._normalizeAnswerItem(e)):[{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1}],this.requestUpdate("answer-list")}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this._handleDocumentClick),this._syncExternalProps()}firstUpdated(){this._syncExternalProps()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("click",this._handleDocumentClick),this._searchTimer&&(window.clearTimeout(this._searchTimer),this._searchTimer=null)}willUpdate(e){e.has("is-edit")&&this["is-edit"]&&this._syncProps(),!this["is-edit"]&&(e.has("title")||e.has("answer-list")||e.has("analysis")||e.has("least-answer-count")||e.has("answer-check-type")||e.has("tag-list")||e.has("category-id")||e.has("rich-text-content"))&&this._syncExternalProps(),e.has("is-key")&&(this._isKey=this["is-key"]),e.has("tag-list")&&(this._selectedTagList=Array.isArray(this["tag-list"])?this["tag-list"].map(e=>({...e})):[]),e.has("category-id")&&(this._categoryId=this["category-id"]?String(this["category-id"]):""),(e.has("exam-expand")||e.has("answer-list"))&&this._syncExamExpand(),e.has("model-value")&&this["use-model"]&&(this._title=this["model-value"])}_supportsLeastAnswerCount(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.type;return"multiple"===e||"sort"===e}_normalizeLeastAnswerCount(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.type;if(!this._supportsLeastAnswerCount(t)||""===e||null==e)return null;const s=Number(e);return Number.isFinite(s)&&s>0?s:null}_leastAnswerCountSuffix(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.type;return this._supportsLeastAnswerCount(t)&&null!==e?`,至少选${e}项${"sort"===t?"并排序":""}`:""}_normalizeAnswerItem(e){const t={...e,title:y(e?.title??e?.answer??""),isCorrect:!!e?.isCorrect},s=e?.answerId??e?.examAnswerId;return void 0!==s&&(t.answerId=s),t}_syncExternalProps(){this._title=this.title||"",this._analysis=this.analysis||"",this._leastAnswerCount=this._normalizeLeastAnswerCount(this["least-answer-count"]),this._answerCheckType=this["answer-check-type"]||1,this._isKey=this["is-key"],this._selectedTagList=Array.isArray(this["tag-list"])?this["tag-list"].map(e=>({...e})):[],this._categoryId=this["category-id"]?String(this["category-id"]):"",this._richText=this["rich-text-content"]||"",this._showRichText=!!this["rich-text-content"],this["answer-list"]?.length&&(this._answers=this["answer-list"].map(e=>this._normalizeAnswerItem(e)))}_syncProps(){this._title=this.title||"",this._analysis=this.analysis||"",this._leastAnswerCount=this._normalizeLeastAnswerCount(this["least-answer-count"]),this._answerCheckType=this["answer-check-type"]||1,this._isKey=this["is-key"],this._selectedTagList=Array.isArray(this["tag-list"])?this["tag-list"].map(e=>({...e})):[],this._categoryId=this["category-id"]?String(this["category-id"]):"",this._richText=this["rich-text-content"]||"",this._showRichText=!!this["rich-text-content"],this["answer-list"]?.length&&(this._answers=this["answer-list"].map(e=>this._normalizeAnswerItem(e))),this._syncExamExpand()}_syncExamExpand(){if(!this["exam-expand"]||!this["answer-list"]?.length)return;const e=this["exam-expand"].split(","),t=this["answer-list"];this._orderList=e.map(e=>{const s=t.findIndex((t,s)=>String(t.answerId??t.orderIndex??s+1)===String(e));return s>=0?this._label(s):""}).filter(Boolean)}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t??null}))}_searchAnswerType(){return"single"===this.type?0:"multiple"===this.type?1:5}_queueSearch(e){this._searchTimer&&(window.clearTimeout(this._searchTimer),this._searchTimer=null);const t=e.trim();if(!t||!this["search-api"]&&"function"!=typeof this["search-handler"])return this._searchResults=[],this._searchOpen=!1,void(this._searchLoading=!1);this._searchTimer=window.setTimeout(()=>{this._runSearch(t)},300)}async _runSearch(e){const t=++this._searchToken;this._searchLoading=!0,this._searchOpen=!0,this.requestUpdate();try{let s=[];if("function"==typeof this["search-handler"])s=await this["search-handler"](e,this._searchAnswerType());else if(this["search-api"]){const t=new URLSearchParams({searchKey:e,answerType:String(this._searchAnswerType())}),i=await fetch(`${this["search-api"]}${this["search-api"].includes("?")?"&":"?"}${t.toString()}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);const r=await i.json();s=(Array.isArray(r)?r:Array.isArray(r?.data)?r.data:[]).map(e=>({...e,value:e?.value||e?.title||""}))}if(t!==this._searchToken)return;this._searchResults=Array.isArray(s)?s:[]}catch(e){if(t!==this._searchToken)return;this._searchResults=[],v(e?.message||"题库搜索失败")}finally{t===this._searchToken&&(this._searchLoading=!1,this.requestUpdate())}}_selectSearchResult(e){const t=e.value||e.title||"";this._title=t,this._searchResults=[],this._searchOpen=!1,this["use-model"]&&this.dispatchEvent(new CustomEvent("update:modelValue",{bubbles:!0,composed:!0,detail:this._title})),this._emit("title-select",{...e,id:e.id??e.examId??e.questionId,title:e.title||t,value:t,customId:this["custom-id"]||""})}_applyAiAnswer(){if(!this["ai-answer"]?.trim())return void v("暂无 AI 推荐答案");const e=this["ai-answer"].split(/\r?\n/).map(e=>x(e)).filter(Boolean);let t=0;if("single"===this.type){let s=!1;this._answers=this._answers.map(i=>{const r=!s&&e.includes(x(i.title||""));return r&&(s=!0,t++),{...i,isCorrect:r}})}else this._answers=this._answers.map(s=>{const i=e.includes(x(s.title||""));return i&&t++,{...s,isCorrect:i}});t?this.requestUpdate():v("未找到匹配的选项,请检查选项内容是否一致")}_onCategoryChange(e){this._categoryId=e,this._emit("category-change",{value:e,customId:this["custom-id"]||"",examId:this["exam-id"]||0})}_setRelation(e,t){const s=e.customAnswerId?{...e}:{...e,customAnswerId:e.answerId||a()};this._answers=this._answers.map((e,i)=>i===t?s:e),this.requestUpdate(),this._emit("set-relation",{customId:this["custom-id"]||"",examId:this["exam-id"]||0,answerIndex:t,answer:s})}_relationLength(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).reduce((e,t)=>e+(Array.isArray(t?.relationAnswers)?t.relationAnswers.length:0),0)}_emitEditResultItem(e,t){this._emit("edit-result-item",{customId:this["custom-id"]||"",examId:this["exam-id"]||0,answerIndex:t,answer:{...e},resultItem:e.resultItem||""})}_resultSlotName(e){return`business-result-item-${e}`}_imageResources(){return(this["resource-list"]||[]).filter(e=>1===e.resourceType).map(e=>e.resource.middle||e.resource.url).filter(Boolean)}_videoResource(){return(this["resource-list"]||[]).find(e=>2===e.resourceType)?.resource||null}_openImageViewer(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this._imageResources().length&&(this._imageViewerIndex=e,this._imageViewerOpen=!0)}_closeImageViewer(){this._imageViewerOpen=!1}_moveImage(e){const t=this._imageResources();t.length&&(this._imageViewerIndex=(this._imageViewerIndex+e+t.length)%t.length)}_openVideoViewer(){this._videoResource()?.url&&(this._videoViewerOpen=!0)}_closeVideoViewer(){this._videoViewerOpen=!1}_label(e){return String.fromCharCode(65+e)}get _titlePlaceholder(){return"single"===this.type?"单选题":"multiple"===this.type?"多选题":"排序题"}_setCorrect(e,t){this.lockAnswerKey||(e.isCorrect=t,this.requestUpdate())}_onTitleInput(e){const t=e.target;t.value.length>this.TITLE_MAX&&(t.value=t.value.slice(0,this.TITLE_MAX)),this._title=t.value,this._queueSearch(this._title),this["use-model"]&&this.dispatchEvent(new CustomEvent("update:modelValue",{bubbles:!0,composed:!0,detail:this._title}))}_onAnswerInput(e,t){const s=e.target;s.value.length>this.ANSWER_MAX&&(s.value=s.value.slice(0,this.ANSWER_MAX)),this._answers[t].title=s.value,this.requestUpdate()}_addAnswer(e){const t=[...this._answers];t.splice(e+1,0,{title:"",isCorrect:!1,customAnswerId:a()}),this._answers=t}_deleteAnswer(e){this._answers.length<3||(this._answers=this._answers.filter((t,s)=>s!==e))}_toggleSortItem(e){const t=this._orderList.indexOf(e);this._orderList=t>=0?this._orderList.filter(t=>t!==e):[...this._orderList,e],this.requestUpdate()}_removeSortItem(e){this._orderList=this._orderList.filter(t=>t!==e),this.requestUpdate()}_getSortOrder(e){const t=this._orderList.indexOf(this._label(e));return t>=0?t+1:null}_sortAnswerValue(e){const t=e.charCodeAt(0)-65,s=this._answers[t];return s?.answerId??t+1}_rowMeta(){return{customId:this["custom-id"]||void 0,answerType:this.type,orderIndex:this["order-index"]}}_collectSnapshot(){const e=(this["is-edit"]?this._answers:this["answer-list"]||[]).map(e=>({...e,title:y(e?.title??e?.answer??""),isCorrect:!!e?.isCorrect,resultItem:y(e?.resultItem??"")})),t=this["is-edit"]?[...this._orderList]:(()=>{const e=this["exam-expand"];return e?e.split(",").map(e=>{const t=this["answer-list"]?.findIndex((t,s)=>String(t.answerId??t.orderIndex??s+1)===String(e));return t>=0?this._label(t):""}).filter(Boolean):[]})();return{title:y(this["is-edit"]?this._title:this.title||""),answers:e,analysis:y(this["is-edit"]?this._analysis:this.analysis||""),leastAnswerCount:this["is-edit"]?this._leastAnswerCount:this._normalizeLeastAnswerCount(this["least-answer-count"]),selectedTagList:Array.isArray(this._selectedTagList)?[...this._selectedTagList]:[],examExpand:this["is-edit"]?t.map(e=>this._sortAnswerValue(e)).join(","):this["exam-expand"]||"",showRichText:this["is-edit"]?this._showRichText:!!this["rich-text-content"],richText:this["is-edit"]?this._richText:this["rich-text-content"]||"",orderList:t}}_validateSnapshot(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.type;const s=this._rowMeta(),i=[];e.title||i.push(new u("题目标题不能为空!","EMPTY_TITLE","title",s));let r=!1,o=0;e.answers.forEach((e,a)=>{e.title?.trim()||i.push(new u(`选项${String.fromCharCode(65+a)}未填写`,"ANSWER_EMPTY","answers",s)),"sort"!==t&&e.isCorrect&&(r=!0,o++)});return new Set(e.answers.map(e=>e.title)).size!==e.answers.length&&e.answers.length>0&&i.push(new u("选项不能重复","DUPLICATE_ANSWERS","answers",s)),"single"===t&&o>1&&i.push(new u("此题为单选题,设置了多个推荐/正确选项,请保存时确认是否切换为多选题","SINGLE_MULTI_CORRECT","answers",s)),"multiple"===t&&(1===o&&i.push(new u("请设置至少两个推荐/正确选项","CORRECT_COUNT_INVALID","answers",s)),o>0&&(r=!0),r&&null!==e.leastAnswerCount&&o<e.leastAnswerCount&&i.push(new u("至少选几项与推荐/正确选项数不符","LEAST_ANSWER_COUNT_INVALID","answers",s))),"sort"===t&&(r=e.orderList.length>0,null!==e.leastAnswerCount&&e.orderList.length<e.leastAnswerCount&&i.push(new u("至少选几项与推荐/正确选项数不符","LEAST_ANSWER_COUNT_INVALID","orderList",s))),{errors:i,isSetCorrectAnswer:r,correctAnswerCount:o}}_serialize(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.type;const t=this._collectSnapshot(),{errors:s,isSetCorrectAnswer:i}=this._validateSnapshot(t,e);if(s.length)throw s[0];const r={answerType:String(e),examTypeEnum:String(e),title:t.title,answers:t.answers.map((e,t)=>{const s=e.resultItem?1:Array.isArray(e.answerRelations)&&e.answerRelations.length?2:null,i={...e,orderIndex:t+1,answer:e.title,relationType:s};return void 0!==e.answerId&&(i.examAnswerId=e.answerId),null===s&&delete i.relationType,i}),examExpand:t.examExpand,analysis:t.analysis,isSetCorrectAnswer:i,examRichTextContent:t.showRichText?t.richText:""};return this["exam-answer-relation-type"]&&(r.examAnswerRelationType=this["exam-answer-relation-type"]),this._supportsLeastAnswerCount(e)&&(r.leastAnswerCount=t.leastAnswerCount),this["custom-id"]&&(r.customId=this["custom-id"]),r}_shouldShowCorrectHint(){return"sort"===this.type?!this._orderList.length:!this._answers.some(e=>!!e.isCorrect)}async _finalizeSave(){try{const e=await this.toJSON();this._emit("save",e)}catch(e){v(e.message)}}async toJSON(){return Promise.resolve(this._serialize())}validate(){return this._validateSnapshot(this._collectSnapshot()).errors}setResultItem(e,t){e<0||e>=this._answers.length||(this._answers=this._answers.map((s,i)=>i===e?{...s,resultItem:t||""}:s),this.requestUpdate())}setAnswerRelation(e,t){e&&(this._answers=this._answers.map(s=>String(s.customAnswerId??s.answerId??"")===String(e)?{...s,answerRelations:t}:s),this.requestUpdate())}_renderCorrectHintDialog(){return this._correctHintDialogOpen?e`
1
+ import{html as e,css as t,LitElement as s}from"lit";import{property as i,state as r}from"lit/decorators.js";import{safeCustomElement as o}from"../base/define.mjs";import{uid as a}from"../base/uid.mjs";import{sortingCardStyles as n,renderSortingCard as l}from"./sorting-card.mjs";import{SubjectTypeLabel as c}from"./types.mjs";var h=Object.defineProperty,d=Object.getOwnPropertyDescriptor,p=(e,t,s,i)=>{for(var r,o=i>1?void 0:i?d(t,s):t,a=e.length-1;a>=0;a--)(r=e[a])&&(o=(i?r(t,s,o):r(o))||o);return i&&o&&h(t,s,o),o};class u extends Error{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"VALIDATION_ERROR",s=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0;super(e),this.code=t,this.field=s,this.row=i,this.name="SubjectError"}static from(e){return new u(e.message,e.code,e.field,e.row)}}const m=e`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>`,g=e`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>`,w=e`<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>`;function x(e){return e.replace(/^\d+\.\s*/,"").replace(/[\s,,。.!!??;;::、'"“”‘’()()[\]【】\-_/\\]+/g,"").toLowerCase()}function y(e){return String(e??"").trim()}function _(e){return String(e??"").split(",").map(e=>e.trim()).filter(Boolean).join(",")}function v(e){const t=document.createElement("div");t.textContent=e,Object.assign(t.style,{position:"fixed",top:"20px",left:"50%",transform:"translateX(-50%)",padding:"10px 20px",borderRadius:"4px",fontSize:"13px",color:"#fff",background:"#f56c6c",zIndex:"99999",boxShadow:"0 4px 12px rgba(0,0,0,.15)",transition:"opacity .3s",opacity:"1"}),document.body.appendChild(t),setTimeout(()=>{t.style.opacity="0",setTimeout(()=>t.remove(),300)},2500)}let f=class extends s{constructor(){super(...arguments),this["order-index"]=0,this["is-edit"]=!1,this["is-save"]=!1,this["is-set"]=!1,this["is-set-correct-answer"]=!1,this.lockAnswerKey=!1,this["is-key"]=!1,this["show-action"]=!0,this["show-add"]=!0,this["hide-add-rich-text"]=!1,this["show-rich-text"]=!1,this["show-delete-action"]=!0,this["show-save-action"]=!0,this.sorting=!1,this["show-answer-setting"]=!1,this["show-key"]=!1,this["show-analysis"]=!1,this.type="single",this["answer-check-type"]=1,this["exam-answer-relation-type"]=0,this["rich-text-content"]="",this.analysis="",this["least-answer-count"]=null,this["exam-expand"]="",this["custom-id"]="",this["exam-id"]=0,this["category-id"]="",this["upload-image"]=async e=>new Promise((t,s)=>{const i=new FileReader;i.onload=e=>t(e.target?.result),i.onerror=s,i.readAsDataURL(e)}),this["tag-list"]=[],this["category-list"]=[],this["ai-answer"]="",this["resource-list"]=[],this["show-tag"]=!1,this["show-category"]=!1,this["show-ai"]=!1,this["show-resource"]=!1,this["show-jump"]=!1,this["has-jump"]=!1,this["search-api"]="",this["model-value"]="",this["use-model"]=!1,this._answers=[{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1}],this.title="",this._title="",this._analysis="",this._richText="",this._showRichText=!1,this._leastAnswerCount=null,this._answerCheckType=1,this._isKey=!1,this._orderList=[],this._selectedTagList=[],this._categoryId="",this._searchResults=[],this._searchOpen=!1,this._searchLoading=!1,this._sortDropdownOpen=!1,this._imageViewerOpen=!1,this._imageViewerIndex=0,this._videoViewerOpen=!1,this._correctHintDialogOpen=!1,this._hasShownCorrectHint=!1,this._changeTypeDialogOpen=!1,this._searchTimer=null,this._searchToken=0,this.TITLE_MAX=200,this.ANSWER_MAX=100,this._handleDocumentClick=e=>{const t=e.composedPath(),s=this.shadowRoot?.querySelector(".multi-select-wrapper"),i=this.shadowRoot?.querySelector(".search-wrap");s&&!t.includes(s)&&(this._sortDropdownOpen=!1),i&&!t.includes(i)&&(this._searchOpen=!1),this.requestUpdate()}}get"answer-list"(){return this._answers}set"answer-list"(e){if(this["is-edit"])return;const t=Array.isArray(e)?e:[];this._answers=t.length?t.map(e=>this._normalizeAnswerItem(e)):[{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1},{title:"",isCorrect:!1}],this.requestUpdate("answer-list")}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this._handleDocumentClick),this._syncExternalProps()}firstUpdated(){this._syncExternalProps()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("click",this._handleDocumentClick),this._searchTimer&&(window.clearTimeout(this._searchTimer),this._searchTimer=null)}willUpdate(e){e.has("is-edit")&&this["is-edit"]&&this._syncProps(),!this["is-edit"]&&(e.has("title")||e.has("answer-list")||e.has("analysis")||e.has("least-answer-count")||e.has("answer-check-type")||e.has("tag-list")||e.has("category-id")||e.has("rich-text-content"))&&this._syncExternalProps(),e.has("is-key")&&(this._isKey=this["is-key"]),e.has("tag-list")&&(this._selectedTagList=Array.isArray(this["tag-list"])?this["tag-list"].map(e=>({...e})):[]),e.has("category-id")&&(this._categoryId=this["category-id"]?String(this["category-id"]):""),(e.has("exam-expand")||e.has("answer-list"))&&this._syncExamExpand(),e.has("model-value")&&this["use-model"]&&(this._title=this["model-value"])}_supportsLeastAnswerCount(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.type;return"multiple"===e||"sort"===e}_normalizeLeastAnswerCount(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.type;if(!this._supportsLeastAnswerCount(t)||""===e||null==e)return null;const s=Number(e);return Number.isFinite(s)&&s>0?s:null}_leastAnswerCountSuffix(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.type;return this._supportsLeastAnswerCount(t)&&null!==e?`,至少选${e}项${"sort"===t?"并排序":""}`:""}_normalizeAnswerItem(e){const t={...e,title:y(e?.title??e?.answer??""),isCorrect:!!e?.isCorrect},s=e?.answerId??e?.examAnswerId;return void 0!==s&&(t.answerId=s),t}_syncExternalProps(){this._title=this.title||"",this._analysis=this.analysis||"",this._leastAnswerCount=this._normalizeLeastAnswerCount(this["least-answer-count"]),this._answerCheckType=this["answer-check-type"]||1,this._isKey=this["is-key"],this._selectedTagList=Array.isArray(this["tag-list"])?this["tag-list"].map(e=>({...e})):[],this._categoryId=this["category-id"]?String(this["category-id"]):"",this._richText=this["rich-text-content"]||"",this._showRichText=!!this["rich-text-content"],this["answer-list"]?.length&&(this._answers=this["answer-list"].map(e=>this._normalizeAnswerItem(e)))}_syncProps(){this._title=this.title||"",this._analysis=this.analysis||"",this._leastAnswerCount=this._normalizeLeastAnswerCount(this["least-answer-count"]),this._answerCheckType=this["answer-check-type"]||1,this._isKey=this["is-key"],this._selectedTagList=Array.isArray(this["tag-list"])?this["tag-list"].map(e=>({...e})):[],this._categoryId=this["category-id"]?String(this["category-id"]):"",this._richText=this["rich-text-content"]||"",this._showRichText=!!this["rich-text-content"],this["answer-list"]?.length&&(this._answers=this["answer-list"].map(e=>this._normalizeAnswerItem(e))),this._syncExamExpand()}_syncExamExpand(){if(!this["exam-expand"]||!this["answer-list"]?.length)return;const e=this["exam-expand"].split(","),t=this["answer-list"];this._orderList=e.map(e=>{const s=t.findIndex((t,s)=>String(t.answerId??t.orderIndex??s+1)===String(e));return s>=0?this._label(s):""}).filter(Boolean)}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t??null}))}_searchAnswerType(){return"single"===this.type?0:"multiple"===this.type?1:5}_queueSearch(e){this._searchTimer&&(window.clearTimeout(this._searchTimer),this._searchTimer=null);const t=e.trim();if(!t||!this["search-api"]&&"function"!=typeof this["search-handler"])return this._searchResults=[],this._searchOpen=!1,void(this._searchLoading=!1);this._searchTimer=window.setTimeout(()=>{this._runSearch(t)},300)}async _runSearch(e){const t=++this._searchToken;this._searchLoading=!0,this._searchOpen=!0,this.requestUpdate();try{let s=[];if("function"==typeof this["search-handler"])s=await this["search-handler"](e,this._searchAnswerType());else if(this["search-api"]){const t=new URLSearchParams({searchKey:e,answerType:String(this._searchAnswerType())}),i=await fetch(`${this["search-api"]}${this["search-api"].includes("?")?"&":"?"}${t.toString()}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);const r=await i.json();s=(Array.isArray(r)?r:Array.isArray(r?.data)?r.data:[]).map(e=>({...e,value:e?.value||e?.title||""}))}if(t!==this._searchToken)return;this._searchResults=Array.isArray(s)?s:[]}catch(e){if(t!==this._searchToken)return;this._searchResults=[],v(e?.message||"题库搜索失败")}finally{t===this._searchToken&&(this._searchLoading=!1,this.requestUpdate())}}_selectSearchResult(e){const t=e.value||e.title||"";this._title=t,this._searchResults=[],this._searchOpen=!1,this["use-model"]&&this.dispatchEvent(new CustomEvent("update:modelValue",{bubbles:!0,composed:!0,detail:this._title})),this._emit("title-select",{...e,id:e.id??e.examId??e.questionId,title:e.title||t,value:t,customId:this["custom-id"]||""})}_applyAiAnswer(){if(!this["ai-answer"]?.trim())return void v("暂无 AI 推荐答案");const e=this["ai-answer"].split(/\r?\n/).map(e=>x(e)).filter(Boolean);let t=0;if("single"===this.type){let s=!1;this._answers=this._answers.map(i=>{const r=!s&&e.includes(x(i.title||""));return r&&(s=!0,t++),{...i,isCorrect:r}})}else this._answers=this._answers.map(s=>{const i=e.includes(x(s.title||""));return i&&t++,{...s,isCorrect:i}});t?this.requestUpdate():v("未找到匹配的选项,请检查选项内容是否一致")}_onCategoryChange(e){this._categoryId=e,this._emit("category-change",{value:e,customId:this["custom-id"]||"",examId:this["exam-id"]||0})}_setRelation(e,t){const s=e.customAnswerId?{...e}:{...e,customAnswerId:e.answerId||a()};this._answers=this._answers.map((e,i)=>i===t?s:e),this.requestUpdate(),this._emit("set-relation",{customId:this["custom-id"]||"",examId:this["exam-id"]||0,answerIndex:t,answer:s})}_relationLength(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).reduce((e,t)=>e+(Array.isArray(t?.relationAnswers)?t.relationAnswers.length:0),0)}_emitEditResultItem(e,t){this._emit("edit-result-item",{customId:this["custom-id"]||"",examId:this["exam-id"]||0,answerIndex:t,answer:{...e},resultItem:e.resultItem||""})}_resultSlotName(e){return`business-result-item-${e}`}_imageResources(){return(this["resource-list"]||[]).filter(e=>1===e.resourceType).map(e=>e.resource.middle||e.resource.url).filter(Boolean)}_videoResource(){return(this["resource-list"]||[]).find(e=>2===e.resourceType)?.resource||null}_openImageViewer(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this._imageResources().length&&(this._imageViewerIndex=e,this._imageViewerOpen=!0)}_closeImageViewer(){this._imageViewerOpen=!1}_moveImage(e){const t=this._imageResources();t.length&&(this._imageViewerIndex=(this._imageViewerIndex+e+t.length)%t.length)}_openVideoViewer(){this._videoResource()?.url&&(this._videoViewerOpen=!0)}_closeVideoViewer(){this._videoViewerOpen=!1}_label(e){return String.fromCharCode(65+e)}get _titlePlaceholder(){return"single"===this.type?"单选题":"multiple"===this.type?"多选题":"排序题"}_setCorrect(e,t){this.lockAnswerKey||(e.isCorrect=t,this.requestUpdate())}_onTitleInput(e){const t=e.target;t.value.length>this.TITLE_MAX&&(t.value=t.value.slice(0,this.TITLE_MAX)),this._title=t.value,this._queueSearch(this._title),this["use-model"]&&this.dispatchEvent(new CustomEvent("update:modelValue",{bubbles:!0,composed:!0,detail:this._title}))}_onAnswerInput(e,t){const s=e.target;s.value.length>this.ANSWER_MAX&&(s.value=s.value.slice(0,this.ANSWER_MAX)),this._answers[t].title=s.value,this.requestUpdate()}_addAnswer(e){const t=[...this._answers];t.splice(e+1,0,{title:"",isCorrect:!1,customAnswerId:a()}),this._answers=t}_deleteAnswer(e){this._answers.length<3||(this._answers=this._answers.filter((t,s)=>s!==e))}_toggleSortItem(e){const t=this._orderList.indexOf(e);this._orderList=t>=0?this._orderList.filter(t=>t!==e):[...this._orderList,e],this.requestUpdate()}_removeSortItem(e){this._orderList=this._orderList.filter(t=>t!==e),this.requestUpdate()}_getSortOrder(e){const t=this._orderList.indexOf(this._label(e));return t>=0?t+1:null}_sortAnswerValue(e){const t=e.charCodeAt(0)-65,s=this._answers[t];return s?.answerId??t+1}_rowMeta(){return{customId:this["custom-id"]||void 0,answerType:this.type,orderIndex:this["order-index"]}}_collectSnapshot(){const e=(this["is-edit"]?this._answers:this["answer-list"]||[]).map(e=>({...e,title:y(e?.title??e?.answer??""),isCorrect:!!e?.isCorrect,resultItem:y(e?.resultItem??"")})),t=this["is-edit"]?[...this._orderList]:(()=>{const e=this["exam-expand"];return e?e.split(",").map(e=>{const t=this["answer-list"]?.findIndex((t,s)=>String(t.answerId??t.orderIndex??s+1)===String(e));return t>=0?this._label(t):""}).filter(Boolean):[]})();return{title:y(this["is-edit"]?this._title:this.title||""),answers:e,analysis:y(this["is-edit"]?this._analysis:this.analysis||""),leastAnswerCount:this["is-edit"]?this._leastAnswerCount:this._normalizeLeastAnswerCount(this["least-answer-count"]),selectedTagList:Array.isArray(this._selectedTagList)?[...this._selectedTagList]:[],examExpand:this["is-edit"]?t.map(e=>this._sortAnswerValue(e)).join(","):this["exam-expand"]||"",showRichText:this["is-edit"]?this._showRichText:!!this["rich-text-content"],richText:this["is-edit"]?this._richText:this["rich-text-content"]||"",orderList:t}}_validateSnapshot(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.type;const s=this._rowMeta(),i=[];e.title||i.push(new u("题目标题不能为空!","EMPTY_TITLE","title",s));let r=!1,o=0;e.answers.forEach((e,a)=>{e.title?.trim()||i.push(new u(`选项${String.fromCharCode(65+a)}未填写`,"ANSWER_EMPTY","answers",s)),"sort"!==t&&e.isCorrect&&(r=!0,o++)});return new Set(e.answers.map(e=>e.title)).size!==e.answers.length&&e.answers.length>0&&i.push(new u("选项不能重复","DUPLICATE_ANSWERS","answers",s)),"single"===t&&o>1&&i.push(new u("此题为单选题,设置了多个推荐/正确选项,请保存时确认是否切换为多选题","SINGLE_MULTI_CORRECT","answers",s)),"multiple"===t&&(1===o&&i.push(new u("请设置至少两个推荐/正确选项","CORRECT_COUNT_INVALID","answers",s)),o>0&&(r=!0),r&&null!==e.leastAnswerCount&&o<e.leastAnswerCount&&i.push(new u("至少选几项与推荐/正确选项数不符","LEAST_ANSWER_COUNT_INVALID","answers",s))),"sort"===t&&(r=e.orderList.length>0,null!==e.leastAnswerCount&&e.orderList.length<e.leastAnswerCount&&i.push(new u("至少选几项与推荐/正确选项数不符","LEAST_ANSWER_COUNT_INVALID","orderList",s))),{errors:i,isSetCorrectAnswer:r,correctAnswerCount:o}}_serialize(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.type;const t=this._collectSnapshot(),{errors:s,isSetCorrectAnswer:i}=this._validateSnapshot(t,e);if(s.length)throw s[0];const r={answerType:String(e),examTypeEnum:String(e),title:t.title,answers:t.answers.map((e,t)=>{const s=e.resultItem?1:Array.isArray(e.answerRelations)&&e.answerRelations.length?2:null,i={...e,orderIndex:t+1,answer:e.title,relationType:s};return void 0!==e.answerId&&(i.examAnswerId=e.answerId),null===s&&delete i.relationType,i}),examExpand:t.examExpand,analysis:t.analysis,isSetCorrectAnswer:i,examRichTextContent:t.showRichText?t.richText:""};return this["exam-answer-relation-type"]&&(r.examAnswerRelationType=this["exam-answer-relation-type"]),this._supportsLeastAnswerCount(e)&&(r.leastAnswerCount=t.leastAnswerCount),this["custom-id"]&&(r.customId=this["custom-id"]),r}_shouldShowCorrectHint(){return"sort"===this.type?!this._orderList.length:!this._answers.some(e=>!!e.isCorrect)}async _finalizeSave(){try{const e=await this.toJSON();this._emit("save",e)}catch(e){v(e.message)}}async toJSON(){return Promise.resolve(this._serialize())}validate(){return this._validateSnapshot(this._collectSnapshot()).errors}setResultItem(e,t){e<0||e>=this._answers.length||(this._answers=this._answers.map((s,i)=>i===e?{...s,resultItem:t||""}:s),this.requestUpdate())}setAnswerRelation(e,t){e&&(this._answers=this._answers.map(s=>String(s.customAnswerId??s.answerId??"")===String(e)?{...s,answerRelations:t}:s),this.requestUpdate())}_renderCorrectHintDialog(){return this._correctHintDialogOpen?e`
2
2
  <div class="modal-backdrop" @click=${()=>{this._correctHintDialogOpen=!1}}>
3
3
  <div class="modal correct-hint-dialog" @click=${e=>e.stopPropagation()}>
4
4
  <div class="modal-header">
@@ -123,7 +123,7 @@ import{html as e,css as t,LitElement as s}from"lit";import{property as i,state a
123
123
  `:""}async _save(e){e?.stopImmediatePropagation();const t=this.validate(),s=t.find(e=>"SINGLE_MULTI_CORRECT"===e.code),i=t.filter(e=>"SINGLE_MULTI_CORRECT"!==e.code);i.length?v(i[0].message):s?this._changeTypeDialogOpen=!0:this._hasShownCorrectHint||!this._shouldShowCorrectHint()?await this._finalizeSave():this._correctHintDialogOpen=!0}_renderPreview(){const t="single"===this.type?"(单选题)":`(${this._titlePlaceholder}${this._leastAnswerCountSuffix(this._normalizeLeastAnswerCount(this["least-answer-count"]))})`,s=this["answer-list"];return e`
124
124
  <div class="preview">
125
125
  <div><span class="title">${this["order-index"]+1}.${this.title||""}${t}</span></div>
126
- ${this["rich-text-content"]?e`<div class="rich-text" .innerHTML=${this["rich-text-content"]}></div>`:""}
126
+ ${this["show-rich-text"]&&this["rich-text-content"]?e`<div class="rich-text" .innerHTML=${this["rich-text-content"]}></div>`:""}
127
127
  <div class="preview-answer">
128
128
  ${s.map((t,s)=>e`
129
129
  <label class="radio">
@@ -253,7 +253,7 @@ import{html as e,css as t,LitElement as s}from"lit";import{property as i,state a
253
253
 
254
254
  ${this._renderResourceSection()}
255
255
 
256
- ${this._showRichText?e`
256
+ ${this["show-rich-text"]&&this._showRichText?e`
257
257
  <div class="flex-items-start" style="margin-top:12px">
258
258
  <div class="label"><span>副文本:</span></div>
259
259
  <div style="flex:1">
@@ -288,7 +288,10 @@ import{html as e,css as t,LitElement as s}from"lit";import{property as i,state a
288
288
  .is-edit=${this["is-edit"]}
289
289
  .is-set=${this["is-set"]}
290
290
  .show-add=${this["show-add"]}
291
- .show-rich-text=${this._showRichText}
291
+ .show-rich-text=${this["show-rich-text"]&&this._showRichText}
292
+ .hide-add-rich-text=${!this["show-rich-text"]||this["hide-add-rich-text"]}
293
+ .show-delete-action=${this["show-delete-action"]}
294
+ .show-save-action=${this["show-save-action"]}
292
295
  .show-jump=${this["show-jump"]}
293
296
  @delete=${()=>this._emit("delete")}
294
297
  @save=${this._save}
@@ -299,6 +302,7 @@ import{html as e,css as t,LitElement as s}from"lit";import{property as i,state a
299
302
  @on-show-rich-text=${()=>{this._showRichText=!this._showRichText,this._showRichText||(this._richText="")}}
300
303
  ></qxs-subject-action>
301
304
  `:""}
305
+ <slot name="action"></slot>
302
306
  </qxs-subject-layout>
303
307
  ${this._renderCorrectHintDialog()}
304
308
  ${this._renderChangeTypeDialog()}
@@ -523,5 +527,5 @@ import{html as e,css as t,LitElement as s}from"lit";import{property as i,state a
523
527
  font-size: 14px;
524
528
  border-radius: 4px;
525
529
  }
526
- `],p([i({type:Number,attribute:"order-index"})],f.prototype,"order-index",2),p([i({type:Boolean,attribute:"is-edit"})],f.prototype,"is-edit",2),p([i({type:Boolean,attribute:"is-save"})],f.prototype,"is-save",2),p([i({type:Boolean,attribute:"is-set"})],f.prototype,"is-set",2),p([i({type:Boolean,attribute:"is-set-correct-answer"})],f.prototype,"is-set-correct-answer",2),p([i({type:Boolean,attribute:"lock-answer-key"})],f.prototype,"lockAnswerKey",2),p([i({type:Boolean,attribute:"is-key"})],f.prototype,"is-key",2),p([i({type:Boolean,attribute:"show-action"})],f.prototype,"show-action",2),p([i({type:Boolean,attribute:"show-add"})],f.prototype,"show-add",2),p([i({type:Boolean,reflect:!0})],f.prototype,"sorting",2),p([i({type:Boolean,attribute:"show-answer-setting"})],f.prototype,"show-answer-setting",2),p([i({type:Boolean,attribute:"show-key"})],f.prototype,"show-key",2),p([i({type:Boolean,attribute:"show-analysis"})],f.prototype,"show-analysis",2),p([i({attribute:"question-type",reflect:!0})],f.prototype,"type",2),p([i({type:Number,attribute:"answer-check-type"})],f.prototype,"answer-check-type",2),p([i({type:Number,attribute:"exam-answer-relation-type"})],f.prototype,"exam-answer-relation-type",2),p([i({type:String,attribute:"rich-text-content"})],f.prototype,"rich-text-content",2),p([i({type:String})],f.prototype,"analysis",2),p([i({type:Number,attribute:"least-answer-count"})],f.prototype,"least-answer-count",2),p([i({type:String,attribute:"exam-expand"})],f.prototype,"exam-expand",2),p([i({type:String,attribute:"custom-id"})],f.prototype,"custom-id",2),p([i({type:Number,attribute:"exam-id"})],f.prototype,"exam-id",2),p([i({type:String,attribute:"category-id"})],f.prototype,"category-id",2),p([i({type:Object,attribute:"upload-image"})],f.prototype,"upload-image",2),p([i({type:Array,attribute:"answer-list"})],f.prototype,"answer-list",1),p([i({type:Array,attribute:"tag-list"})],f.prototype,"tag-list",2),p([i({type:Array,attribute:"category-list"})],f.prototype,"category-list",2),p([i({type:String,attribute:"ai-answer"})],f.prototype,"ai-answer",2),p([i({type:Array,attribute:"resource-list"})],f.prototype,"resource-list",2),p([i({type:Boolean,attribute:"show-tag"})],f.prototype,"show-tag",2),p([i({type:Boolean,attribute:"show-category"})],f.prototype,"show-category",2),p([i({type:Boolean,attribute:"show-ai"})],f.prototype,"show-ai",2),p([i({type:Boolean,attribute:"show-resource"})],f.prototype,"show-resource",2),p([i({type:Boolean,attribute:"show-jump"})],f.prototype,"show-jump",2),p([i({type:Boolean,attribute:"has-jump"})],f.prototype,"has-jump",2),p([i({type:String,attribute:"search-api"})],f.prototype,"search-api",2),p([i({type:Object,attribute:"search-handler"})],f.prototype,"search-handler",2),p([i({type:String,attribute:"model-value"})],f.prototype,"model-value",2),p([i({type:Boolean,attribute:"use-model"})],f.prototype,"use-model",2),p([r()],f.prototype,"_answers",2),p([i({type:String})],f.prototype,"title",2),p([r()],f.prototype,"_title",2),p([r()],f.prototype,"_analysis",2),p([r()],f.prototype,"_richText",2),p([r()],f.prototype,"_showRichText",2),p([r()],f.prototype,"_leastAnswerCount",2),p([r()],f.prototype,"_answerCheckType",2),p([r()],f.prototype,"_isKey",2),p([r()],f.prototype,"_orderList",2),p([r()],f.prototype,"_selectedTagList",2),p([r()],f.prototype,"_categoryId",2),p([r()],f.prototype,"_searchResults",2),p([r()],f.prototype,"_searchOpen",2),p([r()],f.prototype,"_searchLoading",2),p([r()],f.prototype,"_sortDropdownOpen",2),p([r()],f.prototype,"_imageViewerOpen",2),p([r()],f.prototype,"_imageViewerIndex",2),p([r()],f.prototype,"_videoViewerOpen",2),p([r()],f.prototype,"_correctHintDialogOpen",2),p([r()],f.prototype,"_hasShownCorrectHint",2),p([r()],f.prototype,"_changeTypeDialogOpen",2),f=p([o("qxs-subject-single")],f);export{f as QxsSubjectSingle,u as SubjectError,_ as trimCommaSeparatedText,y as trimText};
530
+ `],p([i({type:Number,attribute:"order-index"})],f.prototype,"order-index",2),p([i({type:Boolean,attribute:"is-edit"})],f.prototype,"is-edit",2),p([i({type:Boolean,attribute:"is-save"})],f.prototype,"is-save",2),p([i({type:Boolean,attribute:"is-set"})],f.prototype,"is-set",2),p([i({type:Boolean,attribute:"is-set-correct-answer"})],f.prototype,"is-set-correct-answer",2),p([i({type:Boolean,attribute:"lock-answer-key"})],f.prototype,"lockAnswerKey",2),p([i({type:Boolean,attribute:"is-key"})],f.prototype,"is-key",2),p([i({type:Boolean,attribute:"show-action"})],f.prototype,"show-action",2),p([i({type:Boolean,attribute:"show-add"})],f.prototype,"show-add",2),p([i({type:Boolean,attribute:"hide-add-rich-text"})],f.prototype,"hide-add-rich-text",2),p([i({type:Boolean,attribute:"show-rich-text"})],f.prototype,"show-rich-text",2),p([i({type:Boolean,attribute:"show-delete-action"})],f.prototype,"show-delete-action",2),p([i({type:Boolean,attribute:"show-save-action"})],f.prototype,"show-save-action",2),p([i({type:Boolean,reflect:!0})],f.prototype,"sorting",2),p([i({type:Boolean,attribute:"show-answer-setting"})],f.prototype,"show-answer-setting",2),p([i({type:Boolean,attribute:"show-key"})],f.prototype,"show-key",2),p([i({type:Boolean,attribute:"show-analysis"})],f.prototype,"show-analysis",2),p([i({attribute:"question-type",reflect:!0})],f.prototype,"type",2),p([i({type:Number,attribute:"answer-check-type"})],f.prototype,"answer-check-type",2),p([i({type:Number,attribute:"exam-answer-relation-type"})],f.prototype,"exam-answer-relation-type",2),p([i({type:String,attribute:"rich-text-content"})],f.prototype,"rich-text-content",2),p([i({type:String})],f.prototype,"analysis",2),p([i({type:Number,attribute:"least-answer-count"})],f.prototype,"least-answer-count",2),p([i({type:String,attribute:"exam-expand"})],f.prototype,"exam-expand",2),p([i({type:String,attribute:"custom-id"})],f.prototype,"custom-id",2),p([i({type:Number,attribute:"exam-id"})],f.prototype,"exam-id",2),p([i({type:String,attribute:"category-id"})],f.prototype,"category-id",2),p([i({type:Object,attribute:"upload-image"})],f.prototype,"upload-image",2),p([i({type:Array,attribute:"answer-list"})],f.prototype,"answer-list",1),p([i({type:Array,attribute:"tag-list"})],f.prototype,"tag-list",2),p([i({type:Array,attribute:"category-list"})],f.prototype,"category-list",2),p([i({type:String,attribute:"ai-answer"})],f.prototype,"ai-answer",2),p([i({type:Array,attribute:"resource-list"})],f.prototype,"resource-list",2),p([i({type:Boolean,attribute:"show-tag"})],f.prototype,"show-tag",2),p([i({type:Boolean,attribute:"show-category"})],f.prototype,"show-category",2),p([i({type:Boolean,attribute:"show-ai"})],f.prototype,"show-ai",2),p([i({type:Boolean,attribute:"show-resource"})],f.prototype,"show-resource",2),p([i({type:Boolean,attribute:"show-jump"})],f.prototype,"show-jump",2),p([i({type:Boolean,attribute:"has-jump"})],f.prototype,"has-jump",2),p([i({type:String,attribute:"search-api"})],f.prototype,"search-api",2),p([i({type:Object,attribute:"search-handler"})],f.prototype,"search-handler",2),p([i({type:String,attribute:"model-value"})],f.prototype,"model-value",2),p([i({type:Boolean,attribute:"use-model"})],f.prototype,"use-model",2),p([r()],f.prototype,"_answers",2),p([i({type:String})],f.prototype,"title",2),p([r()],f.prototype,"_title",2),p([r()],f.prototype,"_analysis",2),p([r()],f.prototype,"_richText",2),p([r()],f.prototype,"_showRichText",2),p([r()],f.prototype,"_leastAnswerCount",2),p([r()],f.prototype,"_answerCheckType",2),p([r()],f.prototype,"_isKey",2),p([r()],f.prototype,"_orderList",2),p([r()],f.prototype,"_selectedTagList",2),p([r()],f.prototype,"_categoryId",2),p([r()],f.prototype,"_searchResults",2),p([r()],f.prototype,"_searchOpen",2),p([r()],f.prototype,"_searchLoading",2),p([r()],f.prototype,"_sortDropdownOpen",2),p([r()],f.prototype,"_imageViewerOpen",2),p([r()],f.prototype,"_imageViewerIndex",2),p([r()],f.prototype,"_videoViewerOpen",2),p([r()],f.prototype,"_correctHintDialogOpen",2),p([r()],f.prototype,"_hasShownCorrectHint",2),p([r()],f.prototype,"_changeTypeDialogOpen",2),f=p([o("qxs-subject-single")],f);export{f as QxsSubjectSingle,u as SubjectError,_ as trimCommaSeparatedText,y as trimText};
527
531
  //# sourceMappingURL=single.mjs.map