import * as commutable from "@nteract/commutable" ; import * as Immutable from "immutable" ; import { CellId , ImmutableCell } from "@nteract/commutable" ; import { NotebookModel } from "@nteract/types" ; import { createSelector } from "reselect" ; param model returns export const cellMap = ( model ) => model . notebook . get ( "cellMap" , Immutable . Map < CellId , ImmutableCell > ( ) ) ; param model param { id returns export const cellById = ( model , { id } ) => cellMap ( model ) . get ( id ) ; param model returns export const cellOrder = ( model ) : Immutable . List < CellId > => model . notebook . get ( "cellOrder" , Immutable . List < CellId > ( ) ) ; param model returns export const cellFocused = ( model ) : CellId | null | undefined => model . cellFocused ; param model returns export const editorFocusedId = ( model ) : CellId | null | undefined => model . editorFocused ; param model param cellId returns export const codeCellIdsAbove = ( model , cellId = model . cellFocused ) : Immutable . List < CellId > => { if ( ! cellId ) { return Immutable . List < CellId > ( ) ; } const cellOrder = model . notebook . get ( "cellOrder" , Immutable . List < CellId > ( ) ) ; const index = cellOrder . indexOf ( cellId ) ; return cellOrder . take ( index ) . filter ( ( id ) => model . notebook . getIn ( [ "cellMap" , id , "cell_type" ] ) === "code" ) ; } ; param model param cellId returns export const codeCellIdsBelow = ( model , cellId = model . cellFocused ) : Immutable . List < CellId > => { if ( ! cellId ) { return Immutable . List < CellId > ( ) ; } const cellOrder = model . notebook . get ( "cellOrder" , Immutable . List < CellId > ( ) ) ; const index = cellOrder . indexOf ( cellId ) ; return cellOrder . skip ( index ) . filter ( ( id ) => model . notebook . getIn ( [ "cellMap" , id , "cell_type" ] ) === "code" ) ; } ; /**
 * Returns the CellIds of the hidden cells in a notebook.
 */ export const hiddenCellIds = ( model ) => model . notebook . cellOrder . filter ( id => model . notebook . cellMap . getIn ( [ id , "metadata" , "jupyter" , "source_hidden" ] ) ) ; /**
 * Returns the CellIds of the cells with hidden outputs in the
 * notebook.
 */ export const idsOfHiddenOutputs = ( model ) => model . notebook . cellOrder . filter ( id => model . notebook . cellMap . getIn ( [ id , "metadata" , "jupyter" , "outputs_hidden" ] ) ) ; param model returns export const transientCellMap = ( model ) => model . transient . get ( "cellMap" , Immutable . Map ( ) ) ; export const cellPromptsById = ( model , { id } ) => model . cellPrompts . get ( id , Immutable . List ( ) ) ; /**
 * Returns the CellIds of the code cells within a notebook.
 */ export const codeCellIds = ( model ) => model . notebook . cellOrder . filter ( id => model . notebook . cellMap . getIn ( [ id , "cell_type" ] ) === "code" ) ; param model returns export const metadata = ( model ) => model . notebook . get ( "metadata" , Immutable . Map ( ) ) ; /**
 * Returns the GitHub username the user has authenticated through.
 */ export const githubUsername = createSelector ( metadata , metadata => metadata . get ( "github_username" , null ) ) ; /**
 * Returns the ID of the GitHub Gist the notebook has been recently published
 * to.
 */ export const gistId = createSelector ( metadata , metadata => metadata . get ( "gist_id" , null ) ) ; export const notebook = ( model ) => model . notebook ; export const savedNotebook = ( model ) => model . savedNotebook ; /**
 * Returns true if the notebook differs from the version saved to disk, and
 * false otherwise.
 */ export const isDirty = createSelector ( [ notebook , savedNotebook ] , ( original , disk ) => ! Immutable . is ( original , disk ) ) ; /**
 * Returns the JSON representation of the notebook.
 */ export const asJSON = createSelector ( notebook , notebook => { return commutable . toJS ( notebook ) ; } ) ; /**
 * Returns the stringified version of a notebook. Returns an empty string
 * if no notebookJS exists. Note that this is called asString instead of
 * toString so that REPLs don't think of this as the representation of this
 * module.
 */ export const asString = createSelector ( asJSON , notebookJS => { if ( notebookJS ) { return commutable . stringifyNotebook ( notebookJS ) ; } return "" ; } ) ; const CODE_MIRROR_MODE_DEFAULT = "text" ; /**
 * Returns the CodeMirror mode of the current notebook. This value can be used
 * to initialize the `mode` option in CodeMirror. Returns `text` if no mode
 * is set.
 */ export const codeMirrorMode = createSelector ( metadata , metadata => metadata . getIn ( [ "language_info" , "codemirror_mode" ] ) || metadata . getIn ( [ "kernel_info" , "language" ] ) || metadata . getIn ( [ "kernelspec" , "language" ] ) || CODE_MIRROR_MODE_DEFAULT ) ; /**
 * Returns the display name of the kernel the notebook is currently
 * running against.
 */ export const displayName = createSelector ( metadata , metadata => metadata . getIn ( [ "kernelspec" , "display_name" ] , "" ) ) ;