Deprecate kotlin.browser and kotlin.dom packages and provide
replacements in packages kotlinx.dom and kotlinx.browser KT-39330 Fixed
This commit is contained in:
@@ -6,12 +6,33 @@
|
||||
package kotlin.browser
|
||||
|
||||
import org.w3c.dom.*
|
||||
import kotlin.internal.LowPriorityInOverloadResolution
|
||||
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.browser.window' instead.",
|
||||
replaceWith = ReplaceWith("window", "kotlinx.browser.window")
|
||||
)
|
||||
@LowPriorityInOverloadResolution
|
||||
public external val window: Window
|
||||
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.browser.document' instead.",
|
||||
replaceWith = ReplaceWith("document", "kotlinx.browser.document")
|
||||
)
|
||||
@LowPriorityInOverloadResolution
|
||||
public external val document: Document
|
||||
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.browser.localStorage' instead.",
|
||||
replaceWith = ReplaceWith("localStorage", "kotlinx.browser.localStorage")
|
||||
)
|
||||
@LowPriorityInOverloadResolution
|
||||
public external val localStorage: Storage
|
||||
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.browser.sessionStorage' instead.",
|
||||
replaceWith = ReplaceWith("sessionStorage", "kotlinx.browser.sessionStorage")
|
||||
)
|
||||
@LowPriorityInOverloadResolution
|
||||
public external val sessionStorage: Storage
|
||||
|
||||
|
||||
@@ -5,20 +5,33 @@
|
||||
|
||||
package kotlin.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Element
|
||||
import kotlin.internal.LowPriorityInOverloadResolution
|
||||
import kotlinx.dom.appendElement as newAppendElement
|
||||
import kotlinx.dom.createElement as newCreateElement
|
||||
|
||||
/**
|
||||
* Creates a new element with the specified [name].
|
||||
*
|
||||
* The element is initialized with the speicifed [init] function.
|
||||
*/
|
||||
public fun Document.createElement(name: String, init: Element.() -> Unit): Element = createElement(name).apply(init)
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.createElement' instead.",
|
||||
replaceWith = ReplaceWith("this.createElement(name, init)", "kotlinx.dom.createElement")
|
||||
)
|
||||
public inline fun Document.createElement(name: String, noinline init: Element.() -> Unit): Element = this.newCreateElement(name, init)
|
||||
|
||||
/**
|
||||
* Appends a newly created element with the specified [name] to this element.
|
||||
*
|
||||
* The element is initialized with the speicifed [init] function.
|
||||
*/
|
||||
public fun Element.appendElement(name: String, init: Element.() -> Unit): Element =
|
||||
ownerDocument!!.createElement(name, init).also { appendChild(it) }
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.appendElement' instead.",
|
||||
replaceWith = ReplaceWith("this.appendElement(name, init)", "kotlinx.dom.appendElement")
|
||||
)
|
||||
public inline fun Element.appendElement(name: String, noinline init: Element.() -> Unit): Element = this.newAppendElement(name, init)
|
||||
|
||||
|
||||
@@ -5,44 +5,40 @@
|
||||
|
||||
package kotlin.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.Element
|
||||
import kotlin.internal.LowPriorityInOverloadResolution
|
||||
import kotlinx.dom.addClass as newAddClass
|
||||
import kotlinx.dom.hasClass as newHasClass
|
||||
import kotlinx.dom.removeClass as newRemoveClass
|
||||
|
||||
/** Returns true if the element has the given CSS class style in its 'class' attribute */
|
||||
fun Element.hasClass(cssClass: String): Boolean = className.matches("""(^|.*\s+)$cssClass($|\s+.*)""".toRegex())
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.hasClass' instead.",
|
||||
replaceWith = ReplaceWith("this.hasClass(cssClass)", "kotlinx.dom.hasClass")
|
||||
)
|
||||
inline fun Element.hasClass(cssClass: String): Boolean = this.newHasClass(cssClass)
|
||||
|
||||
/**
|
||||
* Adds CSS class to element. Has no effect if all specified classes are already in class attribute of the element
|
||||
*
|
||||
* @return true if at least one class has been added
|
||||
*/
|
||||
fun Element.addClass(vararg cssClasses: String): Boolean {
|
||||
val missingClasses = cssClasses.filterNot { hasClass(it) }
|
||||
if (missingClasses.isNotEmpty()) {
|
||||
val presentClasses = className.trim()
|
||||
className = buildString {
|
||||
append(presentClasses)
|
||||
if (!presentClasses.isEmpty()) {
|
||||
append(" ")
|
||||
}
|
||||
missingClasses.joinTo(this, " ")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.addClass' instead.",
|
||||
replaceWith = ReplaceWith("this.addClass(cssClasses)", "kotlinx.dom.addClass")
|
||||
)
|
||||
inline fun Element.addClass(vararg cssClasses: String): Boolean = this.newAddClass(*cssClasses)
|
||||
|
||||
/**
|
||||
* Removes all [cssClasses] from element. Has no effect if all specified classes are missing in class attribute of the element
|
||||
*
|
||||
* @return true if at least one class has been removed
|
||||
*/
|
||||
fun Element.removeClass(vararg cssClasses: String): Boolean {
|
||||
if (cssClasses.any { hasClass(it) }) {
|
||||
val toBeRemoved = cssClasses.toSet()
|
||||
className = className.trim().split("\\s+".toRegex()).filter { it !in toBeRemoved }.joinToString(" ")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.removeClass' instead.",
|
||||
replaceWith = ReplaceWith("this.removeClass(cssClasses)", "kotlinx.dom.removeClass")
|
||||
)
|
||||
inline fun Element.removeClass(vararg cssClasses: String): Boolean = this.newRemoveClass(*cssClasses)
|
||||
@@ -5,16 +5,30 @@
|
||||
|
||||
package kotlin.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.Node
|
||||
import kotlin.internal.LowPriorityInOverloadResolution
|
||||
import kotlinx.dom.isElement as newIsElement
|
||||
import kotlinx.dom.isText as newIsText
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether this node is a TEXT_NODE or a CDATA_SECTION_NODE.
|
||||
*/
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.isText' instead.",
|
||||
replaceWith = ReplaceWith("this.isText", "kotlinx.dom.isText")
|
||||
)
|
||||
public val Node.isText: Boolean
|
||||
get() = nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE
|
||||
inline get() = this.newIsText
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether this node is an [Element].
|
||||
*/
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.isElement' instead.",
|
||||
replaceWith = ReplaceWith("this.isElement", "kotlinx.dom.isElement")
|
||||
)
|
||||
public val Node.isElement: Boolean
|
||||
get() = nodeType == Node.ELEMENT_NODE
|
||||
inline get() = this.newIsElement
|
||||
|
||||
@@ -5,21 +5,28 @@
|
||||
|
||||
package kotlin.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.Node
|
||||
import kotlin.internal.LowPriorityInOverloadResolution
|
||||
import kotlinx.dom.appendText as newAppendText
|
||||
import kotlinx.dom.clear as newClear
|
||||
|
||||
/** Removes all the children from this node. */
|
||||
public fun Node.clear() {
|
||||
while (hasChildNodes()) {
|
||||
removeChild(firstChild!!)
|
||||
}
|
||||
}
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.clear' instead.",
|
||||
replaceWith = ReplaceWith("this.clear()", "kotlinx.dom.clear")
|
||||
)
|
||||
public inline fun Node.clear() = this.newClear()
|
||||
|
||||
/**
|
||||
* Creates text node and append it to the element.
|
||||
*
|
||||
* @return this element
|
||||
*/
|
||||
fun Element.appendText(text: String): Element {
|
||||
appendChild(ownerDocument!!.createTextNode(text))
|
||||
return this
|
||||
}
|
||||
@LowPriorityInOverloadResolution
|
||||
@Deprecated(
|
||||
message = "This API is moved to another package, use 'kotlinx.dom.appendText' instead.",
|
||||
replaceWith = ReplaceWith("this.appendText(text)", "kotlinx.dom.appendText")
|
||||
)
|
||||
inline fun Element.appendText(text: String): Element = this.newAppendText(text)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.browser
|
||||
|
||||
import org.w3c.dom.*
|
||||
|
||||
public external val window: Window
|
||||
|
||||
public external val document: Document
|
||||
|
||||
public external val localStorage: Storage
|
||||
|
||||
public external val sessionStorage: Storage
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
|
||||
/**
|
||||
* Creates a new element with the specified [name].
|
||||
*
|
||||
* The element is initialized with the speicifed [init] function.
|
||||
*/
|
||||
public fun Document.createElement(name: String, init: Element.() -> Unit): Element = createElement(name).apply(init)
|
||||
|
||||
/**
|
||||
* Appends a newly created element with the specified [name] to this element.
|
||||
*
|
||||
* The element is initialized with the speicifed [init] function.
|
||||
*/
|
||||
public fun Element.appendElement(name: String, init: Element.() -> Unit): Element =
|
||||
ownerDocument!!.createElement(name, init).also { appendChild(it) }
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
|
||||
/** Returns true if the element has the given CSS class style in its 'class' attribute */
|
||||
fun Element.hasClass(cssClass: String): Boolean = className.matches("""(^|.*\s+)$cssClass($|\s+.*)""".toRegex())
|
||||
|
||||
/**
|
||||
* Adds CSS class to element. Has no effect if all specified classes are already in class attribute of the element
|
||||
*
|
||||
* @return true if at least one class has been added
|
||||
*/
|
||||
fun Element.addClass(vararg cssClasses: String): Boolean {
|
||||
val missingClasses = cssClasses.filterNot { hasClass(it) }
|
||||
if (missingClasses.isNotEmpty()) {
|
||||
val presentClasses = className.trim()
|
||||
className = buildString {
|
||||
append(presentClasses)
|
||||
if (!presentClasses.isEmpty()) {
|
||||
append(" ")
|
||||
}
|
||||
missingClasses.joinTo(this, " ")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all [cssClasses] from element. Has no effect if all specified classes are missing in class attribute of the element
|
||||
*
|
||||
* @return true if at least one class has been removed
|
||||
*/
|
||||
fun Element.removeClass(vararg cssClasses: String): Boolean {
|
||||
if (cssClasses.any { hasClass(it) }) {
|
||||
val toBeRemoved = cssClasses.toSet()
|
||||
className = className.trim().split("\\s+".toRegex()).filter { it !in toBeRemoved }.joinToString(" ")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether this node is a TEXT_NODE or a CDATA_SECTION_NODE.
|
||||
*/
|
||||
public val Node.isText: Boolean
|
||||
get() = nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether this node is an [Element].
|
||||
*/
|
||||
public val Node.isElement: Boolean
|
||||
get() = nodeType == Node.ELEMENT_NODE
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.dom
|
||||
|
||||
import org.w3c.dom.*
|
||||
|
||||
/** Removes all the children from this node. */
|
||||
public fun Node.clear() {
|
||||
while (hasChildNodes()) {
|
||||
removeChild(firstChild!!)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates text node and append it to the element.
|
||||
*
|
||||
* @return this element
|
||||
*/
|
||||
fun Element.appendText(text: String): Element {
|
||||
appendChild(ownerDocument!!.createTextNode(text))
|
||||
return this
|
||||
}
|
||||
Reference in New Issue
Block a user