mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
This reverts commit340bd16cd3. Reason for revert: devtools_pre_built no longer makes hardlinks Original change's description: > Revert "Reland "Updates elements to devtools_module"" > > This reverts commit04858cf7dd. > > Reason for revert: This seems to trigger the known issue that > TSC is rewriting source files because of left-over hard-links. > See https://ci.chromium.org/p/devtools-frontend/builders/ci/Stand-alone%20Linux/2582 > > To reproduce locally, check out the commit before this revision, > do a clean build, then check out this revision, and do a build. > This will succeed but rewrite source files (which it shouldn't). > > > Original change's description: > > Reland "Updates elements to devtools_module" > > > > This reverts commit22d876ca02. > > > > Reason for revert: Build issues on bots should be fixed > > > > Original change's description: > > > Revert "Updates elements to devtools_module" > > > > > > This reverts commit81e818fad8. > > > > > > Reason for revert: Anticipating build errors on bots > > > > > > Original change's description: > > > > Updates elements to devtools_module > > > > > > > > Bug: 1101738 > > > > Change-Id: I294d366c95a3b5dc7ac5b757855846a7b31ac60b > > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2329779 > > > > Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> > > > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > > > > > TBR=aerotwist@chromium.org,jacktfranklin@chromium.org > > > > > > Change-Id: I3e36a1520e34be3ce1779ecdf2b4cead6a293971 > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Bug: 1101738 > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2332815 > > > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > > > TBR=aerotwist@chromium.org,jacktfranklin@chromium.org > > > > # Not skipping CQ checks because this is a reland. > > > > Bug: 1101738 > > Change-Id: Ia0d06bb75f2610459f4d0b31ff6b770b1031d982 > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2335060 > > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > > Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > TBR=aerotwist@chromium.org,jacktfranklin@chromium.org > > Change-Id: Iabfbe2aad94033078eac41338d64ca069f49332f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: 1101738 > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2335273 > Reviewed-by: Sigurd Schneider <sigurds@chromium.org> > Commit-Queue: Sigurd Schneider <sigurds@chromium.org> TBR=sigurds@chromium.org,aerotwist@chromium.org,jacktfranklin@chromium.org # Not skipping CQ checks because this is a reland. Bug: 1101738 Change-Id: I42579d6cac06ec45377789253588ba94ee72a226 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2336715 Commit-Queue: Paul Lewis <aerotwist@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
361 lines
12 KiB
JavaScript
361 lines
12 KiB
JavaScript
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// @ts-nocheck
|
|
// TODO(crbug.com/1011811): Enable TypeScript compiler checks
|
|
|
|
import * as Bindings from '../bindings/bindings.js';
|
|
import * as ColorPicker from '../color_picker/color_picker.js';
|
|
import * as Common from '../common/common.js';
|
|
import * as InlineEditor from '../inline_editor/inline_editor.js';
|
|
import * as UI from '../ui/ui.js';
|
|
|
|
import {StylePropertyTreeElement} from './StylePropertyTreeElement.js'; // eslint-disable-line no-unused-vars
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
export class BezierPopoverIcon {
|
|
/**
|
|
* @param {!StylePropertyTreeElement} treeElement
|
|
* @param {!InlineEditor.SwatchPopoverHelper.SwatchPopoverHelper} swatchPopoverHelper
|
|
* @param {!InlineEditor.ColorSwatch.BezierSwatch} swatch
|
|
*/
|
|
constructor(treeElement, swatchPopoverHelper, swatch) {
|
|
this._treeElement = treeElement;
|
|
this._swatchPopoverHelper = swatchPopoverHelper;
|
|
this._swatch = swatch;
|
|
|
|
this._swatch.iconElement().title = Common.UIString.UIString('Open cubic bezier editor.');
|
|
this._swatch.iconElement().addEventListener('click', this._iconClick.bind(this), false);
|
|
this._swatch.iconElement().addEventListener('mousedown', event => event.consume(), false);
|
|
|
|
this._boundBezierChanged = this._bezierChanged.bind(this);
|
|
this._boundOnScroll = this._onScroll.bind(this);
|
|
}
|
|
|
|
/**
|
|
* @param {!Event} event
|
|
*/
|
|
_iconClick(event) {
|
|
event.consume(true);
|
|
if (this._swatchPopoverHelper.isShowing()) {
|
|
this._swatchPopoverHelper.hide(true);
|
|
return;
|
|
}
|
|
|
|
this._bezierEditor = new InlineEditor.BezierEditor.BezierEditor();
|
|
let cubicBezier = UI.Geometry.CubicBezier.parse(this._swatch.bezierText());
|
|
if (!cubicBezier) {
|
|
cubicBezier =
|
|
/** @type {!UI.Geometry.CubicBezier} */ (UI.Geometry.CubicBezier.parse('linear'));
|
|
}
|
|
this._bezierEditor.setBezier(cubicBezier);
|
|
this._bezierEditor.addEventListener(InlineEditor.BezierEditor.Events.BezierChanged, this._boundBezierChanged);
|
|
this._swatchPopoverHelper.show(this._bezierEditor, this._swatch.iconElement(), this._onPopoverHidden.bind(this));
|
|
this._scrollerElement = this._swatch.enclosingNodeOrSelfWithClass('style-panes-wrapper');
|
|
if (this._scrollerElement) {
|
|
this._scrollerElement.addEventListener('scroll', this._boundOnScroll, false);
|
|
}
|
|
|
|
this._originalPropertyText = this._treeElement.property.propertyText;
|
|
this._treeElement.parentPane().setEditingStyle(true);
|
|
const uiLocation = Bindings.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().propertyUILocation(
|
|
this._treeElement.property, false /* forName */);
|
|
if (uiLocation) {
|
|
Common.Revealer.reveal(uiLocation, true /* omitFocus */);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {!Common.EventTarget.EventTargetEvent} event
|
|
*/
|
|
_bezierChanged(event) {
|
|
this._swatch.setBezierText(/** @type {string} */ (event.data));
|
|
this._treeElement.applyStyleText(this._treeElement.renderedPropertyText(), false);
|
|
}
|
|
|
|
/**
|
|
* @param {!Event} event
|
|
*/
|
|
_onScroll(event) {
|
|
this._swatchPopoverHelper.reposition();
|
|
}
|
|
|
|
/**
|
|
* @param {boolean} commitEdit
|
|
*/
|
|
_onPopoverHidden(commitEdit) {
|
|
if (this._scrollerElement) {
|
|
this._scrollerElement.removeEventListener('scroll', this._boundOnScroll, false);
|
|
}
|
|
|
|
this._bezierEditor.removeEventListener(InlineEditor.BezierEditor.Events.BezierChanged, this._boundBezierChanged);
|
|
delete this._bezierEditor;
|
|
|
|
const propertyText = commitEdit ? this._treeElement.renderedPropertyText() : this._originalPropertyText;
|
|
this._treeElement.applyStyleText(propertyText, true);
|
|
this._treeElement.parentPane().setEditingStyle(false);
|
|
delete this._originalPropertyText;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
export class ColorSwatchPopoverIcon {
|
|
/**
|
|
* @param {!StylePropertyTreeElement} treeElement
|
|
* @param {!InlineEditor.SwatchPopoverHelper.SwatchPopoverHelper} swatchPopoverHelper
|
|
* @param {!InlineEditor.ColorSwatch.ColorSwatch} swatch
|
|
*/
|
|
constructor(treeElement, swatchPopoverHelper, swatch) {
|
|
this._treeElement = treeElement;
|
|
this._treeElement[ColorSwatchPopoverIcon._treeElementSymbol] = this;
|
|
this._swatchPopoverHelper = swatchPopoverHelper;
|
|
this._swatch = swatch;
|
|
|
|
const shiftClickMessage = Common.UIString.UIString('Shift + Click to change color format.');
|
|
this._swatch.iconElement().title = Common.UIString.UIString('Open color picker. %s', shiftClickMessage);
|
|
this._swatch.iconElement().addEventListener('click', this._iconClick.bind(this));
|
|
this._swatch.iconElement().addEventListener('mousedown', event => event.consume(), false);
|
|
this._contrastInfo = null;
|
|
|
|
this._boundSpectrumChanged = this._spectrumChanged.bind(this);
|
|
this._boundOnScroll = this._onScroll.bind(this);
|
|
}
|
|
|
|
/**
|
|
* @return {!ColorPicker.Spectrum.Palette}
|
|
*/
|
|
_generateCSSVariablesPalette() {
|
|
const matchedStyles = this._treeElement.matchedStyles();
|
|
const style = this._treeElement.property.ownerStyle;
|
|
const cssVariables = matchedStyles.availableCSSVariables(style);
|
|
const colors = [];
|
|
const colorNames = [];
|
|
for (const cssVariable of cssVariables) {
|
|
if (cssVariable === this._treeElement.property.name) {
|
|
continue;
|
|
}
|
|
const value = matchedStyles.computeCSSVariable(style, cssVariable);
|
|
if (!value) {
|
|
continue;
|
|
}
|
|
const color = Common.Color.Color.parse(value);
|
|
if (!color) {
|
|
continue;
|
|
}
|
|
colors.push(value);
|
|
colorNames.push(cssVariable);
|
|
}
|
|
return {title: 'CSS Variables', mutable: false, matchUserFormat: true, colors: colors, colorNames: colorNames};
|
|
}
|
|
|
|
/**
|
|
* @param {!StylePropertyTreeElement} treeElement
|
|
* @return {?ColorSwatchPopoverIcon}
|
|
*/
|
|
static forTreeElement(treeElement) {
|
|
return treeElement[ColorSwatchPopoverIcon._treeElementSymbol] || null;
|
|
}
|
|
|
|
/**
|
|
* @param {!ColorPicker.ContrastInfo.ContrastInfo} contrastInfo
|
|
*/
|
|
setContrastInfo(contrastInfo) {
|
|
this._contrastInfo = contrastInfo;
|
|
}
|
|
|
|
/**
|
|
* @param {!Event} event
|
|
*/
|
|
_iconClick(event) {
|
|
event.consume(true);
|
|
this.showPopover();
|
|
}
|
|
|
|
showPopover() {
|
|
if (this._swatchPopoverHelper.isShowing()) {
|
|
this._swatchPopoverHelper.hide(true);
|
|
return;
|
|
}
|
|
|
|
const color = this._swatch.color();
|
|
let format = this._swatch.format();
|
|
if (format === Common.Color.Format.Original) {
|
|
format = color.format();
|
|
}
|
|
this._spectrum = new ColorPicker.Spectrum.Spectrum(this._contrastInfo);
|
|
this._spectrum.setColor(color, format);
|
|
this._spectrum.addPalette(this._generateCSSVariablesPalette());
|
|
|
|
this._spectrum.addEventListener(ColorPicker.Spectrum.Events.SizeChanged, this._spectrumResized, this);
|
|
this._spectrum.addEventListener(ColorPicker.Spectrum.Events.ColorChanged, this._boundSpectrumChanged);
|
|
this._swatchPopoverHelper.show(this._spectrum, this._swatch.iconElement(), this._onPopoverHidden.bind(this));
|
|
this._scrollerElement = this._swatch.enclosingNodeOrSelfWithClass('style-panes-wrapper');
|
|
if (this._scrollerElement) {
|
|
this._scrollerElement.addEventListener('scroll', this._boundOnScroll, false);
|
|
}
|
|
|
|
this._originalPropertyText = this._treeElement.property.propertyText;
|
|
this._treeElement.parentPane().setEditingStyle(true);
|
|
const uiLocation = Bindings.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().propertyUILocation(
|
|
this._treeElement.property, false /* forName */);
|
|
if (uiLocation) {
|
|
Common.Revealer.reveal(uiLocation, true /* omitFocus */);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {!Common.EventTarget.EventTargetEvent} event
|
|
*/
|
|
_spectrumResized(event) {
|
|
this._swatchPopoverHelper.reposition();
|
|
}
|
|
|
|
/**
|
|
* @param {!Common.EventTarget.EventTargetEvent} event
|
|
*/
|
|
_spectrumChanged(event) {
|
|
const color = Common.Color.Color.parse(/** @type {string} */ (event.data));
|
|
if (!color) {
|
|
return;
|
|
}
|
|
this._swatch.setColor(color);
|
|
const colorName = this._spectrum.colorName();
|
|
if (colorName && colorName.startsWith('--')) {
|
|
this._swatch.setText(`var(${colorName})`);
|
|
}
|
|
|
|
this._treeElement.applyStyleText(this._treeElement.renderedPropertyText(), false);
|
|
}
|
|
|
|
/**
|
|
* @param {!Event} event
|
|
*/
|
|
_onScroll(event) {
|
|
this._swatchPopoverHelper.reposition();
|
|
}
|
|
|
|
/**
|
|
* @param {boolean} commitEdit
|
|
*/
|
|
_onPopoverHidden(commitEdit) {
|
|
if (this._scrollerElement) {
|
|
this._scrollerElement.removeEventListener('scroll', this._boundOnScroll, false);
|
|
}
|
|
|
|
this._spectrum.removeEventListener(ColorPicker.Spectrum.Events.ColorChanged, this._boundSpectrumChanged);
|
|
delete this._spectrum;
|
|
|
|
const propertyText = commitEdit ? this._treeElement.renderedPropertyText() : this._originalPropertyText;
|
|
this._treeElement.applyStyleText(propertyText, true);
|
|
this._treeElement.parentPane().setEditingStyle(false);
|
|
delete this._originalPropertyText;
|
|
}
|
|
}
|
|
|
|
ColorSwatchPopoverIcon._treeElementSymbol = Symbol('ColorSwatchPopoverIcon._treeElementSymbol');
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
export class ShadowSwatchPopoverHelper {
|
|
/**
|
|
* @param {!StylePropertyTreeElement} treeElement
|
|
* @param {!InlineEditor.SwatchPopoverHelper.SwatchPopoverHelper} swatchPopoverHelper
|
|
* @param {!InlineEditor.ColorSwatch.CSSShadowSwatch} shadowSwatch
|
|
*/
|
|
constructor(treeElement, swatchPopoverHelper, shadowSwatch) {
|
|
this._treeElement = treeElement;
|
|
this._treeElement[ShadowSwatchPopoverHelper._treeElementSymbol] = this;
|
|
this._swatchPopoverHelper = swatchPopoverHelper;
|
|
this._shadowSwatch = shadowSwatch;
|
|
this._iconElement = shadowSwatch.iconElement();
|
|
|
|
this._iconElement.title = Common.UIString.UIString('Open shadow editor.');
|
|
this._iconElement.addEventListener('click', this._iconClick.bind(this), false);
|
|
this._iconElement.addEventListener('mousedown', event => event.consume(), false);
|
|
|
|
this._boundShadowChanged = this._shadowChanged.bind(this);
|
|
this._boundOnScroll = this._onScroll.bind(this);
|
|
}
|
|
|
|
/**
|
|
* @param {!StylePropertyTreeElement} treeElement
|
|
* @return {?ShadowSwatchPopoverHelper}
|
|
*/
|
|
static forTreeElement(treeElement) {
|
|
return treeElement[ShadowSwatchPopoverHelper._treeElementSymbol] || null;
|
|
}
|
|
|
|
/**
|
|
* @param {!Event} event
|
|
*/
|
|
_iconClick(event) {
|
|
event.consume(true);
|
|
this.showPopover();
|
|
}
|
|
|
|
showPopover() {
|
|
if (this._swatchPopoverHelper.isShowing()) {
|
|
this._swatchPopoverHelper.hide(true);
|
|
return;
|
|
}
|
|
|
|
this._cssShadowEditor = new InlineEditor.CSSShadowEditor.CSSShadowEditor();
|
|
this._cssShadowEditor.setModel(this._shadowSwatch.model());
|
|
this._cssShadowEditor.addEventListener(InlineEditor.CSSShadowEditor.Events.ShadowChanged, this._boundShadowChanged);
|
|
this._swatchPopoverHelper.show(this._cssShadowEditor, this._iconElement, this._onPopoverHidden.bind(this));
|
|
this._scrollerElement = this._iconElement.enclosingNodeOrSelfWithClass('style-panes-wrapper');
|
|
if (this._scrollerElement) {
|
|
this._scrollerElement.addEventListener('scroll', this._boundOnScroll, false);
|
|
}
|
|
|
|
this._originalPropertyText = this._treeElement.property.propertyText;
|
|
this._treeElement.parentPane().setEditingStyle(true);
|
|
const uiLocation = Bindings.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().propertyUILocation(
|
|
this._treeElement.property, false /* forName */);
|
|
if (uiLocation) {
|
|
Common.Revealer.reveal(uiLocation, true /* omitFocus */);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {!Common.EventTarget.EventTargetEvent} event
|
|
*/
|
|
_shadowChanged(event) {
|
|
this._shadowSwatch.setCSSShadow(/** @type {!InlineEditor.CSSShadowModel.CSSShadowModel} */ (event.data));
|
|
this._treeElement.applyStyleText(this._treeElement.renderedPropertyText(), false);
|
|
}
|
|
|
|
/**
|
|
* @param {!Event} event
|
|
*/
|
|
_onScroll(event) {
|
|
this._swatchPopoverHelper.reposition();
|
|
}
|
|
|
|
/**
|
|
* @param {boolean} commitEdit
|
|
*/
|
|
_onPopoverHidden(commitEdit) {
|
|
if (this._scrollerElement) {
|
|
this._scrollerElement.removeEventListener('scroll', this._boundOnScroll, false);
|
|
}
|
|
|
|
this._cssShadowEditor.removeEventListener(
|
|
InlineEditor.CSSShadowEditor.Events.ShadowChanged, this._boundShadowChanged);
|
|
delete this._cssShadowEditor;
|
|
|
|
const propertyText = commitEdit ? this._treeElement.renderedPropertyText() : this._originalPropertyText;
|
|
this._treeElement.applyStyleText(propertyText, true);
|
|
this._treeElement.parentPane().setEditingStyle(false);
|
|
delete this._originalPropertyText;
|
|
}
|
|
}
|
|
|
|
ShadowSwatchPopoverHelper._treeElementSymbol = Symbol('ShadowSwatchPopoverHelper._treeElementSymbol');
|