diff --git a/core/api/core.api b/core/api/core.api index 5643427743..09fbfbdc9c 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -6530,11 +6530,14 @@ public final class org/jetbrains/kotlinx/dataframe/jupyter/DefaultCellRenderer : } public final class org/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper { - public fun (Lorg/jetbrains/kotlinx/dataframe/DataFrame;)V + public fun (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Z)V + public synthetic fun (Lorg/jetbrains/kotlinx/dataframe/DataFrame;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Lorg/jetbrains/kotlinx/dataframe/DataFrame; - public final fun copy (Lorg/jetbrains/kotlinx/dataframe/DataFrame;)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper; - public static synthetic fun copy$default (Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;Lorg/jetbrains/kotlinx/dataframe/DataFrame;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper; + public final fun component2 ()Z + public final fun copy (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Z)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper; + public static synthetic fun copy$default (Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;Lorg/jetbrains/kotlinx/dataframe/DataFrame;ZILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper; public fun equals (Ljava/lang/Object;)Z + public final fun getAddHtml ()Z public final fun getValue ()Lorg/jetbrains/kotlinx/dataframe/DataFrame; public fun hashCode ()I public fun toString ()Ljava/lang/String; diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper.kt index 715d94a86a..47acac89b2 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper.kt @@ -5,6 +5,8 @@ import org.jetbrains.kotlinx.dataframe.annotations.RequiredByIntellijPlugin /** * Allows for disabling the rows limit when generating a DISPLAY output in Jupyter. + * Used in code that Kotlin Notebook sends to Jupyter Kernel / KotlinNotebookPluginUtils + * @param [addHtml] needed to avoid sending HTML in these internal requests, because they won't be displayed anyway, only JSON part of these payloads is used to update "live" state of the widget */ @RequiredByIntellijPlugin -public data class DisableRowsLimitWrapper(public val value: AnyFrame) +public data class DisableRowsLimitWrapper(public val value: AnyFrame, public val addHtml: Boolean = true) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt index 657b84e69c..172e734d5d 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/KotlinNotebookPluginUtils.kt @@ -63,7 +63,7 @@ public object KotlinNotebookPluginUtils { * It's used for example for dynamic pagination in Kotlin Notebook Plugin. */ public fun getRowsSubsetForRendering(df: AnyFrame, startIdx: Int, endIdx: Int): DisableRowsLimitWrapper = - DisableRowsLimitWrapper(df[startIdx.. JupyterHtmlRenderer.render( noinline getFooter: (T) -> String, crossinline modifyConfig: T.(DisplayConfiguration) -> DisplayConfiguration = { it }, applyRowsLimit: Boolean = true, ) = builder.renderWithHost { host, value -> + val addHtml = (value as? DisableRowsLimitWrapper)?.addHtml ?: true val contextRenderer = JupyterCellRenderer(this.notebook, host) val reifiedDisplayConfiguration = value.modifyConfig(display) val footer = getFooter(value) @@ -53,20 +52,22 @@ internal inline fun JupyterHtmlRenderer.render( df.rowsCount() } - val html = DataFrameHtmlData - .tableDefinitions( - includeJs = reifiedDisplayConfiguration.isolatedOutputs, - includeCss = true, - ).plus( - df.toHtml( - // is added later to make sure it's put outside of potential iFrames - configuration = reifiedDisplayConfiguration.copy(enableFallbackStaticTables = false), - cellRenderer = contextRenderer, - ) { footer }, - ).toJupyterHtmlData() + val html by lazy { + DataFrameHtmlData + .tableDefinitions( + includeJs = reifiedDisplayConfiguration.isolatedOutputs, + includeCss = true, + ).plus( + df.toHtml( + // is added later to make sure it's put outside of potential iFrames + configuration = reifiedDisplayConfiguration.copy(enableFallbackStaticTables = false), + cellRenderer = contextRenderer, + ) { footer }, + ).toJupyterHtmlData() + } // Generates a static version of the table which can be displayed in GitHub previews etc. - val staticHtml = df.toStaticHtml(reifiedDisplayConfiguration, DefaultCellRenderer).toJupyterHtmlData() + val staticHtml by lazy { df.toStaticHtml(reifiedDisplayConfiguration, DefaultCellRenderer).toJupyterHtmlData() } if (notebook.kernelVersion >= KotlinKernelVersion.from(MIN_KERNEL_VERSION_FOR_NEW_TABLES_UI)!!) { val ideBuildNumber = KotlinNotebookPluginUtils.getKotlinNotebookIDEBuildNumber() @@ -94,8 +95,13 @@ internal inline fun JupyterHtmlRenderer.render( ) } } - - notebook.renderAsIFrameAsNeeded(data = html, staticData = staticHtml, jsonEncodedDf = jsonEncodedDf) + if (!addHtml) { + mimeResult( + "application/kotlindataframe+json" to jsonEncodedDf, + ) + } else { + notebook.renderAsIFrameAsNeeded(data = html, staticData = staticHtml, jsonEncodedDf = jsonEncodedDf) + } } else { notebook.renderHtmlAsIFrameIfNeeded(data = html) }