diff --git a/js/js.libraries/src/dom/Builder.kt b/js/js.libraries/src/dom/Builder.kt deleted file mode 100644 index b7342b4dd21..00000000000 --- a/js/js.libraries/src/dom/Builder.kt +++ /dev/null @@ -1,31 +0,0 @@ -package kotlin.dom.build - -import org.w3c.dom.* -import kotlin.dom.* - -/** - * Creates a new element which can be configured via a function - */ -@Deprecated("Moved to kotlin.dom package", ReplaceWith("createElement(name, init)", "kotlin.dom.createElement"), level = DeprecationLevel.ERROR) -public fun Document.createElement(name: String, init: Element.() -> Unit): Element = createElement(name).apply(init) - -/** - * Creates a new element to an element which has an owner Document which can be configured via a function - */ -@Deprecated("Use Document.createElement instead", level = DeprecationLevel.ERROR) -fun Element.createElement(name: String, doc: Document? = null, init: Element.() -> Unit): Element = ownerDocument!!.createElement(name).apply(init) - -/** - * Adds a newly created element which can be configured via a function - */ -@Deprecated("Use Element.appendElement instead.", level = DeprecationLevel.ERROR) -fun Document.addElement(name: String, init: Element.() -> Unit): Element { - val child = createElement(name).apply(init) - this.appendChild(child) - return child -} - -@Deprecated("Use Element.appendElement instead", ReplaceWith("appendElement(name, init)", "kotlin.dom.appendElement"), level = DeprecationLevel.ERROR) -fun Element.addElement(name: String, doc: Document? = null, init: Element.() -> Unit): Element = appendElement(name, init) - - diff --git a/js/js.libraries/src/dom/Dom.kt b/js/js.libraries/src/dom/Dom.kt index 34995260063..c66783e4eba 100644 --- a/js/js.libraries/src/dom/Dom.kt +++ b/js/js.libraries/src/dom/Dom.kt @@ -13,133 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@file:Suppress("DEPRECATION_ERROR") package kotlin.dom import org.w3c.dom.* import kotlin.collections.* -// DEPRECATED in 1.1-RC, drop after 1.1 - -/** Returns the children of the element as a list */ -@Deprecated("Use childNodes() function with safe call", ReplaceWith("this?.childNodes()?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) -fun Element?.children(): List { - return this?.childNodes?.asList() ?: emptyList() -} - -/** Returns the child elements of this element */ -@Deprecated("Use childNodes() function with safe call and filter it after", level = DeprecationLevel.ERROR) -fun Element?.childElements(): List = this?.childNodes?.filterElements() ?: emptyList() - -/** Returns the child elements of this element with the given name. */ -@Deprecated("Use childNodes() function with safe call and filter it after", level = DeprecationLevel.ERROR) -fun Element?.childElements(name: String): List = this?.childNodes?.filterElements()?.filter { it.nodeName == name } ?: emptyList() - -/** Returns all the descendant elements given the local element name. */ -@Deprecated("Use getElementsByTagName() instead", ReplaceWith("getElementsByTagName(localName).asList()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) -fun Element.elements(localName: String = "*"): List { - return this.getElementsByTagName(localName).asList() -} - -/** Returns all the descendant elements given the local element name */ -@JsName("deprecated_document_elements") -@Deprecated("Use getElementsByTagName() function with safe call", ReplaceWith("this?.getElementsByTagName(localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) -fun Document?.elements(localName: String = "*"): List { - return this?.elements(localName).orEmpty() -} - -/** Returns all the descendant elements given the namespace URI and local element name. */ -@Deprecated("Use getElementsByTagNameNS() function instead", ReplaceWith("this?.getElementsByTagNameNS(namespaceUri, localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) -public fun Element.elements(namespaceUri: String, localName: String): List { - return this.getElementsByTagNameNS(namespaceUri, localName).asList() -} - -/** Returns all the descendant elements given the namespace URI and local element name */ -@Deprecated("Use getElementsByTagNameNS() function with safe call", ReplaceWith("this?.getElementsByTagNameNS(namespaceUri, localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) -fun Document?.elements(namespaceUri: String, localName: String): List { - return this?.getElementsByTagNameNS(namespaceUri, localName)?.asList() ?: emptyList() -} - -// END OF DEPRECATED - -/** - * Returns a view of this [NodeList] as a list of elements assuming that it contains only elements. - * - * An attempt to get an element with [List.get] indexed accessor of the returned list - * will result in [ClassCastException] being thrown if that node is not an element. - * - * If you want to get a snapshot filtered to contain elements only it's better to use [filterElements] function. - */ -@Deprecated("This API is going to be removed, use asList() as a close replacement instead.", ReplaceWith("asList() as List", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) -public fun NodeList.asElementList(): List = ElementListAsList(this) - -/** - * Returns a list containing only [Element] nodes. - */ -@Deprecated("Use filter function instead", ReplaceWith("filter { it.isElement } as List"), level = DeprecationLevel.ERROR) -public fun List.filterElements(): List { - @Suppress("UNCHECKED_CAST") - return filter { it.isElement } as List -} - -/** - * Returns a list containing only [Element] nodes. - */ -@Deprecated("Use filter function instead", ReplaceWith("asList().filter { it.isElement } as List", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) -public fun NodeList.filterElements(): List = asList().filterElements() - - - -private class ElementListAsList(private val nodeList: NodeList) : AbstractList() { - override fun get(index: Int): Element { - val node = nodeList.item(index) - if (node == null) { - throw IndexOutOfBoundsException("NodeList does not contain a node at index: " + index) - } else if (node.nodeType == Node.ELEMENT_NODE) { - return node as Element - } else { - throw ClassCastException("Node is not an Element as expected but is $node") - } - } - - override val size: Int get() = nodeList.length -} - -/** Returns an [Iterator] over the next siblings of this node. */ -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) -public fun Node.nextSiblings(): Iterable = NextSiblings(this) - -private class NextSiblings(private var node: Node) : Iterable { - override fun iterator(): Iterator = object : AbstractIterator() { - override fun computeNext(): Unit { - val nextValue = node.nextSibling - if (nextValue != null) { - setNext(nextValue) - node = nextValue - } else { - done() - } - } - } -} - -/** Returns an [Iterator] over the next siblings of this node. */ -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) -public fun Node.previousSiblings(): Iterable = PreviousSiblings(this) - -private class PreviousSiblings(private var node: Node) : Iterable { - override fun iterator(): Iterator = object : AbstractIterator() { - override fun computeNext(): Unit { - val nextValue = node.previousSibling - if (nextValue != null) { - setNext(nextValue) - node = nextValue - } else { - done() - } - } - } -} /** * Gets a value indicating whether this node is a TEXT_NODE or a CDATA_SECTION_NODE. diff --git a/js/js.libraries/src/dom/DomEvents.kt b/js/js.libraries/src/dom/DomEvents.kt deleted file mode 100644 index aed1abfcfad..00000000000 --- a/js/js.libraries/src/dom/DomEvents.kt +++ /dev/null @@ -1,73 +0,0 @@ -@file:Suppress("DEPRECATION_ERROR") -package kotlin.dom - -import org.w3c.dom.* -import org.w3c.dom.events.* - -/** - * Turns an event handler function into an [EventListener] - */ -@Deprecated("Use EventListener SAM-like constructor instead", ReplaceWith("EventListener(handler)", "org.w3c.dom.events.EventListener"), level = DeprecationLevel.ERROR) -public fun eventHandler(handler: (Event) -> Unit): EventListener = EventListener(handler) - -@Deprecated("Use EventListener SAM-like constructor instead", ReplaceWith("EventListener(handler)", "org.w3c.dom.events.EventListener"), level = DeprecationLevel.ERROR) -public fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener { - return eventHandler { e -> - if (e is MouseEvent) { - handler(e) - } - } -} - -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) -public interface Closeable { - public open fun close(): Unit -} - -/** - * Registers a handler on the named event - */ -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) -public fun Node.on(name: String, capture: Boolean, handler: (Event) -> Unit): Closeable? { - return on(name, capture, eventHandler(handler)) -} - -/** - * Registers an [EventListener] on the named event - */ -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) -public fun Node?.on(name: String, capture: Boolean, listener: EventListener): Closeable? { - // TODO: instanceof EventTarget is a very bad idea! - // TODO: nullable target is a very bad idea! - // TODO: receiver should be EventTarget - val target = this as? EventTarget - return if (target != null) { - target.addEventListener(name, listener, capture) - CloseableEventListener(target, listener, name, capture) - } else { - null - } -} - -private class CloseableEventListener( - private val target: EventTarget, - private val listener: EventListener, - private val name: String, - private val capture: Boolean -) : Closeable { - public override fun close() { - target.removeEventListener(name, listener, capture) - } - - public override fun toString(): String = "CloseableEventListener($target, $name)" -} - -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) -public fun Node?.onClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? { - return on("click", capture, mouseEventHandler(handler)) -} - -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) -public fun Node?.onDoubleClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? { - return on("dblclick", capture, mouseEventHandler(handler)) -} \ No newline at end of file diff --git a/js/js.libraries/src/dom/DomJS.kt b/js/js.libraries/src/dom/DomJS.kt deleted file mode 100644 index 3295cd4708f..00000000000 --- a/js/js.libraries/src/dom/DomJS.kt +++ /dev/null @@ -1,20 +0,0 @@ -package kotlin.dom - -import org.w3c.dom.* -import org.w3c.dom.DOMTokenList -import org.w3c.dom.HTMLCollection -import org.w3c.dom.HTMLElement - -/** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */ -@Deprecated("Use querySelectorAll instead", level = DeprecationLevel.ERROR) -@Suppress("DEPRECATION_ERROR") -operator fun Document?.get(selector: String): List { - return this?.querySelectorAll(selector)?.asList()?.filterElements() ?: emptyList() -} - -/** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */ -@Deprecated("Use querySelectorAll instead", level = DeprecationLevel.ERROR) -@Suppress("DEPRECATION_ERROR") -operator fun Element.get(selector: String): List { - return querySelectorAll(selector).asList().filterElements() -} diff --git a/js/js.libraries/src/dom/Mutations.kt b/js/js.libraries/src/dom/Mutations.kt index 275dfc543b5..0009bdeb6f4 100644 --- a/js/js.libraries/src/dom/Mutations.kt +++ b/js/js.libraries/src/dom/Mutations.kt @@ -9,36 +9,6 @@ public fun Node.clear() { } } -/** - * Removes this node from parent node. Does nothing if no parent node - */ -@Deprecated("Use parentNode?.removeChild(this) instead.", ReplaceWith("this.also { it.parentNode?.removeChild(it) }"), level = DeprecationLevel.ERROR) -public fun Node.removeFromParent() { - parentNode?.removeChild(this) -} - -@Deprecated("Use appendChild instead", ReplaceWith("appendChild(node)"), level = DeprecationLevel.ERROR) -operator fun Node.plus(child: Node): Node { - appendChild(child) - return this -} - -@Deprecated("Use appendText instead", ReplaceWith("appendText(text)"), level = DeprecationLevel.ERROR) -operator fun Element.plus(text: String): Element = appendText(text) - -@Deprecated("Use appendText instead", ReplaceWith("appendText(text)"), level = DeprecationLevel.ERROR) -operator fun Element.plusAssign(text: String): Unit { - appendText(text) -} - -/** Returns the owner document of the element or uses the provided document */ -@Deprecated("Use ownerDocument property instead", ReplaceWith("this.ownerDocument ?: doc ?: error(\"no ownerDocument\")"), level = DeprecationLevel.ERROR) -fun Node.ownerDocument(doc: Document? = null): Document = when { - nodeType == Node.DOCUMENT_NODE -> this as Document - else -> doc ?: ownerDocument ?: throw IllegalArgumentException("Neither node contains nor parameter doc provides an owner document for $this") -} - - /** * Creates text node and append it to the element. * @@ -48,11 +18,3 @@ fun Element.appendText(text: String): Element { appendChild(ownerDocument!!.createTextNode(text)) return this } - -/** - * Appends the node to the specified parent element - */ -@Deprecated("Use parent.appendChild instead", ReplaceWith("this.let(parent::appendChild)"), level = DeprecationLevel.ERROR) -fun Node.appendTo(parent: Element) { - parent.appendChild(this) -}