Skip to content

Commit

Permalink
Merge pull request #13540 from calixteman/13536
Browse files Browse the repository at this point in the history
XFA - Return html element for the different possible value
  • Loading branch information
calixteman authored Jun 11, 2021
2 parents 950dcc7 + 367d1ad commit 7b4fa0a
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ function getRoot(node) {
return parent;
}

function valueToHtml(value) {
return HTMLResult.success({
name: "span",
attributes: {
class: ["xfaRich"],
style: Object.create(null),
},
value,
});
}

function getTransformedBBox(node) {
// Take into account rotation and anchor the get the
// real bounding box.
Expand Down Expand Up @@ -615,7 +626,7 @@ class BooleanElement extends Option01 {
}

[$toHTML](availableSpace) {
return HTMLResult.success(this[$content] === 1);
return valueToHtml(this[$content] === 1);
}
}

Expand Down Expand Up @@ -1257,11 +1268,12 @@ class DateElement extends ContentObject {
}

[$finalize]() {
this[$content] = new Date(this[$content].trim());
const date = this[$content].trim();
this[$content] = date ? new Date(date) : null;
}

[$toHTML](availableSpace) {
return HTMLResult.success(this[$content].toString());
return valueToHtml(this[$content] ? this[$content].toString() : "");
}
}

Expand All @@ -1275,11 +1287,12 @@ class DateTime extends ContentObject {
}

[$finalize]() {
this[$content] = new Date(this[$content].trim());
const date = this[$content].trim();
this[$content] = date ? new Date(date) : null;
}

[$toHTML](availableSpace) {
return HTMLResult.success(this[$content].toString());
return valueToHtml(this[$content] ? this[$content].toString() : "");
}
}

Expand Down Expand Up @@ -1351,7 +1364,7 @@ class Decimal extends ContentObject {
}

[$toHTML](availableSpace) {
return HTMLResult.success(
return valueToHtml(
this[$content] !== null ? this[$content].toString() : ""
);
}
Expand Down Expand Up @@ -2365,12 +2378,12 @@ class Field extends XFAObject {
if (this.ui.imageEdit) {
ui.children.push(this.value[$toHTML]().html);
} else if (!this.ui.button) {
const value = this.value[$toHTML]().html;
const value = this.value[$toHTML]().html.value;
if (value) {
if (ui.children[0].name === "textarea") {
ui.children[0].attributes.textContent = value.value;
ui.children[0].attributes.textContent = value;
} else {
ui.children[0].attributes.value = value.value;
ui.children[0].attributes.value = value;
}
}
}
Expand Down Expand Up @@ -2522,7 +2535,7 @@ class Float extends ContentObject {
}

[$toHTML](availableSpace) {
return HTMLResult.success(
return valueToHtml(
this[$content] !== null ? this[$content].toString() : ""
);
}
Expand Down Expand Up @@ -2812,7 +2825,7 @@ class Integer extends ContentObject {
}

[$toHTML](availableSpace) {
return HTMLResult.success(
return valueToHtml(
this[$content] !== null ? this[$content].toString() : ""
);
}
Expand Down Expand Up @@ -4642,14 +4655,7 @@ class Text extends ContentObject {
if (typeof this[$content] === "string") {
// \u2028 is a line separator.
// \u2029 is a paragraph separator.
const html = {
name: "span",
attributes: {
class: ["xfaRich"],
style: {},
},
value: this[$content],
};
const html = valueToHtml(this[$content]).html;

if (this[$content].includes("\u2029")) {
// We've plain text containing a paragraph separator
Expand Down Expand Up @@ -4782,12 +4788,13 @@ class Time extends StringObject {
}

[$finalize]() {
// TODO
this[$content] = new Date(this[$content]);
// TODO: need to handle the string as a time and not as a date.
const date = this[$content].trim();
this[$content] = date ? new Date(date) : null;
}

[$toHTML](availableSpace) {
return HTMLResult.success(this[$content].toString());
return valueToHtml(this[$content] ? this[$content].toString() : "");
}
}

Expand Down

0 comments on commit 7b4fa0a

Please sign in to comment.