@deepnote/blocks 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # @deepnote/blocks
2
+
3
+ The blocks package defines the Deepnote Blocks.
4
+
5
+ ## Overview
6
+
7
+ This package provides TypeScript types and utilities for working with Deepnote notebook blocks, including:
8
+
9
+ - **Block Types**: Code, SQL, Text, Markdown, Input, Visualization, Button, Big Number, Image, Separator
10
+ - **Python Code Generation**: Convert blocks to executable Python code
11
+ - **Markdown Conversion**: Convert text blocks to/from markdown format
12
+
13
+ ## Supported Block Types
14
+
15
+ ### Code & Data Blocks
16
+
17
+ - **code**: Python code execution
18
+ - **sql**: SQL query execution with variable assignment
19
+
20
+ ### Input Blocks
21
+
22
+ - **input-text**: Single-line text input
23
+ - **input-textarea**: Multi-line text input
24
+ - **input-checkbox**: Boolean checkbox
25
+ - **input-select**: Single or multi-select dropdown
26
+ - **input-slider**: Numeric slider
27
+ - **input-file**: File path selector
28
+ - **input-date**: Date picker
29
+ - **input-date-range**: Date range with presets (past 7 days, past month, etc.)
30
+
31
+ ### Display Blocks
32
+
33
+ - **visualization**: Interactive charts using Vega-Lite
34
+ - **big-number**: KPI display with Jinja2 templates
35
+ - **button**: Interactive button with variable control
36
+
37
+ ### Text & Markdown Blocks
38
+
39
+ - **text-cell-h1/h2/h3**: Headings
40
+ - **text-cell-p**: Paragraphs
41
+ - **text-cell-bullet**: Bullet lists
42
+ - **text-cell-todo**: Checkboxes
43
+ - **text-cell-callout**: Highlighted notes
44
+ - **separator**: Horizontal rule (`<hr>`)
45
+ - **image**: Embedded images with alignment and sizing
46
+
47
+ ## Usage
48
+
49
+ ### Python Code Generation
50
+
51
+ ```typescript
52
+ import { createPythonCode } from "@deepnote/blocks";
53
+
54
+ // Code block
55
+ const codeBlock = {
56
+ type: "code",
57
+ content: 'print("Hello, world!")',
58
+ // ...
59
+ };
60
+ createPythonCode(codeBlock); // 'print("Hello, world!")'
61
+
62
+ // SQL block
63
+ const sqlBlock = {
64
+ type: "sql",
65
+ content: "SELECT * FROM users",
66
+ metadata: {
67
+ deepnote_variable_name: "df_users",
68
+ sql_integration_id: "abc-123",
69
+ },
70
+ // ...
71
+ };
72
+ createPythonCode(sqlBlock);
73
+ // df_users = _dntk.execute_sql('SELECT * FROM users', 'SQL_ABC_123', ...)
74
+
75
+ // Input checkbox
76
+ const checkboxBlock = {
77
+ type: "input-checkbox",
78
+ metadata: {
79
+ deepnote_variable_name: "is_enabled",
80
+ deepnote_variable_value: true,
81
+ },
82
+ // ...
83
+ };
84
+ createPythonCode(checkboxBlock); // is_enabled = True
85
+
86
+ // Input date range
87
+ const dateRangeBlock = {
88
+ type: "input-date-range",
89
+ metadata: {
90
+ deepnote_variable_name: "date_range",
91
+ deepnote_variable_value: "past7days",
92
+ },
93
+ // ...
94
+ };
95
+ createPythonCode(dateRangeBlock);
96
+ // from datetime import datetime as _deepnote_datetime, timedelta as _deepnote_timedelta
97
+ // date_range = [_deepnote_datetime.now().date() - _deepnote_timedelta(days=7), ...]
98
+ ```
99
+
100
+ ### Markdown Conversion
101
+
102
+ ```typescript
103
+ import { createMarkdown, stripMarkdown } from "@deepnote/blocks";
104
+
105
+ const headingBlock = {
106
+ type: "text-cell-h1",
107
+ content: "Main Title",
108
+ // ...
109
+ };
110
+
111
+ const markdown = createMarkdown(headingBlock); // "# Main Title"
112
+ const plainText = stripMarkdown(headingBlock); // "Main Title"
113
+
114
+ const todoBlock = {
115
+ type: "text-cell-todo",
116
+ content: "Complete task",
117
+ metadata: { checked: true },
118
+ // ...
119
+ };
120
+
121
+ createMarkdown(todoBlock); // "- [x] Complete task"
122
+
123
+ const separatorBlock = {
124
+ type: "separator",
125
+ content: "",
126
+ // ...
127
+ };
128
+
129
+ createMarkdown(separatorBlock); // "<hr>"
130
+
131
+ const imageBlock = {
132
+ type: "image",
133
+ content: "",
134
+ metadata: {
135
+ deepnote_img_src: "https://example.com/image.png",
136
+ deepnote_img_width: "500",
137
+ deepnote_img_alignment: "center",
138
+ },
139
+ // ...
140
+ };
141
+
142
+ createMarkdown(imageBlock); // '<img src="https://example.com/image.png" width="500" align="center" />'
143
+ ```