Skip to content

Shady Parts: improved support for mutations, plus small bugfixes #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 24, 2020
2 changes: 2 additions & 0 deletions packages/shadycss/externs/shadycss-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* flushCustomStyles: function(),
* getComputedStyleValue: function(!Element, string): string,
* onInsertBefore: function(!HTMLElement, !HTMLElement, ?HTMLElement): void,
* onSetAttribute: function(!HTMLElement, !string, !string, ?string): void,
* onRemoveAttribute: function(!HTMLElement, !string): void,
* ScopingShim: (Object|undefined),
* ApplyShim: (Object|undefined),
* CustomStyleInterface: (Object|undefined),
Expand Down
7 changes: 7 additions & 0 deletions packages/shadycss/src/common-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN

import { MIXIN_MATCH, VAR_ASSIGN } from './common-regex.js';

/**
* The prefix used by ShadyDOM for the native version of patched methods
* (e.g. `__shady_native_setAttribute`).
* @type {!string}
*/
export const NATIVE_PREFIX = '__shady_native_';

/**
* @param {Element} element
* @param {Object=} properties
Expand Down
45 changes: 45 additions & 0 deletions packages/shadycss/src/scoping-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,51 @@ export default class ScopingShim {
}
}

/* eslint-disable no-unused-vars */

/**
* Hook for performing ShadyCSS updates after a relevant attribute is set.
* Note ShadyDOM will only call this function for "part" and "exportparts"
* attributes.
*
* @param {!HTMLElement} element Element
* @param {!string} name Attribute name.
* @param {!string} newValue New attribute value.
* @param {?string} oldValue Old attribute value or null if was unset.
* @return {void}
*/
onSetAttribute(element, name, newValue, oldValue) {
if (!disableShadowParts) {
if (name === 'part') {
shadowParts.onSetPartAttribute(element);
} else if (name === 'exportparts') {
shadowParts.onSetExportPartsAttribute(element, newValue, oldValue);
}
}
}

/* eslint-enable no-unused-vars */

/**
* Hook for performing ShadyCSS updates after a relevant attribute is removed.
* Note ShadyDOM will only call this function for "part" and "exportparts"
* attributes.
*
* @param {!HTMLElement} element Element
* @param {!string} name Attribute name.
* @param {!string} oldValue Old attribute value.
* @return {void}
*/
onRemoveAttribute(element, name, oldValue) {
if (!disableShadowParts) {
if (name === 'part') {
shadowParts.onRemovePartAttribute(element);
} else if (name === 'exportparts') {
shadowParts.onRemoveExportPartsAttribute(element, oldValue);
}
}
}

/**
* Apply styles for the given element
*
Expand Down
Loading