mirror of
https://github.com/google/blockly.git
synced 2026-05-12 23:20:10 +02:00
9d5dcc6e46
* chore: fix circular dependencies w/ static workspace funcs * remove preserved imports that aren't currently necessary (probably) * fix circular dependency with workspaces and block using stub * fix dependency between variables and xml by moving function to utils * add stub for trashcan as well * fix line endings from rebase * fix goog/base order * add trashcan patch * fix: types of compose and decompose in block * fix: workspace naming in toolbox * chore: add jsdoc * chore: restore registry comments to better positions * chore: remove implementations in goog.js * chore: fix types of stubs * chore: remove added AnyDuringMigration casts * chore: remove modifications to xml and variables * chore: format * chore: remove event requirements in workspace comments * chore: fix circular dependency with xml and workspace comments * fixup remove ContextMenu import * chore: fix dependency between mutator and workspace * chore: break circular dependency between names and procedures * chore: get tests to run? * chore: pr comments' * chore: fix stubbing field registry fromJson * chore: fix spying on fire * chore: fix stubbing parts of connection checker * chore: fix stubbing dialog * chore: fix stubbing style * chore: fix spying on duplicate * chore: fix stubbing variables * chore: fix stubbing copy * chore: fix stubbing in workspace * chore: remove unnecessary stubs * chore: fix formatting * chore: fix other formatting * chore: add backwards compatible static properties to workspace * chore: move static type properties * chore: move and comment stubs * chore: add newlines at EOF * chore: improve errors for monkey patched functions * chore: update comment with a pointer to the doc * chore: update comment with a pointer to the doc * chore: format
143 lines
4.3 KiB
TypeScript
143 lines
4.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Zelos renderer.
|
|
*/
|
|
|
|
/**
|
|
* Zelos renderer.
|
|
* @class
|
|
*/
|
|
import * as goog from '../../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.zelos.Renderer');
|
|
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
// Unused import preserved for side-effects. Remove if unneeded.
|
|
// import '../../theme.js';
|
|
|
|
import type {BlockSvg} from '../../block_svg.js';
|
|
import type {Connection} from '../../connection.js';
|
|
import {ConnectionType} from '../../connection_type.js';
|
|
import {InsertionMarkerManager} from '../../insertion_marker_manager.js';
|
|
import type {Marker} from '../../keyboard_nav/marker.js';
|
|
import type {RenderedConnection} from '../../rendered_connection.js';
|
|
import type {BlockStyle} from '../../theme.js';
|
|
import type {WorkspaceSvg} from '../../workspace_svg.js';
|
|
import * as blockRendering from '../common/block_rendering.js';
|
|
import type {RenderInfo as BaseRenderInfo} from '../common/info.js';
|
|
import {Renderer as BaseRenderer} from '../common/renderer.js';
|
|
|
|
import {ConstantProvider} from './constants.js';
|
|
import {Drawer} from './drawer.js';
|
|
import {RenderInfo} from './info.js';
|
|
import {MarkerSvg} from './marker_svg.js';
|
|
import {PathObject} from './path_object.js';
|
|
|
|
|
|
/**
|
|
* The zelos renderer.
|
|
* @alias Blockly.zelos.Renderer
|
|
*/
|
|
export class Renderer extends BaseRenderer {
|
|
protected override constants_!: ConstantProvider;
|
|
|
|
/**
|
|
* @param name The renderer name.
|
|
* @internal
|
|
*/
|
|
constructor(name: string) {
|
|
super(name);
|
|
}
|
|
|
|
/**
|
|
* Create a new instance of the renderer's constant provider.
|
|
* @return The constant provider.
|
|
*/
|
|
protected override makeConstants_(): ConstantProvider {
|
|
return new ConstantProvider();
|
|
}
|
|
|
|
/**
|
|
* Create a new instance of the renderer's render info object.
|
|
* @param block The block to measure.
|
|
* @return The render info object.
|
|
*/
|
|
protected override makeRenderInfo_(block: BlockSvg): RenderInfo {
|
|
return new RenderInfo(this, block);
|
|
}
|
|
|
|
/**
|
|
* Create a new instance of the renderer's drawer.
|
|
* @param block The block to render.
|
|
* @param info An object containing all information needed to render this
|
|
* block.
|
|
* @return The drawer.
|
|
*/
|
|
protected override makeDrawer_(block: BlockSvg, info: BaseRenderInfo):
|
|
Drawer {
|
|
return new Drawer(block, (info as RenderInfo));
|
|
}
|
|
|
|
/**
|
|
* Create a new instance of the renderer's cursor drawer.
|
|
* @param workspace The workspace the cursor belongs to.
|
|
* @param marker The marker.
|
|
* @return The object in charge of drawing the marker.
|
|
* @internal
|
|
*/
|
|
override makeMarkerDrawer(workspace: WorkspaceSvg, marker: Marker):
|
|
MarkerSvg {
|
|
return new MarkerSvg(workspace, this.getConstants(), marker);
|
|
}
|
|
|
|
/**
|
|
* Create a new instance of a renderer path object.
|
|
* @param root The root SVG element.
|
|
* @param style The style object to use for colouring.
|
|
* @return The renderer path object.
|
|
* @internal
|
|
*/
|
|
override makePathObject(root: SVGElement, style: BlockStyle): PathObject {
|
|
return new PathObject(
|
|
root, style, (this.getConstants() as ConstantProvider));
|
|
}
|
|
|
|
/**
|
|
* Get the current renderer's constant provider. We assume that when this is
|
|
* called, the renderer has already been initialized.
|
|
* @return The constant provider.
|
|
*/
|
|
override getConstants(): ConstantProvider {
|
|
return this.constants_;
|
|
}
|
|
|
|
override shouldHighlightConnection(conn: Connection) {
|
|
return conn.type !== ConnectionType.INPUT_VALUE &&
|
|
conn.type !== ConnectionType.OUTPUT_VALUE;
|
|
}
|
|
|
|
override getConnectionPreviewMethod(
|
|
closest: RenderedConnection, local: RenderedConnection,
|
|
topBlock: BlockSvg) {
|
|
if (local.type === ConnectionType.OUTPUT_VALUE) {
|
|
if (!closest.isConnected()) {
|
|
return InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE;
|
|
}
|
|
// TODO: Returning this is a total hack, because we don't want to show
|
|
// a replacement fade, we want to show an outline affect.
|
|
// Sadly zelos does not support showing an outline around filled
|
|
// inputs, so we have to pretend like the connected block is getting
|
|
// replaced.
|
|
return InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE;
|
|
}
|
|
|
|
return super.getConnectionPreviewMethod(closest, local, topBlock);
|
|
}
|
|
}
|
|
|
|
blockRendering.register('zelos', Renderer);
|