Skip to content

Commit 46832ff

Browse files
authored
Merge pull request #84 from manolo/elemental2
Elemental2
2 parents 3d6a9b6 + 3e476d0 commit 46832ff

34 files changed

+2005
-353
lines changed

bin/gwt-api-generator.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
var gulp = require('gulp')
44
require('../gulpfile');
55

6+
var gutil = require('gulp-util');
7+
gutil.log('Running gwt-api-generator version: ' + require('../package.json').version);
8+
69
require('coa').Cmd()
710
.name(process.argv[1])
811
.title('gwt-api-generator')
@@ -32,6 +35,11 @@ require('coa').Cmd()
3235
.title('Artifact id of the project. (Default: gwt-polymer-elements)')
3336
.long('artifactId')
3437
.end()
38+
.opt()
39+
.name('Module Name')
40+
.title('Module name of your components. (Default: Elements.gwt.xml)')
41+
.long('moduleName')
42+
.end()
3543
.opt()
3644
.name('Version')
3745
.title('Version of the generated maven project. (Defaults to package.json.pom.version || pakage.json.version)')

gulpfile.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,16 @@ gulp.task('generate:widget-events', ['parse'], function() {
230230
});
231231
});
232232

233-
gulp.task('generate:gwt-module', function() {
234-
if (!args.excludeLib) {
233+
gulp.task('generate:gwt-module', function () {
234+
if (args.moduleName != 'Elements' || args.groupId != 'com.vaadin.polymer') {
235+
var dest = globalVar.publicDir.replace(/[^\/]+\/?$/, '');
236+
gutil.log("Generating Module: " + dest + args.moduleName + ".gwt.xml");
235237
return gulp.src(tplDir + "GwtModule.template")
236-
.pipe(rename("Elements.gwt.xml"))
237-
.pipe(gulp.dest(globalVar.publicDir + "../"));
238+
.pipe(rename(args.moduleName + ".gwt.xml"))
239+
.pipe(gulp.dest(dest));
238240
}
239241
});
240242

241-
gulp.task('copy:static-gwt-module', function() {
242-
return gulp.src(tplDir + "Elements.gwt.xml")
243-
.pipe(gulp.dest(globalVar.publicDirBase + '/com/vaadin/polymer/'));
244-
});
245-
246-
247243
gulp.task('generate:elements-all', ['generate:elements', 'generate:events']);
248244

249245
gulp.task('generate:widgets-all', ['generate:widgets', 'generate:widget-events']);
@@ -281,8 +277,8 @@ gulp.task('copy:pom', function() {
281277

282278
gulp.task('default', function(){
283279
if(args.pom) {
284-
runSequence('clean', 'bower:install', 'generate', 'copy:lib', 'copy:static-gwt-module', 'copy:pom');
280+
runSequence('clean', 'bower:install', 'generate', 'copy:lib', 'copy:pom');
285281
} else {
286-
runSequence('clean', 'bower:install', 'generate', 'copy:lib', 'copy:static-gwt-module');
282+
runSequence('clean', 'bower:install', 'generate', 'copy:lib');
287283
}
288284
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
<module>
33
<source path="" />
44
<inherits name='com.google.gwt.user.User'/>
5+
<inherits name='elemental2.core.Core'/>
6+
<inherits name='elemental2.dom.Dom'/>
57
</module>

lib/com/vaadin/polymer/Polymer.java

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import com.google.gwt.core.client.GWT;
44
import com.google.gwt.core.client.JavaScriptObject;
5-
import com.google.gwt.core.client.JsArray;
5+
import elemental2.core.Array;
66
import com.google.gwt.dom.client.Document;
77
import com.google.gwt.dom.client.Element;
88
import com.google.gwt.user.client.DOM;
9-
import com.google.gwt.user.client.Timer;
109

11-
import com.vaadin.polymer.elemental.Function;
12-
import com.vaadin.polymer.elemental.HTMLElement;
10+
import com.vaadin.polymer.PolymerFunction;
11+
import elemental2.dom.HTMLElement;
1312

1413
import java.util.ArrayList;
1514
import java.util.HashMap;
@@ -22,6 +21,7 @@
2221
import jsinterop.annotations.JsPackage;
2322
import jsinterop.annotations.JsProperty;
2423
import jsinterop.annotations.JsType;
24+
import jsinterop.base.Js;
2525

2626
@SuppressWarnings({"rawtypes", "unchecked"})
2727
public abstract class Polymer {
@@ -61,11 +61,11 @@ public interface DomApi {
6161

6262
<T extends HTMLElement> T querySelector(String selector);
6363

64-
JsArray querySelectorAll(String selector);
64+
Array querySelectorAll(String selector);
6565

6666
void appendChild(Object el);
6767

68-
JsArray children();
68+
Array children();
6969
}
7070

7171
@JsType(isNative=true, namespace=GLOBAL)
@@ -120,7 +120,7 @@ public interface Base {
120120
* timing (after the current method finishes, but before the next event from the event
121121
* queue is processed). Returns a handle that can be used to cancel the task.
122122
*/
123-
Object async(Function method, int wait);
123+
Object async(PolymerFunction method, int wait);
124124

125125
/**
126126
* Cancels the identified async task.
@@ -143,7 +143,7 @@ public interface Base {
143143
/**
144144
* Dynamically imports an HTML document.
145145
*/
146-
void importHref(String href, Function onload, Function onerror);
146+
void importHref(String href, PolymerFunction onload, PolymerFunction onerror);
147147

148148
/**
149149
* Takes a URL relative to the <dom-module> of an imported Polymer element, and returns
@@ -154,7 +154,7 @@ public interface Base {
154154
}
155155

156156
private static Set<String> urlImported = new HashSet<>();
157-
private static HashMap<String, List<Function>> whenImported = new HashMap<>();
157+
private static HashMap<String, List<PolymerFunction>> whenImported = new HashMap<>();
158158

159159
/**
160160
* Inserts the appropriate &lt;import&gt; of a component given by url.
@@ -171,7 +171,7 @@ public static void importHref(String href) {
171171
* @param href either an absolute url or a path relative to bower_components folder.
172172
* @param ok callback to run in case of success
173173
*/
174-
public static void importHref(String href, Function ok) {
174+
public static void importHref(String href, PolymerFunction ok) {
175175
importHref(href, ok, null);
176176
}
177177

@@ -191,7 +191,7 @@ private static String absoluteHref(String hrefOrTag) {
191191
}
192192

193193
// Loads Polymer once if not done yet, and queue all callbaks until ready
194-
private static native void whenPolymerLoaded(Function ok)
194+
private static native void whenPolymerLoaded(PolymerFunction ok)
195195
/*-{
196196
function resolve() {
197197
// Set our static reference to Base
@@ -236,19 +236,19 @@ function resolve() {
236236
* @param ok callback to run in case of success
237237
* @param err callback to run in case of failure
238238
*/
239-
public static void importHref(String hrefOrTag, final Function ok, final Function err) {
239+
public static void importHref(String hrefOrTag, final PolymerFunction ok, final PolymerFunction err) {
240240
final String href = absoluteHref(hrefOrTag);
241241

242-
Function done = arg -> {
243-
urlImported.add(href);
244-
List<Function> pending = whenImported.get(href);
245-
if (pending != null) {
246-
for (Function f : pending) {
247-
f.call(null);
248-
}
242+
PolymerFunction done = arg -> {
243+
urlImported.add(href);
244+
List<PolymerFunction> pending = whenImported.get(href);
245+
if (pending != null) {
246+
for (PolymerFunction f : pending) {
247+
f.call(null);
249248
}
250-
whenImported.remove(href);
251-
return null;
249+
}
250+
whenImported.remove(href);
251+
return null;
252252
};
253253
if (Base == null) {
254254
whenPolymerLoaded(arg -> {
@@ -259,9 +259,9 @@ public static void importHref(String hrefOrTag, final Function ok, final Functio
259259
}
260260
if (!urlImported.contains(href)) {
261261
if (!isRegistered(href)) {
262-
List<Function> pending = whenImported.get(href);
262+
List<PolymerFunction> pending = whenImported.get(href);
263263
if (pending == null) {
264-
pending = new ArrayList<Function>();
264+
pending = new ArrayList<PolymerFunction>();
265265
whenImported.put(href, pending);
266266
Base.importHref(href, done, err);
267267
}
@@ -291,9 +291,8 @@ public static void importHref(final List<String> hrefs) {
291291
*
292292
* @param hrefs a list of absolute urls or relative paths to load.
293293
* @param ok callback to run in case of all import success
294-
* @param err callback to run in case of failure
295294
*/
296-
public static void importHref(final List<String> hrefs, final Function ok) {
295+
public static void importHref(final List<String> hrefs, final PolymerFunction ok) {
297296
importHref(hrefs, ok, null);
298297
}
299298

@@ -304,8 +303,8 @@ public static void importHref(final List<String> hrefs, final Function ok) {
304303
* @param ok callback to run in case of all import success
305304
* @param err callback to run in case of failure
306305
*/
307-
public static void importHref(final List<String> hrefs, final Function ok, Function err) {
308-
Function allOk = ok == null ? ok : new Function() {
306+
public static void importHref(final List<String> hrefs, final PolymerFunction ok, PolymerFunction err) {
307+
PolymerFunction allOk = ok == null ? ok : new PolymerFunction() {
309308
int count = hrefs.size();
310309
public Object call(Object arg) {
311310
if (--count == 0) {
@@ -355,8 +354,8 @@ public static <T> T createElement(String tagName) {
355354
/**
356355
* Returns the JsInterop instance of Document
357356
*/
358-
public static com.vaadin.polymer.elemental.Document getDocument() {
359-
return (com.vaadin.polymer.elemental.Document)Document.get();
357+
public static elemental2.dom.Document getDocument() {
358+
return Js.cast(Document.get());
360359
}
361360

362361
/**
@@ -376,11 +375,11 @@ private native static boolean isRegisteredElement(Object e)
376375
return !!e && e.constructor !== $wnd.HTMLElement && e.constructor != $wnd.HTMLUnknownElement;
377376
}-*/;
378377

379-
public static void ready(HTMLElement e, Function f) {
380-
whenReady(f, (Element)e);
378+
public static void ready(HTMLElement e, PolymerFunction f) {
379+
whenReady(f, Js.cast(e));
381380
}
382381

383-
public static void ready(Element e, Function f) {
382+
public static void ready(Element e, PolymerFunction f) {
384383
whenReady(f, e);
385384
}
386385

@@ -394,7 +393,7 @@ public static void updateStyles() {
394393
/**
395394
* Executes a function after all imports have been loaded.
396395
*/
397-
public static void whenReady(Function f) {
396+
public static void whenReady(PolymerFunction f) {
398397
whenReady(f, null);
399398
}
400399

@@ -408,7 +407,7 @@ private native static boolean htmlImportsSupported()
408407
* passed element is ready to use.
409408
* For browsers not supporting html imports, it loads the webcomponentsjs polyfill.
410409
*/
411-
public static native void whenReady(Function f, Element e)
410+
public static native void whenReady(PolymerFunction f, Element e)
412411
/*-{
413412
function registered() {
414413
if (e) {
@@ -445,12 +444,12 @@ function loadPolyfill() {
445444

446445
/**
447446
* If an element is not ready, loops until it gets ready, then
448-
* run a Function (JsFunction or JavaFunction)
447+
* run a PolymerFunction (JsFunction or JavaFunction)
449448
* @deprecated use {@link #whenReady(Function, Element)} instead.
450449
*/
451450
@Deprecated
452451
private static void onReady(Element e, Object f) {
453-
whenReady((Function)f, e);
452+
whenReady((PolymerFunction)f, e);
454453
}
455454

456455
/**
@@ -478,12 +477,12 @@ public static void endLoading(final Element container, Element webcomponent) {
478477
*
479478
* @param container : The container to show when the component is available
480479
* @param webcomponent : Web component to monitor
481-
* @param callback : Calback function
480+
* @param func : Calback function
482481
*/
483-
public static void endLoading(final Element container, Element webcomponent, final Function func) {
482+
public static void endLoading(final Element container, Element webcomponent, final PolymerFunction func) {
484483
container.getStyle().setOpacity(0);
485484
container.getStyle().setProperty("transition", "opacity 1.1s");
486-
ready(webcomponent, new Function() {
485+
ready(webcomponent, new PolymerFunction() {
487486
public Object call(Object arg) {
488487
reFlow();
489488
container.getStyle().setOpacity(1);
@@ -531,7 +530,7 @@ public static native <T> List<T> asList(JavaScriptObject o)
531530
* penalty because we directly take the native array of the super ArrayList
532531
* implementation.
533532
*/
534-
public static native <T extends JavaScriptObject> JsArray<T> asJsArray(List<?> l)
533+
public static native <T extends JavaScriptObject> Array<T> asJsArray(List<?> l)
535534
/*-{
536535
return l.@java.util.ArrayList::array;
537536
}-*/;
@@ -570,7 +569,7 @@ public native static void property(Object jso, String name, Object value)
570569
* Utility method for setting a function to a JS object.
571570
* Useful for binding functions to templates.
572571
*/
573-
public static void function(Object jso, String name, Function fnc) {
572+
public static void function(Object jso, String name, PolymerFunction fnc) {
574573
property(jso, name, fnc);
575574
}
576575

@@ -582,16 +581,10 @@ public native static <T> T apply(Object jso, String methodName, Object... args)
582581
return jso[methodName].apply(jso, args);
583582
}-*/;
584583

585-
public static native <T> T cast(Object o)
586-
/*-{
587-
return o;
588-
}-*/;
589-
590584
/**
591585
* Return the dom API of one element.
592586
*/
593587
public static DomApi dom(Object element) {
594588
return Polymer.dom(element);
595589
}
596590
}
597-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.vaadin.polymer;
2+
3+
import static jsinterop.annotations.JsPackage.GLOBAL;
4+
5+
import elemental2.dom.HTMLElement;
6+
import jsinterop.annotations.JsType;
7+
8+
/**
9+
* PolymerElement is a class over the HTMLElement of elemental2 adding
10+
* some utility methods present in Polymer Elements, or missing in the
11+
* elemental2 API.
12+
*/
13+
@JsType(isNative=true, namespace = GLOBAL, name = "HTMLElement")
14+
public class PolymerElement extends HTMLElement {
15+
16+
/** Properties and methods added by Polymer API **/
17+
public HTMLElement root;
18+
public native void debounce(String name, PolymerFunction<?, ?> f, int timeout);
19+
/**
20+
* Polymer’s custom property shim evaluates and applies custom property values once at element creation time.
21+
* In order to have an element (and its subtree) re- evaluate custom property values due to dynamic changes
22+
* such as application of CSS classes, etc., call updateStyles().
23+
*/
24+
public native void updateStyles();
25+
26+
/** Missing properties in elemental2.dom.Element **/
27+
public String textContent;
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.vaadin.polymer;
2+
3+
import jsinterop.annotations.JsProperty;
4+
import jsinterop.annotations.JsType;
5+
import elemental2.dom.EventInit;
6+
import elemental2.dom.EventTarget;
7+
8+
import static jsinterop.annotations.JsPackage.GLOBAL;
9+
10+
11+
/**
12+
* PolymerEvent is a class over the Element implementation of elemental2 adding
13+
* some properties present in Polymer Events, or missing in the elemental2 API.
14+
*/
15+
@JsType(isNative=true, namespace=GLOBAL, name="Event")
16+
public class PolymerEvent extends elemental2.dom.Event {
17+
18+
public PolymerEvent(String type, EventInit eventInitDict) {
19+
super(type, eventInitDict);
20+
}
21+
22+
public PolymerEvent(String type) {
23+
super(type);
24+
}
25+
26+
@JsProperty
27+
public native String getType();
28+
29+
@JsProperty
30+
public native Detail getDetail();
31+
32+
@JsProperty
33+
public native EventTarget getTarget();
34+
35+
@JsType(isNative=true)
36+
public interface Detail {
37+
}
38+
}
39+

0 commit comments

Comments
 (0)