Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/component/renderable/schema/edit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
"inline.object": [{ id: 1423330 }],
},
};
$bc.tryToGetSource("answer.data").then(e=>{
console.log(e)
})
console.log(result)
</script>
</html>
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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" }));
Expand All @@ -111,6 +112,8 @@ export default class HTMLFieldType extends QuestionPart {
}
public getAddedAsync(): Promise<IUserActionPart> {
let retVal = null;


if (!this.answer) {
if (this.value) {
retVal = {
Expand All @@ -130,6 +133,7 @@ export default class HTMLFieldType extends QuestionPart {
}
public getEditedAsync(): Promise<IUserActionPart> {
let retVal = null;

if (this.answer) {
const changed = this.value != this.answer.values[0].value;
if (changed) {
Expand All @@ -149,7 +153,6 @@ export default class HTMLFieldType extends QuestionPart {

public getDeletedAsync(): Promise<IUserActionPart> {
let retVal = null;

if (this.answer && Object.keys(this.value).length == 0) {
const changed = this.value != this.answer.values[0].value;
if (changed) {
Expand All @@ -168,6 +171,6 @@ export default class HTMLFieldType extends QuestionPart {
}

public getValuesAsync(): Promise<IUserActionPart> {
return Promise.resolve(this.value);
return Promise.resolve(this.value as IUserActionPart);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]"
Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/component/renderable/schema/question/Question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -181,6 +182,9 @@ export default class Question {
}
: null;
}
public clearAnswer(){
this.answer =null
}
}

declare type AddRemoveCallback = () => void;
21 changes: 11 additions & 10 deletions src/options/connection-options/ChunkBasedConnectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 (
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"emitDecoratorMetadata": true,
"strictNullChecks": false,
"declaration": true,
"outDir": "src/types"
"outDir": "src/types",
"allowSyntheticDefaultImports": true
}
}