weather block, mixins, docOverrides, ioPlus
This commit is contained in:
parent
dce355387e
commit
16578e4af7
2 changed files with 18 additions and 4 deletions
|
|
@ -1,12 +1,12 @@
|
||||||
import weatherMixin from "./weather_mixin.js"
|
import weatherMixin from "./weather_mixin.js"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
{ keyToLabel, HELP_TEXT_BY_PROP: propText } = weatherMixin,
|
{ keyToLabel, HELP_TEXT_BY_PROP: propText } = weatherMixin,
|
||||||
propLines = (prefix, props) =>
|
propLines = (prefix, props) =>
|
||||||
props.map(prop => `${prefix}- \`${keyToLabel(prop)}\`: ${propText[prop].description}`).join("")
|
props.map(prop => `${prefix}- \`${keyToLabel(prop)}\`: ${propText[prop].description}`).join("")
|
||||||
|
|
||||||
|
/** @type {import('#types').BlockDefinitionRaw} */
|
||||||
export default {
|
export default {
|
||||||
type: "weather",
|
type: "weather",
|
||||||
bytecodeKey: "weather",
|
bytecodeKey: "weather",
|
||||||
|
|
@ -36,6 +36,7 @@ export default {
|
||||||
weatherLocationOptions.unshift([ "Select Location", "" ])
|
weatherLocationOptions.unshift([ "Select Location", "" ])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
block.replaceDropdownOptions("POWER_UP_ID", weatherLocationOptions)
|
block.replaceDropdownOptions("POWER_UP_ID", weatherLocationOptions)
|
||||||
|
|
||||||
// skip the rest if we're in the toolbox
|
// skip the rest if we're in the toolbox
|
||||||
|
|
@ -46,16 +47,16 @@ export default {
|
||||||
// nope out for insertion markers
|
// nope out for insertion markers
|
||||||
if(block.isInsertionMarker()) { return }
|
if(block.isInsertionMarker()) { return }
|
||||||
|
|
||||||
// auto-disable block, if necessary
|
// @ts-ignore auto-disable block, if necessary
|
||||||
block.setEnabledByLocation()
|
block.setEnabledByLocation()
|
||||||
|
|
||||||
// react to incoming forecast data
|
// react to incoming forecast data
|
||||||
const unobserve = observeData('currentWeatherByLocation', (newData = {}) => {
|
const unobserve = observeData('currentWeatherByLocation', (newData = {}) => {
|
||||||
// if this block is disposed, clean up this listener
|
// if this block is disposed, clean up this listener
|
||||||
if (block.isDisposed()) { unobserve(); return }
|
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
|
block.currentWeatherByLocation = newData
|
||||||
// re-run the things that use the data
|
// @ts-ignore re-run the things that use the data
|
||||||
block.refreshPropertyOptions({})
|
block.refreshPropertyOptions({})
|
||||||
})
|
})
|
||||||
}, 1)
|
}, 1)
|
||||||
|
|
|
||||||
13
app/types.js
13
app/types.js
|
|
@ -11,6 +11,8 @@
|
||||||
/**
|
/**
|
||||||
* @typedef {object} BlockExtensionFunctionInjectable
|
* @typedef {object} BlockExtensionFunctionInjectable
|
||||||
* @prop {Blockly.Block} block
|
* @prop {Blockly.Block} block
|
||||||
|
* @prop {function} observeData
|
||||||
|
* @prop {object} data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,6 +24,14 @@
|
||||||
* @typedef {Object.<string, BlockExtensionFunction>} BlockExtensions
|
* @typedef {Object.<string, BlockExtensionFunction>} BlockExtensions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {string|object} BlocklyMixin
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {BlocklyMixin[]} BlockMixins
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback BlockGenerator
|
* @callback BlockGenerator
|
||||||
* @param {Blockly.Block} block
|
* @param {Blockly.Block} block
|
||||||
|
|
@ -66,13 +76,16 @@
|
||||||
* @prop {string=} primaryCategory For blocks appearing in multiple categories,
|
* @prop {string=} primaryCategory For blocks appearing in multiple categories,
|
||||||
* this property determines which menu this block will appear under in the
|
* this property determines which menu this block will appear under in the
|
||||||
* docs.
|
* docs.
|
||||||
|
* @prop {boolean=} ioPlus Indicates this block requires an IO+ account.
|
||||||
* @prop {string} description Markdown documentation for this block. The first
|
* @prop {string} description Markdown documentation for this block. The first
|
||||||
* line will be automatically set as the Block's tooltip.
|
* line will be automatically set as the Block's tooltip.
|
||||||
* @prop {BlockConnections} connections
|
* @prop {BlockConnections} connections
|
||||||
* @prop {BlockExtensions=} extensions
|
* @prop {BlockExtensions=} extensions
|
||||||
|
* @prop {BlockMixins=} mixins
|
||||||
* @prop {string} template
|
* @prop {string} template
|
||||||
* @prop {object=} fields
|
* @prop {object=} fields
|
||||||
* @prop {object=} inputs
|
* @prop {object=} inputs
|
||||||
* @prop {BlockGenerators=} generators
|
* @prop {BlockGenerators=} generators
|
||||||
* @prop {BlockRegenerators=} regenerators
|
* @prop {BlockRegenerators=} regenerators
|
||||||
|
* @prop {object=} docOverrides
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue