Public
Edited
Jan 16, 2023
Insert cell
Insert cell
Insert cell
Insert cell
viewof workspace = createWorkSpace(Blockly, {
invalidation,
height: 300,
width: 300
// toolbox: await generateStandardToolbox(Blockly)
// theme
})
Insert cell
Insert cell
Insert cell
Blockly.JavaScript.workspaceToCode(workspace)
Insert cell
Insert cell
Insert cell
Blockly.defineBlocksWithJsonArray([
// Block for variable getter.
{
type: "variables_get",
message0: "%1",
args0: [
{
// Beginning of the field variable dropdown
type: "field_variable",
name: "VAR", // Static name of the field
variable: "%{BKY_VARIABLES_DEFAULT_NAME}" // Given at runtime
} // End of the field variable dropdown
],
output: null // Null means the return value can be of any type
},

// Block for variable setter.
{
type: "variables_set",
message0: "%{BKY_VARIABLES_SET}",
args0: [
{
type: "field_variable",
name: "VAR",
variable: "%{BKY_VARIABLES_DEFAULT_NAME}"
},
{
type: "input_value", // This expects an input of any type
name: "VALUE"
}
]
},
{
type: "prompt",
message0: "Generate starting with %1", // Shows up on the UI
args0: [
{
type: "input_value",
name: "prompt",
check: "String",
align: "TOP"
}
],
output: null // Null means the return value can be of any type
},
{
type: "extract_html",
message0: "Extract human-readable text from this HTML %1", // Shows up on the UI
args0: [
{
type: "input_value",
name: "extract_html",
check: "String",
align: "TOP"
}
],
output: null // Null means the return value can be of any type
},
// Clean this text so that it makes sense.
{
type: "transform_sense",
message0: "Clean this text so that it makes sense %1", // Shows up on the UI
args0: [
{
type: "input_value",
name: "transform_sense",
check: "String",
align: "TOP"
}
],
output: null // Null means the return value can be of any type
}, // Rewrite this in the style of Hunter S. Thompson.
{
type: "rewrite_style",
message0: "Rewrite this in the style of %1", // Shows up on the UI
args0: [
{
type: "input_value",
name: "rewrite_style",
check: "String",
align: "TOP"
}
],
output: null // Null means the return value can be of any type
}, // Rewrite this for a short magazine article.
{
type: "rewrite_for",
message0: "Rewrite this for %1", // Shows up on the UI
args0: [
{
type: "input_value",
name: "rewrite_for",
check: "String",
align: "TOP"
}
],
output: null // Null means the return value can be of any type
}
])
Insert cell
Insert cell
Insert cell
Blockly.Blocks
Insert cell
// Derives block categories from block ID namespaces.
generateToolbox = (Blockly) => {
const categories = {};
for(const blockId of Object.keys(Blockly.Blocks)) {
const i = blockId.indexOf('_');
const cName = blockId.slice(0, 1).toUpperCase() + blockId.slice(1, i > -1 ? i : blockId.length);
const cat = categories[cName] || (categories[cName] = {
kind: 'category',
name: cName,
contents: [],
});
cat.contents.push({
kind: 'block',
type: blockId,
});
}
return {
kind: 'categoryToolbox',
contents: Object.values(categories),
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more