diff --git a/src/playground/block_view.js b/src/playground/block_view.js index 781299799b..751b9d64f2 100644 --- a/src/playground/block_view.js +++ b/src/playground/block_view.js @@ -88,7 +88,7 @@ Entry.BlockView = class BlockView { } this.isInBlockMenu = this.getBoard() instanceof Entry.BlockMenu; - this.mouseHandler = function (e) { + this.mouseHandler = function(e) { (_.result(that.block.events, 'mousedown') || []).forEach((fn) => { if (Entry.documentMousedown) { Entry.documentMousedown.notify(e); @@ -608,7 +608,7 @@ Entry.BlockView = class BlockView { const mouseDownCoordinate = this.mouseDownCoordinate; const diff = Math.sqrt( Math.pow(mouseEvent.pageX - mouseDownCoordinate.x, 2) + - Math.pow(mouseEvent.pageY - mouseDownCoordinate.y, 2) + Math.pow(mouseEvent.pageY - mouseDownCoordinate.y, 2) ); if (this.dragMode == Entry.DRAG_MODE_DRAG || diff > Entry.BlockView.DRAG_RADIUS) { const blockView = this; @@ -1019,9 +1019,8 @@ Entry.BlockView = class BlockView { magnet = this.magnet.previous; const dragHeight = dragBlock.getBelowHeight(); const nextX = _get(dragBlock, 'magnet.next.x'); - transform = `translate(${pos.scaleX + magnet.x - nextX},${ - pos.scaleY + magnet.y - dragHeight - })`; + transform = `translate(${pos.scaleX + magnet.x - nextX},${pos.scaleY + magnet.y - dragHeight + })`; } const $shadow = $(shadow); @@ -1642,7 +1641,7 @@ Entry.BlockView = class BlockView { halfWidth = 20; } return { - getBoundingClientRect: function () { + getBoundingClientRect: function() { const coord = this.getAbsoluteCoordinate(); const boardOffset = this._board.relativeOffset; const magnet = this.magnet[selector]; @@ -1767,7 +1766,7 @@ Entry.BlockView = class BlockView { canvas.height = height; const ctx = canvas.getContext('2d'); - img.onload = function () { + img.onload = function() { try { ctx.drawImage(img, 0, 0, width, height); const data = canvas.toDataURL('image/png'); @@ -1780,7 +1779,7 @@ Entry.BlockView = class BlockView { } }; - img.onerror = function () { + img.onerror = function() { return reject('error occured'); }; img.src = src; diff --git a/src/playground/blocks/block_expansion_weather.js b/src/playground/blocks/block_expansion_weather.js index aa92c36d9d..43b8555093 100644 --- a/src/playground/blocks/block_expansion_weather.js +++ b/src/playground/blocks/block_expansion_weather.js @@ -3,16 +3,17 @@ const { getStateOptions, getCityOptions, locationData } = require('../../util/lo const { callApi } = require('../../util/common'); function resolveData(weatherData, type, dateStr) { + const defaultData = Entry.EXPANSION_BLOCK.weather.defaultData; try { + let key = Entry.EXPANSION_BLOCK.weather.getDate(dateStr); if (type === 'now') { - return weatherData[Object.keys(weatherData)[0]]; + key = Object.keys(weatherData)[0]; } else if (type === 'hour') { - return weatherData[dateStr]; - } else { - return weatherData[Entry.EXPANSION_BLOCK.weather.getDate(dateStr)]; + key = dateStr; } + return weatherData[key] || defaultData; } catch (e) { - return Entry.EXPANSION_BLOCK.weather.defaultData; + return defaultData; } } diff --git a/src/playground/field/textInput.js b/src/playground/field/textInput.js index 7565773540..814ed7880c 100644 --- a/src/playground/field/textInput.js +++ b/src/playground/field/textInput.js @@ -270,6 +270,7 @@ Entry.FieldTextInput = class FieldTextInput extends Entry.Field { applyValue(value, isNotUpdate) { let result = value; + if (this.optionWidget) { switch (this.optionWidget.type) { case 'angleWidget': @@ -289,6 +290,12 @@ Entry.FieldTextInput = class FieldTextInput extends Entry.Field { this.optionInput.val(result); } + if (this._block?.data?.type === 'function_field_label') { + const reg = /(%\d)/im; + if (result && reg.test(result)) { + result = result.replace(/%(\d)/gi, '$1'); + } + } this.setValue(result); this._setTextValue(); this.resize(); @@ -318,6 +325,11 @@ Entry.FieldTextInput = class FieldTextInput extends Entry.Field { delete this.optionInput; } + const reg = /(%\d)/im; + if (this.value && reg.test(this.value)) { + this.applyValue(this.value.replace(/%(\d)/gi, '$1')); + } + super.destroyOption(skipCommand, forceCommand); }