diff --git a/jso/apis/src/main/java/org/teavm/jso/ajax/FormData.java b/jso/apis/src/main/java/org/teavm/jso/ajax/FormData.java new file mode 100644 index 000000000..d41b3a7c5 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/ajax/FormData.java @@ -0,0 +1,67 @@ +/* + * Copyright 2024 ihromant. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.ajax; + +import org.teavm.jso.JSClass; +import org.teavm.jso.JSObject; +import org.teavm.jso.core.JSArray; +import org.teavm.jso.dom.html.HTMLElement; +import org.teavm.jso.dom.html.HTMLFormElement; +import org.teavm.jso.file.Blob; + +@JSClass +public class FormData implements JSObject { + public FormData() { + } + + public FormData(HTMLFormElement form) { + } + + public FormData(HTMLFormElement form, HTMLElement submitter) { + } + + public native void append(String name, String value); + + public native void append(String name, Blob value); + + public native void append(String name, String value, String fileName); + + public native void append(String name, Blob value, String fileName); + + public native void delete(String name); + + /** + * Actual element is either {@link Blob} or {@link org.teavm.jso.core.JSString} + */ + // TODO: update signature when union types supported in TeaVM + public native JSObject get(String name); + + /** + * Actual elements are {@link Blob} or {@link org.teavm.jso.core.JSString} + */ + // TODO: update signature when union types supported in TeaVM + public native JSArray getAll(String name); + + public native boolean has(String name); + + public native void set(String name, String value); + + public native void set(String name, Blob value); + + public native void set(String name, String value, String fileName); + + public native void set(String name, Blob value, String fileName); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java b/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java index 7ab01821d..824225ddc 100644 --- a/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java +++ b/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java @@ -24,6 +24,7 @@ import org.teavm.jso.dom.events.EventListener; import org.teavm.jso.dom.events.EventTarget; import org.teavm.jso.dom.events.Registration; import org.teavm.jso.dom.xml.Document; +import org.teavm.jso.file.Blob; @JSClass public class XMLHttpRequest implements JSObject, EventTarget { @@ -52,6 +53,10 @@ public class XMLHttpRequest implements JSObject, EventTarget { public native void send(String data); + public native void send(Blob blob); + + public native void send(FormData formData); + public native void send(JSObject data); public native void setRequestHeader(String name, String value); diff --git a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLInputElement.java b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLInputElement.java index cf8f15940..150270b46 100644 --- a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLInputElement.java +++ b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLInputElement.java @@ -16,6 +16,7 @@ package org.teavm.jso.dom.html; import org.teavm.jso.JSProperty; +import org.teavm.jso.file.FileList; public abstract class HTMLInputElement extends HTMLElement { @JSProperty @@ -79,4 +80,7 @@ public abstract class HTMLInputElement extends HTMLElement { @JSProperty public abstract void setPlaceholder(String value); + + @JSProperty + public abstract FileList getFiles(); } diff --git a/jso/apis/src/main/java/org/teavm/jso/file/Blob.java b/jso/apis/src/main/java/org/teavm/jso/file/Blob.java new file mode 100644 index 000000000..39de513ce --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/file/Blob.java @@ -0,0 +1,60 @@ +/* + * Copyright 2024 ihromant. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.file; + +import org.teavm.jso.JSClass; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; +import org.teavm.jso.core.JSArrayReader; +import org.teavm.jso.core.JSPromise; +import org.teavm.jso.streams.ReadableStream; +import org.teavm.jso.typedarrays.ArrayBuffer; + +@JSClass +public class Blob implements JSObject { + /** + * Actual elements within array are either {@link Blob} or {@link org.teavm.jso.core.JSString} + */ + // TODO: update signature when + public Blob(JSArrayReader array) { + } + + /** + * Actual elements within array are either {@link Blob} or {@link org.teavm.jso.core.JSString} + */ + public Blob(JSArrayReader array, BlobPropertyBag options) { + } + + @JSProperty + public native int getSize(); + + @JSProperty + public native String getType(); + + public native JSPromise arrayBuffer(); + + public native Blob slice(); + + public native Blob slice(int start); + + public native Blob slice(int start, int end); + + public native Blob slice(int start, int end, String contentType); + + public native ReadableStream stream(); + + public native JSPromise text(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/file/BlobPropertyBag.java b/jso/apis/src/main/java/org/teavm/jso/file/BlobPropertyBag.java new file mode 100644 index 000000000..6d4f74f98 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/file/BlobPropertyBag.java @@ -0,0 +1,51 @@ +/* + * Copyright 2024 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.file; + +import org.teavm.jso.JSClass; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; +import org.teavm.jso.core.JSObjects; + +@JSClass(transparent = true) +public abstract class BlobPropertyBag implements JSObject { + public static final String ENDING_TYPE_TRANSPARENT = "transparent"; + public static final String ENDING_TYPE_NATIVE = "native"; + + BlobPropertyBag() { + } + + public static BlobPropertyBag create() { + return JSObjects.create(); + } + + public BlobPropertyBag type(String type) { + setType(type); + return this; + } + + // TODO: update signature when union of strings (lighweight enums) are supported in TeaVM + public BlobPropertyBag endingType(String endingType) { + setEndingType(endingType); + return this; + } + + @JSProperty + private native void setType(String type); + + @JSProperty + private native void setEndingType(String endingType); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/file/File.java b/jso/apis/src/main/java/org/teavm/jso/file/File.java new file mode 100644 index 000000000..1a209c778 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/file/File.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024 ihromant. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.file; + +import org.teavm.jso.JSClass; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; +import org.teavm.jso.core.JSArrayReader; + +@JSClass +public class File extends Blob implements JSObject { + /** + * Actual elements within array are either {@link Blob} or {@link org.teavm.jso.core.JSString} + */ + public File(JSArrayReader array, String fileName) { + super(null); + } + + /** + * Actual elements within array are either {@link Blob} or {@link org.teavm.jso.core.JSString} + */ + public File(JSArrayReader array, String fileName, JSObject options) { + super(null, null); + } + + @JSProperty + public native double getLastModified(); + + @JSProperty + public native String getName(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/file/FileList.java b/jso/apis/src/main/java/org/teavm/jso/file/FileList.java new file mode 100644 index 000000000..c35898fae --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/file/FileList.java @@ -0,0 +1,25 @@ +/* + * Copyright 2024 ihromant. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.file; + +import org.teavm.jso.JSIndexer; +import org.teavm.jso.JSObject; +import org.teavm.jso.core.JSArrayReader; + +public interface FileList extends JSObject, JSArrayReader { + @JSIndexer + File item(int index); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/file/FilePropertyBag.java b/jso/apis/src/main/java/org/teavm/jso/file/FilePropertyBag.java new file mode 100644 index 000000000..43721a4e5 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/file/FilePropertyBag.java @@ -0,0 +1,48 @@ +/* + * Copyright 2024 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.file; + +import org.teavm.jso.JSClass; +import org.teavm.jso.JSProperty; +import org.teavm.jso.core.JSObjects; + +@JSClass(transparent = true) +public class FilePropertyBag extends BlobPropertyBag { + FilePropertyBag() { + } + + public static FilePropertyBag create() { + return JSObjects.create(); + } + + @Override + public FilePropertyBag type(String type) { + return (FilePropertyBag) super.type(type); + } + + @Override + public FilePropertyBag endingType(String endingType) { + return (FilePropertyBag) super.endingType(endingType); + } + + public FilePropertyBag lastModified(long lastModified) { + setLastModified(lastModified); + return this; + } + + @JSProperty + private native void setLastModified(double lastModified); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStream.java b/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStream.java new file mode 100644 index 000000000..8ff123f44 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStream.java @@ -0,0 +1,42 @@ +/* + * Copyright 2024 ihromant. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.streams; + +import org.teavm.jso.JSClass; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; +import org.teavm.jso.core.JSArrayReader; +import org.teavm.jso.core.JSPromise; +import org.teavm.jso.core.JSUndefined; + +@JSClass +public class ReadableStream implements JSObject { + private ReadableStream() { + } + + @JSProperty + public native boolean isLocked(); + + public native JSPromise abort(String reason); + + public native JSPromise cancel(); + + public native JSPromise cancel(String reason); + + public native JSArrayReader tee(); + + public native ReadableStreamDefaultReader getReader(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStreamDefaultReader.java b/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStreamDefaultReader.java new file mode 100644 index 000000000..93f4fd393 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStreamDefaultReader.java @@ -0,0 +1,37 @@ +/* + * Copyright 2024 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.streams; + +import org.teavm.jso.JSClass; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; +import org.teavm.jso.core.JSPromise; +import org.teavm.jso.core.JSUndefined; + +@JSClass +public class ReadableStreamDefaultReader implements JSObject { + private ReadableStreamDefaultReader() { + } + + @JSProperty + public native JSPromise getClosed(); + + public native JSPromise cancel(JSObject reason); + + public native JSPromise read(); + + public native void releaseLock(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStreamReadResult.java b/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStreamReadResult.java new file mode 100644 index 000000000..cb28bfdf6 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/streams/ReadableStreamReadResult.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.streams; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; +import org.teavm.jso.typedarrays.Int8Array; + +public interface ReadableStreamReadResult extends JSObject { + @JSProperty + Int8Array getValue(); + + @JSProperty + boolean isDone(); +}