GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: re-export scratch-blocks utility functions (#26) · SnoopyMod/scratch-blocks@685ecfc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • core
    • scratch_blocks_utils.js
  • src
    • index.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎core/scratch_blocks_utils.js‎

Copy file name to clipboardExpand all lines: core/scratch_blocks_utils.js
+10-18Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@
2222
* @fileoverview Utility methods for Scratch Blocks but not Blockly.
2323
* @author [email protected] (Rachel Fenichel)
2424
*/
25-
'use strict';
26-
27-
/**
28-
* @name Blockly.scratchBlocksUtils
29-
* @namespace
30-
**/
31-
goog.provide('Blockly.scratchBlocksUtils');
32-
25+
import * as Blockly from 'blockly/core';
3326

3427
/**
3528
* Measure some text using a canvas in-memory.
@@ -41,7 +34,7 @@ goog.provide('Blockly.scratchBlocksUtils');
4134
* @return {number} Width of the text in px.
4235
* @package
4336
*/
44-
Blockly.scratchBlocksUtils.measureText = function(fontSize, fontFamily,
37+
export function measureText(fontSize, fontFamily,
4538
fontWeight, text) {
4639
var canvas = document.createElement('canvas');
4740
var context = canvas.getContext('2d');
@@ -57,7 +50,7 @@ Blockly.scratchBlocksUtils.measureText = function(fontSize, fontFamily,
5750
* @return {string} String with HTML entities encoded.
5851
* @package
5952
*/
60-
Blockly.scratchBlocksUtils.encodeEntities = function(rawStr) {
53+
export function encodeEntities(rawStr) {
6154
// CC-BY-SA https://stackoverflow.com/questions/18749591/encode-html-entities-in-javascript
6255
return rawStr.replace(/[\u00A0-\u9999<>&]/gim, function(i) {
6356
return '&#' + i.charCodeAt(0) + ';';
@@ -70,7 +63,7 @@ Blockly.scratchBlocksUtils.encodeEntities = function(rawStr) {
7063
* @param {Blockly.Block} block the root block to be processed.
7164
* @package
7265
*/
73-
Blockly.scratchBlocksUtils.changeObscuredShadowIds = function(block) {
66+
export function changeObscuredShadowIds(block) {
7467
var blocks = block.getDescendants(false);
7568
for (var i = blocks.length - 1; i >= 0; i--) {
7669
var descendant = blocks[i];
@@ -97,7 +90,7 @@ Blockly.scratchBlocksUtils.changeObscuredShadowIds = function(block) {
9790
* @return {boolean} True if the block should be duplicated on drag.
9891
* @package
9992
*/
100-
Blockly.scratchBlocksUtils.isShadowArgumentReporter = function(block) {
93+
export function isShadowArgumentReporter(block) {
10194
return (block.isShadow() && (block.type == 'argument_reporter_boolean' ||
10295
block.type == 'argument_reporter_string_number'));
10396
};
@@ -108,7 +101,7 @@ Blockly.scratchBlocksUtils.isShadowArgumentReporter = function(block) {
108101
* @param {string} str2 Second input.
109102
* @return {number} -1, 0, or 1 to signify greater than, equality, or less than.
110103
*/
111-
Blockly.scratchBlocksUtils.compareStrings = function(str1, str2) {
104+
export function compareStrings(str1, str2) {
112105
return str1.localeCompare(str2, [], {
113106
sensitivity: 'base',
114107
numeric: true
@@ -122,7 +115,7 @@ Blockly.scratchBlocksUtils.compareStrings = function(str1, str2) {
122115
* @return {boolean} True if the block can be recycled.
123116
* @package
124117
*/
125-
Blockly.scratchBlocksUtils.blockIsRecyclable = function(block) {
118+
export function blockIsRecyclable(block) {
126119
// If the block needs to parse mutations, never recycle.
127120
if (block.mutationToDom && block.domToMutation) {
128121
return false;
@@ -148,15 +141,14 @@ Blockly.scratchBlocksUtils.blockIsRecyclable = function(block) {
148141
// Check children.
149142
if (input.connection) {
150143
var child = input.connection.targetBlock();
151-
if (child && !Blockly.scratchBlocksUtils.blockIsRecyclable(child)) {
144+
if (child && !blockIsRecyclable(child)) {
152145
return false;
153146
}
154147
}
155148
}
156149
return true;
157150
};
158151

159-
160152
/**
161153
* Creates a callback function for a click on the "duplicate" context menu
162154
* option in Scratch Blocks. The block is duplicated and attached to the mouse,
@@ -168,7 +160,7 @@ Blockly.scratchBlocksUtils.blockIsRecyclable = function(block) {
168160
* drag.
169161
* @package
170162
*/
171-
Blockly.scratchBlocksUtils.duplicateAndDragCallback = function(oldBlock, event) {
163+
export function duplicateAndDragCallback(oldBlock, event) {
172164
var isMouseEvent = Blockly.Touch.getTouchIdentifierFromEvent(event) === 'mouse';
173165
return function(e) {
174166
// Give the context menu a chance to close.
@@ -195,7 +187,7 @@ Blockly.scratchBlocksUtils.duplicateAndDragCallback = function(oldBlock, event)
195187
var newBlock = Blockly.Xml.domToBlock(xml, ws);
196188

197189
// Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
198-
Blockly.scratchBlocksUtils.changeObscuredShadowIds(newBlock);
190+
changeObscuredShadowIds(newBlock);
199191

200192
var svgRootNew = newBlock.getSvgRoot();
201193
if (!svgRootNew) {
Collapse file

‎src/index.js‎

Copy file name to clipboardExpand all lines: src/index.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import '../blocks_vertical/looks.js';
1212
import '../blocks_vertical/motion.js';
1313
import '../blocks_vertical/operators.js';
1414
import '../blocks_vertical/sound.js';
15+
import * as scratchBlocksUtils from '../core/scratch_blocks_utils.js';
1516

1617
export * from 'blockly';
1718
export * from './categories.js';
1819
export * from '../core/colours.js';
1920
export * from '../msg/scratch_msgs.js';
21+
export {scratchBlocksUtils};

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.