mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Use existing UID util
This commit is contained in:
parent
8355dd662f
commit
0a5ccbf42f
1 changed files with 2 additions and 28 deletions
|
@ -1,32 +1,6 @@
|
||||||
const mutationAdapter = require('./mutation-adapter');
|
const mutationAdapter = require('./mutation-adapter');
|
||||||
const html = require('htmlparser2');
|
const html = require('htmlparser2');
|
||||||
|
const uid = require('../util/uid');
|
||||||
/**
|
|
||||||
* (Copied from Blockly.utils)
|
|
||||||
* Legal characters for the unique ID. Should be all on a US keyboard.
|
|
||||||
* No characters that conflict with XML or JSON. Requests to remove additional
|
|
||||||
* 'problematic' characters from this soup will be denied. That's your failure
|
|
||||||
* to properly escape in your own environment. Issues #251, #625, #682, #1304.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const genUidSoup_ = '!#$%()*+,-./:;=?@[]^_`{|}~' +
|
|
||||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Copied from Blockly.utils)
|
|
||||||
* Generate a unique ID. This should be globally unique.
|
|
||||||
* 87 characters ^ 20 length > 128 bits (better than a UUID).
|
|
||||||
* @return {string} A globally unique ID string.
|
|
||||||
*/
|
|
||||||
const genUid_ = function () {
|
|
||||||
const length = 20;
|
|
||||||
const soupLength = genUidSoup_.length;
|
|
||||||
const id = [];
|
|
||||||
for (let i = 0; i < length; i++) {
|
|
||||||
id[i] = genUidSoup_.charAt(Math.random() * soupLength);
|
|
||||||
}
|
|
||||||
return id.join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert and an individual block DOM to the representation tree.
|
* Convert and an individual block DOM to the representation tree.
|
||||||
|
@ -39,7 +13,7 @@ const genUid_ = function () {
|
||||||
*/
|
*/
|
||||||
const domToBlock = function (blockDOM, blocks, isTopBlock, parent) {
|
const domToBlock = function (blockDOM, blocks, isTopBlock, parent) {
|
||||||
if (!blockDOM.attribs.id) {
|
if (!blockDOM.attribs.id) {
|
||||||
blockDOM.attribs.id = genUid_();
|
blockDOM.attribs.id = uid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block skeleton.
|
// Block skeleton.
|
||||||
|
|
Loading…
Reference in a new issue