weather block, mixins, docOverrides, ioPlus

This commit is contained in:
Loren Norman 2025-08-01 15:49:53 -04:00
parent dce355387e
commit 16578e4af7
2 changed files with 18 additions and 4 deletions

View file

@ -1,12 +1,12 @@
import weatherMixin from "./weather_mixin.js"
const
{ keyToLabel, HELP_TEXT_BY_PROP: propText } = weatherMixin,
propLines = (prefix, props) =>
props.map(prop => `${prefix}- \`${keyToLabel(prop)}\`: ${propText[prop].description}`).join("")
/** @type {import('#types').BlockDefinitionRaw} */
export default {
type: "weather",
bytecodeKey: "weather",
@ -36,6 +36,7 @@ export default {
weatherLocationOptions.unshift([ "Select Location", "" ])
}
// @ts-ignore
block.replaceDropdownOptions("POWER_UP_ID", weatherLocationOptions)
// skip the rest if we're in the toolbox
@ -46,16 +47,16 @@ export default {
// nope out for insertion markers
if(block.isInsertionMarker()) { return }
// auto-disable block, if necessary
// @ts-ignore auto-disable block, if necessary
block.setEnabledByLocation()
// react to incoming forecast data
const unobserve = observeData('currentWeatherByLocation', (newData = {}) => {
// if this block is disposed, clean up this listener
if (block.isDisposed()) { unobserve(); return }
// update the reference to the injected/updated extension data
// @ts-ignore update the reference to the injected/updated extension data
block.currentWeatherByLocation = newData
// re-run the things that use the data
// @ts-ignore re-run the things that use the data
block.refreshPropertyOptions({})
})
}, 1)

View file

@ -11,6 +11,8 @@
/**
* @typedef {object} BlockExtensionFunctionInjectable
* @prop {Blockly.Block} block
* @prop {function} observeData
* @prop {object} data
*/
/**
@ -22,6 +24,14 @@
* @typedef {Object.<string, BlockExtensionFunction>} BlockExtensions
*/
/**
* @typedef {string|object} BlocklyMixin
*/
/**
* @typedef {BlocklyMixin[]} BlockMixins
*/
/**
* @callback BlockGenerator
* @param {Blockly.Block} block
@ -66,13 +76,16 @@
* @prop {string=} primaryCategory For blocks appearing in multiple categories,
* this property determines which menu this block will appear under in the
* docs.
* @prop {boolean=} ioPlus Indicates this block requires an IO+ account.
* @prop {string} description Markdown documentation for this block. The first
* line will be automatically set as the Block's tooltip.
* @prop {BlockConnections} connections
* @prop {BlockExtensions=} extensions
* @prop {BlockMixins=} mixins
* @prop {string} template
* @prop {object=} fields
* @prop {object=} inputs
* @prop {BlockGenerators=} generators
* @prop {BlockRegenerators=} regenerators
* @prop {object=} docOverrides
*/