0
# Data Models
1
2
Core interfaces for handling MIME data, metadata, and toolbar components within the JupyterLab rendering system.
3
4
## Capabilities
5
6
### IMimeModel Interface
7
8
Represents a model for MIME data that can be rendered by MIME renderers. Contains the actual data, metadata, and trust information.
9
10
```typescript { .api }
11
/**
12
* A model for mime data containing trusted data, metadata, and data modification capabilities
13
*/
14
interface IMimeModel {
15
/** Whether the data in the model is trusted */
16
readonly trusted: boolean;
17
/** The data associated with the model */
18
readonly data: ReadonlyPartialJSONObject;
19
/**
20
* The metadata associated with the model.
21
* Among others, it can include an attribute named `fragment`
22
* that stores a URI fragment identifier for the MIME resource.
23
*/
24
readonly metadata: ReadonlyPartialJSONObject;
25
/**
26
* Set the data associated with the model.
27
* Calling this function may trigger an asynchronous operation
28
* that could cause the renderer to be rendered with a new model
29
* containing the new data.
30
*/
31
setData(options: IMimeModel.ISetDataOptions): void;
32
}
33
```
34
35
**Usage Example:**
36
37
```typescript
38
import { IRenderMime } from "@jupyterlab/rendermime-interfaces";
39
40
// Implementing a custom mime model
41
class MyMimeModel implements IRenderMime.IMimeModel {
42
constructor(
43
private _trusted: boolean,
44
private _data: ReadonlyPartialJSONObject,
45
private _metadata: ReadonlyPartialJSONObject = {}
46
) {}
47
48
get trusted(): boolean {
49
return this._trusted;
50
}
51
52
get data(): ReadonlyPartialJSONObject {
53
return this._data;
54
}
55
56
get metadata(): ReadonlyPartialJSONObject {
57
return this._metadata;
58
}
59
60
setData(options: IRenderMime.IMimeModel.ISetDataOptions): void {
61
if (options.data !== undefined) {
62
this._data = options.data;
63
}
64
if (options.metadata !== undefined) {
65
this._metadata = options.metadata;
66
}
67
// Trigger re-rendering logic here
68
}
69
}
70
```
71
72
### IMimeModel.ISetDataOptions Interface
73
74
Options for updating the data and metadata in a MIME model.
75
76
```typescript { .api }
77
/**
78
* The options used to update a mime model
79
*/
80
interface ISetDataOptions {
81
/** The new data object */
82
data?: ReadonlyPartialJSONObject;
83
/** The new metadata object */
84
metadata?: ReadonlyPartialJSONObject;
85
}
86
```
87
88
### IToolbarItem Interface
89
90
Represents a toolbar item that can be displayed in a renderer's toolbar.
91
92
```typescript { .api }
93
/**
94
* A toolbar item with a unique name and associated widget
95
*/
96
interface IToolbarItem {
97
/** Unique item name */
98
name: string;
99
/** Toolbar widget */
100
widget: Widget;
101
}
102
```
103
104
**Usage Example:**
105
106
```typescript
107
import { IRenderMime } from "@jupyterlab/rendermime-interfaces";
108
import { Widget } from "@lumino/widgets";
109
110
// Creating toolbar items
111
function createToolbarItems(): IRenderMime.IToolbarItem[] {
112
const button = new Widget();
113
button.node.innerHTML = '<button>Custom Action</button>';
114
115
return [
116
{
117
name: "custom-action",
118
widget: button
119
}
120
];
121
}
122
123
// Using in document widget factory options
124
const factoryOptions: IRenderMime.IDocumentWidgetFactoryOptions = {
125
name: "My Renderer",
126
primaryFileType: "my-format",
127
fileTypes: ["my-format"],
128
toolbarFactory: () => createToolbarItems()
129
};
130
```
131
132
## Types
133
134
### External Dependencies
135
136
These interfaces depend on types from external packages. See the main documentation for complete type definitions.