diff --git a/example/component/renderable/schema/edit/index.html b/example/component/renderable/schema/edit/index.html index 463d55f4..3286c3f2 100644 --- a/example/component/renderable/schema/edit/index.html +++ b/example/component/renderable/schema/edit/index.html @@ -42,5 +42,9 @@ "inline.object": [{ id: 1423330 }], }, }; + $bc.tryToGetSource("answer.data").then(e=>{ + console.log(e) + }) + console.log(result) diff --git a/package-lock.json b/package-lock.json index fda55e18..3620223c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,6 +23,7 @@ "ignore-loader": "^0.1.2", "lodash.clonedeep": "^4.5.0", "lodash.defaultsdeep": "^4.6.1", + "node-gzip": "^1.1.2", "reflect-metadata": "^0.1.13", "style-loader": "^3.3.1", "ts-loader": "^9.2.6", diff --git a/src/component/renderable/schema/part-control/html/HTMLFieldType.ts b/src/component/renderable/schema/part-control/html/HTMLFieldType.ts index 58048922..8219ffc6 100644 --- a/src/component/renderable/schema/part-control/html/HTMLFieldType.ts +++ b/src/component/renderable/schema/part-control/html/HTMLFieldType.ts @@ -11,8 +11,9 @@ import { IQuestionPart } from "../../IQuestionSchema"; export default class HTMLFieldType extends QuestionPart { private valueInput: HTMLInputElement; - private value: IUserActionPart; + public value: IUserActionPart | string; private modalElement: HTMLElement; + public answer; constructor(part: IQuestionPart, owner: Question, answer: IPartCollection) { super(part, layout, owner, answer); this.modalElement = Util.parse(HTMLLayout).querySelector( @@ -51,7 +52,7 @@ export default class HTMLFieldType extends QuestionPart { let data; try { data = JSON.parse(e.data); - } catch { } + } catch {} if (data) { if (Object.keys(data).find((e) => e == "isLoaded")) { if (data.isLoaded) { @@ -92,7 +93,7 @@ export default class HTMLFieldType extends QuestionPart { iframe.onload = (e) => { if (this.value) { iframe.contentWindow.postMessage( - JSON.stringify({ ...this.value, mode: "edit" }) + JSON.stringify({ ...(this.value as IUserActionPart), mode: "edit" }) ); } else { iframe.contentWindow.postMessage(JSON.stringify({ mode: "new" })); @@ -111,6 +112,8 @@ export default class HTMLFieldType extends QuestionPart { } public getAddedAsync(): Promise { let retVal = null; + + if (!this.answer) { if (this.value) { retVal = { @@ -130,6 +133,7 @@ export default class HTMLFieldType extends QuestionPart { } public getEditedAsync(): Promise { let retVal = null; + if (this.answer) { const changed = this.value != this.answer.values[0].value; if (changed) { @@ -149,7 +153,6 @@ export default class HTMLFieldType extends QuestionPart { public getDeletedAsync(): Promise { let retVal = null; - if (this.answer && Object.keys(this.value).length == 0) { const changed = this.value != this.answer.values[0].value; if (changed) { @@ -168,6 +171,6 @@ export default class HTMLFieldType extends QuestionPart { } public getValuesAsync(): Promise { - return Promise.resolve(this.value); + return Promise.resolve(this.value as IUserActionPart); } } diff --git a/src/component/renderable/schema/question-container/QuestionContainer.ts b/src/component/renderable/schema/question-container/QuestionContainer.ts index 119d0982..4b40d7c6 100644 --- a/src/component/renderable/schema/question-container/QuestionContainer.ts +++ b/src/component/renderable/schema/question-container/QuestionContainer.ts @@ -8,6 +8,7 @@ import { IAnswerProperty, IAnswerPart } from "../IAnswerSchema"; import { IQuestion } from "../IQuestionSchema"; import IQuestionCellManager from "../IQuestionCellManager"; import QuestionPart from "../question-part/QuestionPart"; +import HTMLFieldType from "../part-control/html/HTMLFieldType"; export default class QuestionContainer { public readonly QuestionSchema: IQuestion; @@ -40,7 +41,9 @@ export default class QuestionContainer { if (!questionSchema.help) { uiElement.querySelector("[data-bc-help-btn]").remove(); } else { - uiElement.querySelector("[data-bc-help-btn]").setAttribute("data-bc-help-tooltip", questionSchema.help); + uiElement + .querySelector("[data-bc-help-btn]") + .setAttribute("data-bc-help-tooltip", questionSchema.help); } const headerContainer = uiElement.querySelector( "[data-bc-answer-title-container]" @@ -123,12 +126,16 @@ export default class QuestionContainer { public onQuestionRemove(question: Question) { const index = this._questions.indexOf(question); - this._questions.splice(index, 1); - if (question.answer?.id) { - if (!this._removedQuestions) { - this._removedQuestions = []; + if (question.question.parts[0].viewType == "html") { + (question._parts[0] as HTMLFieldType).value =""; + } else { + this._questions.splice(index, 1); + if (question.answer?.id) { + if (!this._removedQuestions) { + this._removedQuestions = []; + } + this._removedQuestions.push(question.answer.id); } - this._removedQuestions.push(question.answer.id); } } diff --git a/src/component/renderable/schema/question/Question.ts b/src/component/renderable/schema/question/Question.ts index 9549b7a8..6f3aab27 100644 --- a/src/component/renderable/schema/question/Question.ts +++ b/src/component/renderable/schema/question/Question.ts @@ -21,7 +21,7 @@ export default class Question { private _addButton: HTMLButtonElement; private _pairBtnContainer: HTMLDivElement; readonly owner: QuestionContainer; - readonly answer: IAnswerPart; + answer: IAnswerPart; private readonly _ui: HTMLElement; private _onAddClick: AddRemoveCallback; private _onRemoveClick: AddRemoveCallback; @@ -49,10 +49,11 @@ export default class Question { this.button.addEventListener("click", this.onBtnClick.bind(this)); this._removeButton.addEventListener("click", (e) => { + e.preventDefault; this.owner.onQuestionRemove(this); this._ui.remove(); - this.owner.addQuestion(null); + this.owner.addQuestion(null); }); this._addButton.addEventListener("click", () => this._onAddClick()); this._onAddClick = () => { @@ -181,6 +182,9 @@ export default class Question { } : null; } + public clearAnswer(){ + this.answer =null + } } declare type AddRemoveCallback = () => void; diff --git a/src/options/connection-options/ChunkBasedConnectionOptions.ts b/src/options/connection-options/ChunkBasedConnectionOptions.ts index 62d051b8..29801be3 100644 --- a/src/options/connection-options/ChunkBasedConnectionOptions.ts +++ b/src/options/connection-options/ChunkBasedConnectionOptions.ts @@ -79,13 +79,13 @@ export default class ChunkBasedConnectionOptions extends ConnectionOptions { const { value, done: doneReading } = await reader.read(); done = doneReading; if (value) { - try { + // try { let json; let decodedStr; if (gzipMode == "perchunk") { decodedStr = pako.ungzip(value, { to: "string" }); } else { - if (this.isFinalValueCanParsed) { + if (isFinalValueCanParsed) { decodedStr = decoder .decode(value, { stream: true }) .slice(0, -1); @@ -101,7 +101,8 @@ export default class ChunkBasedConnectionOptions extends ConnectionOptions { decodedStr != ",null]" && decodedStr != "[null" ) { - throw new Error("invalid json"); + console.log("str",decodedStr); + //throw new Error("invalid json"); } } if ( @@ -131,13 +132,13 @@ export default class ChunkBasedConnectionOptions extends ConnectionOptions { } } } - } catch (ex) { - reject(ex); - context.logger.logError( - "Error in process chunk based request", - ex - ); - } + // } catch (ex) { + // reject(ex); + // context.logger.logError( + // "Error in process chunk based request", + // ex + // ); + // } } } activeFetch.delete(sourceId); diff --git a/tsconfig.json b/tsconfig.json index 4b391a94..81148bd9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "emitDecoratorMetadata": true, "strictNullChecks": false, "declaration": true, - "outDir": "src/types" + "outDir": "src/types", + "allowSyntheticDefaultImports": true } }