Skip to content

Commit

Permalink
wip: transpilation error for browser
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLuq committed Feb 1, 2019
1 parent e5a5999 commit 140d95c
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"description": "A javascript implementation of schematron testing for XML documents. This specifically resolves a need for a package that allows a quick, reliable install for validating HL7 clinical documents, such as C-CDA.",
"cjs": "build/schematron-runner.js",
"cjsDebug": "build/debug.js",
"main": "build/debug.js",
"main": "build/schematron-runner.js",
"module": "build/schematron-runner.mjs",
"browser": "build/schematron-browser.js",
"types": "esm/schematron-runner.d.ts",
Expand Down Expand Up @@ -47,6 +47,7 @@
"@types/node-fetch": "^2.1.4",
"@types/xmldom": "^0.1.29",
"ava": "^1.0.1",
"babel-polyfill": "^6.26.0",
"nyc": "^13.1.0",
"rollup": "^1.1.2",
"rollup-plugin-babel": "^4.3.2",
Expand Down
5 changes: 4 additions & 1 deletion rollup.config.js
Expand Up @@ -16,6 +16,9 @@ function xpathResolver() {
if (importee === "xpath") {
return resolvePath(process.cwd(), "node_modules", "xpath", "xpath.js");
}
if (importee === "regenerator-runtime/runtime") {
return resolvePath(process.cwd(), "node_modules", "regenerator-runtime", "runtime.js");
}
return null;
}
};
Expand Down Expand Up @@ -58,7 +61,7 @@ export default [
plugins: [
resolve(),
sourcemaps(),
babel(babelConf({ chrome: "62", node: "8" })),
babel(babelConf({ chrome: "64", node: "8" })),
terser(),
]
},
Expand Down
4 changes: 3 additions & 1 deletion src/browser.ts
@@ -1,3 +1,5 @@
import "regenerator-runtime/runtime";

import { IValidateOptions } from "./common";
import { validateFocused, webDefaults } from "./validator";

Expand All @@ -11,7 +13,7 @@ export {
export {
clearCache, validateFocused,
throwDefaults, webDefaults,
CheckOptionsHandler, IValidationResult,
CheckOptionsHandler, ICompletedValidation, IValidationResult,
} from "./validator";

export { IValidateOptions } from "./common";
Expand Down
2 changes: 1 addition & 1 deletion src/schematron-runner.ts
Expand Up @@ -8,7 +8,7 @@ export {
export {
clearCache, validate, validate as default, validateFocused,
polymorphicDefaults, throwDefaults, webDefaults,
CheckOptionsHandler, IValidationResult,
CheckOptionsHandler, ICompletedValidation, IValidationResult,
} from "./validator";

export { IValidateOptions } from "./common";
Expand Down
32 changes: 32 additions & 0 deletions test/browser/es5.html
@@ -0,0 +1,32 @@
<html>
<head>
<title>Example</title>
<script data-main="./es5" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" defer="" async=""></script>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<div id="c">
<div>
<div class="i">
<label for="sch">Schematron URL</label>
<input id="sch" value="https://raw.githubusercontent.com/OpenPEPPOL/peppol-bis-invoice-3/master/rules/examples/Allowance-example.xml" />
</div>
<div class="i">
<label for="xml">XML URL</label>
<input id="xml" value="https://raw.githubusercontent.com/OpenPEPPOL/peppol-bis-invoice-3/master/rules/sch/CEN-EN16931-UBL.sch" />
</div>
<div>
<button id="btn" disabled="disabled">Run validation</button>
<span id="status">Loading...</span>
</div>
</div>
<hr />
<table id="table">
<thead>
<tr><th>Lvl</th><th>Assertion</th><th>Description</th></tr>
</thead>
<tbody id="results"></tbody>
</table>
</div>
</body>
</html>
69 changes: 69 additions & 0 deletions test/browser/es5.js
@@ -0,0 +1,69 @@
requirejs.config({});

function createTr(data) {
var r = document.createElement("tr");
for (var i = 0; i < data.length; i++) {
var e = document.createElement("td");
e.textContent = data[i] || "";
r.appendChild(e);
}
return r;
}

requirejs(['../../build/schematron-browser'], function (shematron) {
/** @type {HTMLButtonElement} */
var btn = document.getElementById("btn");
/** @type {HTMLDivElement} */
var status = document.getElementById("status");
/** @type {HTMLInputElement} */
var sch = document.getElementById("sch");
/** @type {HTMLInputElement} */
var xml = document.getElementById("xml");
/** @type {HTMLTableSectionElement} */
var results = document.getElementById("results");

/** @type {import("../../esm/browser").validate} */
var validate = schematron.validate;

btn.onclick = function () {
btn.disabled = true;
status.textContent = "Running validation...";
while (results.hasChildNodes()) {
results.removeChild(results.lastChild);
}

/** @type {import("../../esm/browser").IValidateOptions} */
const options = {
resourceDir: window.location.href
};

validate(xml.value, sch.value, options).then(function (r) {
r.errors.forEach(function (e) {
var d = ["🔴", e.assertionId, e.description];
results.appendChild(createTr(d));
});
r.ignored.forEach(function (e) {
var d = ["⚠", e.assertionId, e.errorMessage];
results.appendChild(createTr(d));
});
r.warnings.forEach(function (e) {
var d = ["🔸", e.assertionId, e.description];
results.appendChild(createTr(d));
});
r.passed.forEach(function (e) {
var d = ["✓", e.assertionId, e.description];
results.appendChild(createTr(d));
});

status.textContent = "";
}).catch(function (e) {
console.error(e);
status.textContent = e.toString();
}).then(function () {
btn.disabled = false;
});
};

status.textContent = "";
btn.disabled = false;
});
43 changes: 43 additions & 0 deletions test/browser/styles.css
@@ -0,0 +1,43 @@
:root, html {
margin: 0;
padding: 0;
background: #ccc;
}

body {
max-width: 720px;
margin: 0 auto;
padding: 8px;
background: #efefef;
}

#c {
position: relative;
}

tr.warn {
color: rgb(120, 85, 0);
}
tr.error {
color: rgb(90, 0, 0);
}
tr.passed {
color: rgb(0, 90, 0);
}

.i {
position: relative;
margin: 12px 0;
}
.i > input {
display: block;
width: 100%;
}
.i > input:focus {
outline: #009 thin;
border-color: #009;
}
.i > label {
display: block;
width: auto;
}

0 comments on commit 140d95c

Please sign in to comment.