documents.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. .. _documents:
  2. Documents
  3. ---------
  4. JupyterLab can be extended in two ways via:
  5. - Extensions (top level): Application extensions extend the
  6. functionality of JupyterLab itself, and we cover them in the
  7. :ref:`developer_extensions`.
  8. - **Document widget extensions (lower level):** Document widget
  9. extensions extend the functionality of document widgets added to the
  10. application, and we cover them in this section.
  11. For this section, the term 'document' refers to any visual thing that
  12. is backed by a file stored on disk (i.e. uses Contents API).
  13. The `Document
  14. Registry <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html>`__
  15. is where document types and factories are registered. Plugins can
  16. require a document registry instance and register their content types
  17. and providers.
  18. The `Document
  19. Manager <http://jupyterlab.github.io/jupyterlab/classes/_docmanager_src_manager_.documentmanager.html>`__
  20. uses the Document Registry to create models and widgets for documents.
  21. The Document Manager is only meant to be accessed by the File Browser
  22. itself.
  23. Document Registry
  24. ~~~~~~~~~~~~~~~~~
  25. *Document widget extensions* in the JupyterLab application can register:
  26. - widget factories
  27. - model factories
  28. - widget extension factories
  29. - file types
  30. - file creators
  31. `Widget Factories <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addwidgetfactory>`__
  32. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  33. Create a widget for a given file.
  34. *Example*
  35. - The notebook widget factory that creates NotebookPanel widgets.
  36. `Model Factories <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addmodelfactory>`__
  37. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  38. Create a model for a given file.
  39. Models are generally differentiated by the contents options used to
  40. fetch the model (e.g. text, base64, notebook).
  41. `Widget Extension Factories <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addwidgetextension>`__
  42. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  43. Adds additional functionality to a widget type. An extension instance is
  44. created for each widget instance, enabling the extension to add
  45. functionality to each widget or observe the widget and/or its context.
  46. *Examples*
  47. - The ipywidgets extension that is created for NotebookPanel widgets.
  48. - Adding a button to the toolbar of each NotebookPanel widget.
  49. `File Types <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addfiletype>`__
  50. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  51. Intended to be used in a "Create New" dialog, providing a list of known
  52. file types.
  53. `File Creators <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html>`__
  54. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  55. Intended for create quick launch file creators.
  56. The default use will be for the "create new" dropdown in the file
  57. browser, giving list of items that can be created with default options
  58. (e.g. "Python 3 Notebook").
  59. `Document Models <http://jupyterlab.github.io/jupyterlab/interfaces/_docregistry_src_registry_.documentregistry.imodel.html>`__
  60. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  61. Created by the model factories and passed to widget factories and widget
  62. extension factories. Models are the way in which we interact with the
  63. data of a document. For a simple text file, we typically only use the
  64. ``to/fromString()`` methods. A more complex document like a Notebook
  65. contains more points of interaction like the Notebook metadata.
  66. `Document Contexts <http://jupyterlab.github.io/jupyterlab/interfaces/_docregistry_src_registry_.documentregistry.icontext.html>`__
  67. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  68. Created by the Document Manager and passed to widget factories and
  69. widget extensions. The context contains the model as one of its
  70. properties so that we can pass a single object around.
  71. They are used to provide an abstracted interface to the session and
  72. contents API from ``@jupyterlab/services`` for the given model. They can
  73. be shared between widgets.
  74. The reason for a separate context and model is so that it is easy to
  75. create model factories and the heavy lifting of the context is left to
  76. the Document Manager. Contexts are not meant to be subclassed or
  77. re-implemented. Instead, the contexts are intended to be the glue
  78. between the document model and the wider application.
  79. Document Manager
  80. ~~~~~~~~~~~~~~~~
  81. The *Document Manager* handles:
  82. - document models
  83. - document contexts
  84. The *File Browser* uses the *Document Manager* to open documents and
  85. manage them.