Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
fix #10 and add patch for microsoft/monaco-editor#1353
Browse files Browse the repository at this point in the history
  • Loading branch information
blutorange committed Aug 31, 2019
1 parent efe602c commit fedec76
Show file tree
Hide file tree
Showing 17 changed files with 1,108 additions and 123 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ Finally create a simple `xhtml` page and include the editor as a tag:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:blut="http://github.com/blutorange"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/jsf/core http://java.sun.com/jsf/core http://primefaces.org/ui/extensions ">
xsi:schemaLocation="http://xmlns.jcp.org/jsf/core http://xmlns.jcp.org/jsf/core http://primefaces.org/ui/extensions ">

<h:head>
<title>Demo Application</title>
Expand Down Expand Up @@ -220,7 +220,7 @@ repository. Now just specify the `extender` option on the editor component:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:blut="http://github.com/blutorange"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/jsf/core http://java.sun.com/jsf/core http://primefaces.org/ui/extensions ">
xsi:schemaLocation="http://xmlns.jcp.org/jsf/core http://xmlns.jcp.org/jsf/core http://primefaces.org/ui/extensions ">

<!-- ... -->

Expand Down Expand Up @@ -401,6 +401,7 @@ is for this project.

# Release

* __CHECK AND REMOVE src/npm/patches/monaco-editor+0.17.1.patch__ (https://github.com/microsoft/monaco-editor/issues/1353)
* `mvn versions:display-dependency-updates`
* Check for `TODO`s.
* Check `src/npm/descriptor/create.js` whether it reflects the current Monaco Editor API.
Expand Down
15 changes: 14 additions & 1 deletion demo/src/main/java/TestBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class TestBean implements Serializable {
private String longCode;
private String uiLanguage;
private boolean rendered;
private boolean rendered2;
private TheEnum theEnum;
private EditorOptions editorOptions;

Expand Down Expand Up @@ -103,11 +104,23 @@ public void setRendered(boolean rendered) {
this.rendered = rendered;
}

public boolean getRendered() {
public boolean isRendered() {
return rendered;
}

public void toggleRendered() {
rendered = !rendered;
}

public void setRendered2(boolean rendered2) {
this.rendered2 = rendered2;
}

public boolean isRendered2() {
return rendered2;
}

public void toggleRendered2() {
rendered2 = !rendered2;
}
}
17 changes: 14 additions & 3 deletions demo/src/main/webapp/resources/extender.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ class LocalStorageService {
}
}

/** @type {Map<string, string>} */
const TypeDeclarations = new Map();

/**
* An extener that loads the given typescript definition files into the editor
* @param {boolean} useLocalStorage
* @param {string[]} typescriptDefinitionFiles
* @return {import("../../../../../src/npm/primefaces-monaco").MonacoExtender}
*/
function createExtender(useLocalStorage, ...typescriptDefinitionFiles) {
Expand All @@ -68,9 +73,15 @@ function createExtender(useLocalStorage, ...typescriptDefinitionFiles) {

// Load all typescript definitions files and add register them with the editor.
const fetched = typescriptDefinitionFiles.map(file =>
fetch(file)
.then(response => response.text())
.then(text => ({text, file}))
TypeDeclarations.has(file) ?
{file, text: TypeDeclarations.get(file)} :
fetch(file)
.then(response => response.text())
.then(text => {
TypeDeclarations.set(file, text);
return text;
})
.then(text => ({text, file}))
);
return Promise.all(fetched)
.then(defs => defs.forEach(def => {
Expand Down
169 changes: 120 additions & 49 deletions demo/src/main/webapp/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,131 @@
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">

<h:head>
<title>My First JSF Application</title>
<h:outputStylesheet>
.ui-layout-center {
overflow: hidden !important;
}
#log pre {
margin: 0.5em 0;
white-space: pre-wrap;
}
#log {
counter-reset: line 0;
}
.line {
counter-increment: line;
display: flex;
flex-direction: row;
word-break: break-all;
}
.line::before {
content: counter(line) ">";
margin-right: 0.5em;
min-width: 40px;
font-weight: bold;
}
#tests {
display: flex;
flex-direction: row;
flex-wrap: wrap;
list-style-type: none;
}
h1 {
margin: 0;
}
#tests li {
margin: 0 0.25em;
}
</h:outputStylesheet>
<script>
var toLog = [];
function log() {
var div = document.getElementById("log");
if (!div) {
toLog.push(arguments);
return;
}
else if (toLog.length !== 0) {
for (var i = 0; i !== toLog.length; ++i) {
var message = Array.prototype.join.call(toLog[i], " ");
var pre = document.createElement("pre");
pre.setAttribute("class", "line");
pre.textContent = message;
div.appendChild(pre);
}
toLog = [];
}
var message = Array.prototype.join.call(arguments, " ");
var pre = document.createElement("pre");
pre.setAttribute("class", "line");
pre.textContent = message;
div.appendChild(pre);
}

// Log errors
window.addEventListener("error", function(event) {
log("An unhandled error occurred");
log(event.message);
});
</script>
<h:outputScript rendered="#{logXhr}">
// Log requests
(function(){
// XMLHttpRequest
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
origOpen.apply(this, arguments);
window.dispatchEvent(new CustomEvent("xhr.open", {
detail: {
method: method,
url: url,
xmlHttpRequest: this,
},
}));
};
// worker
var origWorker = window.Worker;
class _Worker extends origWorker {
constructor(url, options) {
super(url, options);
window.dispatchEvent(new CustomEvent("xhr.open", {
detail: {
method: "GET",
url: url,
xmlHttpRequest: this,
},
}));
}
}
window.Worker = _Worker;
})();

// Fetch
var origFetch = window.fetch;
window.fetch = function(input, init) {
const promise = origFetch.call(this, input, init);
window.dispatchEvent(new CustomEvent("xhr.open", {
detail: {
method: init ? init.method || "GET" : "GET",
url: input,
xmlHttpRequest: this,
},
}));
return promise;
};

window.addEventListener("xhr.open", function(e) {
log("AJAX request to", e.detail.url);
});
</h:outputScript>
<ui:insert name="headLast" />
</h:head>
<h:outputStylesheet>
.ui-layout-center {
overflow: hidden !important;
}
#log pre {
margin: 0.5em 0;
white-space: pre-wrap;
}
#log {
counter-reset: line 0;
}
.line {
counter-increment: line;
display: flex;
flex-direction: row;
}
.line::before {
content: counter(line) ">";
margin-right: 0.5em;
font-weight: bold;
}
#tests {
display: flex;
flex-direction: row;
flex-wrap: wrap;
list-style-type: none;
}
h1 {
margin: 0;
}
#tests li {
margin: 0 0.25em;
}
</h:outputStylesheet>
<h:body>
<pe:layout fullPage="true" style="overflow:hidden;">
<pe:layoutPane position="center" style="overflow:hidden;">
Expand All @@ -74,18 +157,6 @@
</pe:layoutPane>
</pe:layout>
<script>
function log() {
var div = document.getElementById("log");
var message = Array.prototype.join.call(arguments, " ");
var pre = document.createElement("pre");
pre.setAttribute("class", "line");
pre.textContent = message;
div.appendChild(pre);
}
window.addEventListener("error", function(event) {
log("An unhandled error occurred");
log(event.message);
});
$(function() {
if (typeof window.testCase === "function") {
try {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/webapp/test.xhtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:blut="http://github.com/blutorange"
xmlns:xi="http://www.xima.de/taglib/xfc"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:pe="http://primefaces.org/ui/extensions"
template="./template.xhtml">

Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/webapp/test2.xhtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:blut="http://github.com/blutorange"
xmlns:xi="http://www.xima.de/taglib/xfc"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:pe="http://primefaces.org/ui/extensions"
template="./template.xhtml">

Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/webapp/test3.xhtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:blut="http://github.com/blutorange"
xmlns:xi="http://www.xima.de/taglib/xfc"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:pe="http://primefaces.org/ui/extensions"
template="./template.xhtml">

Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/webapp/test4.xhtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:blut="http://github.com/blutorange"
xmlns:xi="http://www.xima.de/taglib/xfc"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:pe="http://primefaces.org/ui/extensions"
template="./template.xhtml">

Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/webapp/test5.xhtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:blut="http://github.com/blutorange"
xmlns:xi="http://www.xima.de/taglib/xfc"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:pe="http://primefaces.org/ui/extensions"
template="./template.xhtml">

Expand Down
15 changes: 9 additions & 6 deletions demo/src/main/webapp/test6.xhtml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:blut="http://github.com/blutorange"
xmlns:xi="http://www.xima.de/taglib/xfc"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:pe="http://primefaces.org/ui/extensions"
template="./template.xhtml">

<f:metadata>
<f:viewAction actionListener="#{testBean.setCodeLanguage('scss')}"/>
<f:viewAction actionListener="#{testBean.setCode('body { color: red; }')}"/>
</f:metadata>

<ui:define name="headLast">
<h:outputScript name="extender.js" />
<c:set value="scss" target="#{testBean}" property="codeLanguage" />
<c:set value="body { color: red; }" target="#{testBean}" property="code" />
</ui:define>

<ui:define name="monaco">
Expand Down
Loading

0 comments on commit fedec76

Please sign in to comment.