mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
chore: use prettier instead of clang-format (#7014)
* chore: add and configure prettier * chore: remove clang-format * chore: remove clang-format config * chore: lint additional ts files * chore: fix lint errors in blocks * chore: add prettier-ignore where needed * chore: ignore js blocks when formatting * chore: fix playground html syntax * chore: fix yaml spacing from merge * chore: convert text blocks to use arrow functions * chore: format everything with prettier * chore: fix lint unused imports in blocks
This commit is contained in:
committed by
GitHub
parent
af991f5e1b
commit
88ff901a72
@@ -19,7 +19,6 @@ import type {IDragTarget} from './interfaces/i_drag_target.js';
|
||||
import type {IPositionable} from './interfaces/i_positionable.js';
|
||||
import * as arrayUtils from './utils/array.js';
|
||||
|
||||
|
||||
class Capability<_T> {
|
||||
static POSITIONABLE = new Capability<IPositionable>('positionable');
|
||||
static DRAG_TARGET = new Capability<IDragTarget>('drag_target');
|
||||
@@ -67,8 +66,12 @@ export class ComponentManager {
|
||||
const id = componentInfo.component.id;
|
||||
if (!opt_allowOverrides && this.componentData.has(id)) {
|
||||
throw Error(
|
||||
'Plugin "' + id + '" with capabilities "' +
|
||||
this.componentData.get(id)?.capabilities + '" already added.');
|
||||
'Plugin "' +
|
||||
id +
|
||||
'" with capabilities "' +
|
||||
this.componentData.get(id)?.capabilities +
|
||||
'" already added.'
|
||||
);
|
||||
}
|
||||
this.componentData.set(id, componentInfo);
|
||||
const stringCapabilities = [];
|
||||
@@ -107,15 +110,20 @@ export class ComponentManager {
|
||||
* @param id The ID of the component to add the capability to.
|
||||
* @param capability The capability to add.
|
||||
*/
|
||||
addCapability<T>(id: string, capability: string|Capability<T>) {
|
||||
addCapability<T>(id: string, capability: string | Capability<T>) {
|
||||
if (!this.getComponent(id)) {
|
||||
throw Error(
|
||||
'Cannot add capability, "' + capability + '". Plugin "' + id +
|
||||
'" has not been added to the ComponentManager');
|
||||
'Cannot add capability, "' +
|
||||
capability +
|
||||
'". Plugin "' +
|
||||
id +
|
||||
'" has not been added to the ComponentManager'
|
||||
);
|
||||
}
|
||||
if (this.hasCapability(id, capability)) {
|
||||
console.warn(
|
||||
'Plugin "' + id + 'already has capability "' + capability + '"');
|
||||
'Plugin "' + id + 'already has capability "' + capability + '"'
|
||||
);
|
||||
return;
|
||||
}
|
||||
capability = `${capability}`.toLowerCase();
|
||||
@@ -129,16 +137,24 @@ export class ComponentManager {
|
||||
* @param id The ID of the component to remove the capability from.
|
||||
* @param capability The capability to remove.
|
||||
*/
|
||||
removeCapability<T>(id: string, capability: string|Capability<T>) {
|
||||
removeCapability<T>(id: string, capability: string | Capability<T>) {
|
||||
if (!this.getComponent(id)) {
|
||||
throw Error(
|
||||
'Cannot remove capability, "' + capability + '". Plugin "' + id +
|
||||
'" has not been added to the ComponentManager');
|
||||
'Cannot remove capability, "' +
|
||||
capability +
|
||||
'". Plugin "' +
|
||||
id +
|
||||
'" has not been added to the ComponentManager'
|
||||
);
|
||||
}
|
||||
if (!this.hasCapability(id, capability)) {
|
||||
console.warn(
|
||||
'Plugin "' + id + 'doesn\'t have capability "' + capability +
|
||||
'" to remove');
|
||||
'Plugin "' +
|
||||
id +
|
||||
'doesn\'t have capability "' +
|
||||
capability +
|
||||
'" to remove'
|
||||
);
|
||||
return;
|
||||
}
|
||||
capability = `${capability}`.toLowerCase();
|
||||
@@ -153,10 +169,12 @@ export class ComponentManager {
|
||||
* @param capability The capability to check for.
|
||||
* @returns Whether the component has the capability.
|
||||
*/
|
||||
hasCapability<T>(id: string, capability: string|Capability<T>): boolean {
|
||||
hasCapability<T>(id: string, capability: string | Capability<T>): boolean {
|
||||
capability = `${capability}`.toLowerCase();
|
||||
return this.componentData.has(id) &&
|
||||
this.componentData.get(id)!.capabilities.indexOf(capability) !== -1;
|
||||
return (
|
||||
this.componentData.has(id) &&
|
||||
this.componentData.get(id)!.capabilities.indexOf(capability) !== -1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +183,7 @@ export class ComponentManager {
|
||||
* @param id The ID of the component to get.
|
||||
* @returns The component with the given name or undefined if not found.
|
||||
*/
|
||||
getComponent(id: string): IComponent|undefined {
|
||||
getComponent(id: string): IComponent | undefined {
|
||||
return this.componentData.get(id)?.component;
|
||||
}
|
||||
|
||||
@@ -177,7 +195,9 @@ export class ComponentManager {
|
||||
* @returns The components that match the specified capability.
|
||||
*/
|
||||
getComponents<T extends IComponent>(
|
||||
capability: string|Capability<T>, sorted: boolean): T[] {
|
||||
capability: string | Capability<T>,
|
||||
sorted: boolean
|
||||
): T[] {
|
||||
capability = `${capability}`.toLowerCase();
|
||||
const componentIds = this.capabilityToComponentIds.get(capability);
|
||||
if (!componentIds) {
|
||||
@@ -189,10 +209,10 @@ export class ComponentManager {
|
||||
componentIds.forEach((id) => {
|
||||
componentDataList.push(this.componentData.get(id)!);
|
||||
});
|
||||
componentDataList.sort(function(a, b) {
|
||||
componentDataList.sort(function (a, b) {
|
||||
return a.weight - b.weight;
|
||||
});
|
||||
componentDataList.forEach(function(componentDatum) {
|
||||
componentDataList.forEach(function (componentDatum) {
|
||||
components.push(componentDatum.component as T);
|
||||
});
|
||||
} else {
|
||||
@@ -208,7 +228,7 @@ export namespace ComponentManager {
|
||||
/** An object storing component information. */
|
||||
export interface ComponentDatum {
|
||||
component: IComponent;
|
||||
capabilities: Array<string|Capability<IComponent>>;
|
||||
capabilities: Array<string | Capability<IComponent>>;
|
||||
weight: number;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user