scratch-blocks 2.1.10 → 2.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedures.d.ts","sourceRoot":"","sources":["../../../../src/blocks/procedures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAIvC;;GAEG;AACH,KAAK,aAAa,GAAG,MAAM,CACzB,MAAM,EACN;IACE,MAAM,EAAE,OAAO,GAAG,SAAS,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAA;CAC/B,GAAG,IAAI,CACT,CAAA;AAED;;GAEG;AACH,aAAK,YAAY;IACf,MAAM,MAAM;IACZ,MAAM,MAAM;IACZ,OAAO,MAAM;CACd;
|
|
1
|
+
{"version":3,"file":"procedures.d.ts","sourceRoot":"","sources":["../../../../src/blocks/procedures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAIvC;;GAEG;AACH,KAAK,aAAa,GAAG,MAAM,CACzB,MAAM,EACN;IACE,MAAM,EAAE,OAAO,GAAG,SAAS,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAA;CAC/B,GAAG,IAAI,CACT,CAAA;AAED;;GAEG;AACH,aAAK,YAAY;IACf,MAAM,MAAM;IACZ,MAAM,MAAM;IACZ,OAAO,MAAM;CACd;AA8vCD,UAAU,cAAe,SAAQ,OAAO,CAAC,QAAQ;IAC/C,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,WAAW,EAAE,MAAM,MAAM,CAAA;IACzB,gBAAgB,EAAE,MAAM,IAAI,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AAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,YAAY,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"xml.d.ts","sourceRoot":"","sources":["../../../src/xml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAGvC;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,YAAY,GAAG,MAAM,EAAE,CAkDpG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scratch-blocks",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.12",
|
|
4
4
|
"description": "Scratch Blocks is a library for building creative computing interfaces.",
|
|
5
5
|
"author": "Massachusetts Institute of Technology",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,20 +38,20 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@commitlint/cli": "20.5.0",
|
|
40
40
|
"@commitlint/config-conventional": "20.5.0",
|
|
41
|
-
"@vitest/browser": "4.1.
|
|
42
|
-
"@vitest/browser-playwright": "4.1.
|
|
41
|
+
"@vitest/browser": "4.1.4",
|
|
42
|
+
"@vitest/browser-playwright": "4.1.4",
|
|
43
43
|
"eslint": "9.39.4",
|
|
44
|
-
"eslint-config-scratch": "14.1.
|
|
44
|
+
"eslint-config-scratch": "14.1.7",
|
|
45
45
|
"husky": "9.1.7",
|
|
46
46
|
"playwright": "1.59.1",
|
|
47
|
-
"prettier": "3.8.
|
|
47
|
+
"prettier": "3.8.2",
|
|
48
48
|
"scratch-semantic-release-config": "4.0.1",
|
|
49
49
|
"semantic-release": "25.0.3",
|
|
50
50
|
"source-map-loader": "5.0.0",
|
|
51
51
|
"ts-loader": "9.5.7",
|
|
52
52
|
"typescript": "5.9.3",
|
|
53
|
-
"vitest": "4.1.
|
|
54
|
-
"webpack": "5.
|
|
53
|
+
"vitest": "4.1.4",
|
|
54
|
+
"webpack": "5.106.1",
|
|
55
55
|
"webpack-cli": "6.0.1",
|
|
56
56
|
"webpack-dev-server": "5.2.3"
|
|
57
57
|
},
|
package/src/blocks/procedures.ts
CHANGED
|
@@ -97,6 +97,38 @@ function parseRequiredMutationJson<T>(
|
|
|
97
97
|
return parse(parsedValue, name)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Parse an optional mutation attribute as JSON, returning a fallback when the
|
|
102
|
+
* attribute is absent. Use this only for attributes that can be safely
|
|
103
|
+
* defaulted in isolation, without invalidating structural invariants that
|
|
104
|
+
* relate them to other attributes on the same mutation. A present-but-malformed
|
|
105
|
+
* attribute still throws, since that indicates corruption rather than an older
|
|
106
|
+
* schema.
|
|
107
|
+
* @param xmlElement The mutation element that may contain the attribute.
|
|
108
|
+
* @param name The specific mutation attribute to retrieve and parse.
|
|
109
|
+
* @param parse Validates and narrows the parsed JSON value.
|
|
110
|
+
* @param fallback Value to return when the attribute is absent.
|
|
111
|
+
* @returns Parsed and validated mutation attribute value, or `fallback`.
|
|
112
|
+
*/
|
|
113
|
+
function parseOptionalMutationJson<T>(
|
|
114
|
+
xmlElement: Element,
|
|
115
|
+
name: string,
|
|
116
|
+
parse: (value: unknown, name: string) => T,
|
|
117
|
+
fallback: T,
|
|
118
|
+
): T {
|
|
119
|
+
const rawValue = xmlElement.getAttribute(name)
|
|
120
|
+
if (rawValue === null) {
|
|
121
|
+
return fallback
|
|
122
|
+
}
|
|
123
|
+
let parsedValue: unknown
|
|
124
|
+
try {
|
|
125
|
+
parsedValue = JSON.parse(rawValue)
|
|
126
|
+
} catch {
|
|
127
|
+
throw new Error(`Invalid JSON in mutation attribute: ${name}`)
|
|
128
|
+
}
|
|
129
|
+
return parse(parsedValue, name)
|
|
130
|
+
}
|
|
131
|
+
|
|
100
132
|
/**
|
|
101
133
|
* Validate a parsed mutation value as a boolean.
|
|
102
134
|
* @param value Parsed mutation value.
|
|
@@ -277,7 +309,7 @@ function callerDomToMutation(this: ProcedureCallBlock, xmlElement: Element) {
|
|
|
277
309
|
const generateshadows = xmlElement.getAttribute('generateshadows')
|
|
278
310
|
this.generateShadows_ = generateshadows !== null ? JSON.parse(generateshadows) === true : false
|
|
279
311
|
this.argumentIds_ = parseRequiredMutationJson(xmlElement, 'argumentids', parseStringArrayMutationValue)
|
|
280
|
-
this.warp_ =
|
|
312
|
+
this.warp_ = parseOptionalMutationJson(xmlElement, 'warp', parseBooleanMutationValue, false)
|
|
281
313
|
this.updateDisplay_()
|
|
282
314
|
}
|
|
283
315
|
|
|
@@ -312,7 +344,7 @@ function definitionMutationToDom(
|
|
|
312
344
|
*/
|
|
313
345
|
function definitionDomToMutation(this: ProcedurePrototypeBlock | ProcedureDeclarationBlock, xmlElement: Element) {
|
|
314
346
|
this.procCode_ = getRequiredMutationAttribute(xmlElement, 'proccode')
|
|
315
|
-
this.warp_ =
|
|
347
|
+
this.warp_ = parseOptionalMutationJson(xmlElement, 'warp', parseBooleanMutationValue, false)
|
|
316
348
|
|
|
317
349
|
const prevArgIds = this.argumentIds_
|
|
318
350
|
const prevDisplayNames = this.displayNames_
|
package/src/xml.ts
CHANGED
|
@@ -36,8 +36,29 @@ export function clearWorkspaceAndLoadFromXml(xml: Element, workspace: Blockly.Wo
|
|
|
36
36
|
xml.querySelector('variables')?.remove()
|
|
37
37
|
|
|
38
38
|
// Defer to core for the rest of the deserialization.
|
|
39
|
-
|
|
39
|
+
let blockIds: string[]
|
|
40
|
+
try {
|
|
41
|
+
blockIds = Blockly.Xml.domToWorkspace(xml, workspace)
|
|
42
|
+
} catch (error) {
|
|
43
|
+
const context =
|
|
44
|
+
Array.from(xml.children)
|
|
45
|
+
.map((el) => {
|
|
46
|
+
const type = el.getAttribute('type')
|
|
47
|
+
const id = el.getAttribute('id')
|
|
48
|
+
const attrs = [...(type ? [`type=${type}`] : []), ...(id ? [`id=${id}`] : [])]
|
|
49
|
+
return attrs.length ? `${el.tagName}[${attrs.join(', ')}]` : el.tagName
|
|
50
|
+
})
|
|
51
|
+
.join(', ') || '(none)'
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
53
|
+
const wrapped = new Error(
|
|
54
|
+
`Failed to load workspace XML (${message}). Top-level elements: ${context}`,
|
|
55
|
+
) as Error & { cause?: unknown }
|
|
56
|
+
wrapped.cause = error
|
|
57
|
+
throw wrapped
|
|
58
|
+
} finally {
|
|
59
|
+
Blockly.Events.setGroup(false)
|
|
60
|
+
workspace.setResizesEnabled(true)
|
|
61
|
+
}
|
|
40
62
|
|
|
41
|
-
workspace.setResizesEnabled(true)
|
|
42
63
|
return blockIds
|
|
43
64
|
}
|