Releases: nalgeon/codapi-js
0.10.2
0.10.1
0.10.0
Code cells
Now you can create code cells — snippets that depend on each other. To do this, use a depends-on
attribute that points to the other snippet ID. This results in Jupyter notebook-like behavior and eliminates the need for code duplication.
For example, here are the thee snippets (create
, insert
and select
), where each depends on the previous one:
➀ Create:
```sql
create table employees (
id integer primary key,
name varchar(50),
department varchar(10),
salary integer
);
```
<codapi-snippet id="create.sql" sandbox="postgres" editor="basic">
</codapi-snippet>
➁ Insert:
```sql
insert into employees
(id, name, department, salary)
values
(11, 'Diane', 'hr', 70),
(12, 'Bob', 'hr', 78),
(21, 'Emma', 'it', 84);
```
<codapi-snippet id="insert.sql" sandbox="postgres" editor="basic" depends-on="create.sql">
</codapi-snippet>
➂ Select:
```sql
select * from employees;
```
<codapi-snippet id="select.sql" sandbox="postgres" editor="basic" depends-on="insert.sql">
</codapi-snippet>
This is how the snippets work:
- When you run the
insert
snippet, it automatically creates the table before inserting the data. - When you run the
select
snippet, it automatically creates the table and inserts the records before selecting the data.
The dependencies do not have to be linear, they can form any (acyclic) graph. For example:
create ← insert-1 ← select
↖ insert-2 ↙
0.9.2
0.9.1
0.9.0
0.8.0
Changed the "Sample output" logic introduced in 0.5.0.
Fallback output
Now you can define the default code output (e.g. what happens if the reader clicks Run without changing the code). The widget will show this output if the Codapi server is down.
The default output will also be displayed in the RSS feed, which can be useful for readers who consume content through an RSS reader without ever visiting the actual page.
To use the fallback output, add an output
attribute to the codapi-snippet
and add an element with a default output after the snippet:
<pre>msg = "hello world"
print(msg)</pre>
<codapi-snippet sandbox="python" editor="basic" output>
</codapi-snippet>
<pre>hello world</pre>
0.7.2
0.7.1
0.7.0
Snippet initialization changes:
- Non-standard
@prev
selector. For example,selector
=@prev .code
selects an element of classcode
within the previous sibling element. - Optional
init-delay
attribute. Delays snippet initialization by a specified number of milliseconds.⚠️ This is an experimental feature that may be removed in future releases. - Snippet
load
event. Fires when the snippet completes its initialization.