Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pxtblocks/fields/field_colour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ import { FieldCustom, FieldCustomOptions } from './field_utils';
*/
export type FieldColourValueMode = "hex" | "rgb" | "index";

/**
* Fallback palette used when a colour field is created without explicit
* `colours` field options and the target defines no `runtime.palette`. Older
* pxt tolerated a missing palette; without this guard makeSwatches() receives
* `undefined` and throws, which aborts the whole flyout layout (every block in
* the category is left unpositioned). This is the canonical MakeCode palette.
*/
const DEFAULT_COLOUR_PALETTE: string[] = [
"#000000", "#ffffff", "#ff2121", "#ff93c4", "#ff8135", "#fff609",
"#249ca3", "#78dc52", "#003fad", "#87f2ff", "#8e2ec4", "#a4839f",
"#5c406c", "#e5cdc4", "#91463d", "#000000"
];

export interface FieldColourNumberOptions extends FieldCustomOptions {
colours?: string; // parsed as a JSON array
columns?: string; // parsed as a number
Expand Down Expand Up @@ -64,6 +77,11 @@ export class FieldColorNumber extends FieldGridDropdown implements FieldCustom {
titles[0] = lf("transparent");
}
}
if (!allColoursCSSFormat) {
// No field-level colours and no target palette: fall back so
// makeSwatches doesn't throw and break the flyout layout.
allColoursCSSFormat = DEFAULT_COLOUR_PALETTE.slice();
}
super(makeSwatches(valueMode, allColoursCSSFormat, titles), opt_validator, {
primaryColour: "white",
borderColour: "#dadce0",
Expand Down
Loading