mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
* fix(build): Restore erroneously-deleted filter function This was deleted in PR #7406 as it was mainly being used to filter core/ vs. test/mocha/ deps into separate deps files - but it turns out also to be used for filtering error messages too. Oops. * refactor(tests): Migrate advanced compilation test to ES Modules * refactor(build): Migrate main.js to TypeScript This turns out to be pretty straight forward, even if it would cause crashing if one actually tried to import this module instead of just feeding it to Closure Compiler. * chore(build): Remove goog.declareModuleId calls Replace goog.declareModuleId calls with a comment recording the former module ID for posterity (or at least until we decide how to reformat the renamings file. * chore(tests): Delete closure/goog/* For the moment we still need something to serve as base.js for the benefit of closure-make-deps, so we keep a vestigial base.js around, containing only the @provideGoog declaration. * refactor(build): Remove vestigial base.js By changing slightly the command line arguments to closure-make-deps and closure-calculate-chunks the need to have any base.js is eliminated. * chore: Typo fix for PR #7415
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* Non-editable, serializable text field. Behaves like a
|
|
* normal label but is serialized to XML. It may only be
|
|
* edited programmatically.
|
|
*
|
|
* @class
|
|
*/
|
|
// Former goog.module ID: Blockly.FieldLabelSerializable
|
|
|
|
import {
|
|
FieldLabel,
|
|
FieldLabelConfig,
|
|
FieldLabelFromJsonConfig,
|
|
} from './field_label.js';
|
|
import * as fieldRegistry from './field_registry.js';
|
|
import * as parsing from './utils/parsing.js';
|
|
|
|
/**
|
|
* Class for a non-editable, serializable text field.
|
|
*/
|
|
export class FieldLabelSerializable extends FieldLabel {
|
|
/**
|
|
* Editable fields usually show some sort of UI indicating they are
|
|
* editable. This field should not.
|
|
*/
|
|
override EDITABLE = false;
|
|
|
|
/**
|
|
* Serializable fields are saved by the XML renderer, non-serializable
|
|
* fields are not. This field should be serialized, but only edited
|
|
* programmatically.
|
|
*/
|
|
override SERIALIZABLE = true;
|
|
|
|
/**
|
|
* @param value The initial value of the field. Should cast to a string.
|
|
* Defaults to an empty string if null or undefined.
|
|
* @param textClass Optional CSS class for the field's text.
|
|
* @param config A map of options used to configure the field.
|
|
* See the [field creation documentation]{@link
|
|
* https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation}
|
|
* for a list of properties this parameter supports.
|
|
*/
|
|
constructor(value?: string, textClass?: string, config?: FieldLabelConfig) {
|
|
super(String(value ?? ''), textClass, config);
|
|
}
|
|
|
|
/**
|
|
* Construct a FieldLabelSerializable from a JSON arg object,
|
|
* dereferencing any string table references.
|
|
*
|
|
* @param options A JSON object with options (text, and class).
|
|
* @returns The new field instance.
|
|
* @nocollapse
|
|
* @internal
|
|
*/
|
|
static override fromJson(
|
|
options: FieldLabelFromJsonConfig,
|
|
): FieldLabelSerializable {
|
|
const text = parsing.replaceMessageReferences(options.text);
|
|
// `this` might be a subclass of FieldLabelSerializable if that class
|
|
// doesn't override the static fromJson method.
|
|
return new this(text, undefined, options);
|
|
}
|
|
}
|
|
|
|
fieldRegistry.register('field_label_serializable', FieldLabelSerializable);
|