Skip to content
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

♻️ Migrate Style and DOM helpers into core/DOM + type-checking #34681

Merged
merged 28 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
071297f
Split display asserts out of src/style
rcebulko Jun 3, 2021
e741f47
Move src/style to core/dom/style
rcebulko Jun 3, 2021
71beb55
Update eslint rules for style
rcebulko Jun 3, 2021
ef6e24a
Move document-visibility to core
rcebulko Jun 3, 2021
06a18e3
Move full-overlay-frame-helper to ads/inabox
rcebulko Jun 3, 2021
b7e350c
Move utils/size-observer into core/dom
rcebulko Jun 3, 2021
096dfe1
Fix types and externs for size-observer
rcebulko Jun 3, 2021
74d9fa7
Move src/utils/video to core/dom
rcebulko Jun 3, 2021
b9a2606
Move dom/weakref to data-structures/dom-based-weakref
rcebulko Jun 3, 2021
286121a
Make dom/video a submodule
rcebulko Jun 3, 2021
18317e0
Move pause-helper into core/dom/video
rcebulko Jun 3, 2021
c7b2348
Move static-template into core/dom
rcebulko Jun 3, 2021
98fd2c0
Split openWindowDialog out of src/dom
rcebulko Jun 3, 2021
3c9e459
Split amp-element helpers out of dom
rcebulko Jun 7, 2021
8113493
Move dom to src/core
rcebulko Jun 7, 2021
9a195aa
Update presubmits for dom move
rcebulko Jun 7, 2021
ec29de9
Update imports of display asserts
rcebulko Jun 3, 2021
72598b0
Update imports of style
rcebulko Jun 3, 2021
685096d
Update imports of document-visibility
rcebulko Jun 3, 2021
34e53b0
Update imports of size-observer
rcebulko Jun 3, 2021
f8e1f12
Update imports/refs to video
rcebulko Jun 3, 2021
2e97a98
Update imports of pause-helper
rcebulko Jun 3, 2021
27528b5
Update imports of static-template
rcebulko Jun 3, 2021
6912100
Update imports of open-window-dialog
rcebulko Jun 3, 2021
05deeb0
Update imports of dom
rcebulko Jun 3, 2021
8696ff5
Fix zindex
rcebulko Jun 8, 2021
7287fb6
Code review fixes
rcebulko Jun 9, 2021
6645cd5
Lint fixes
rcebulko Jun 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion 3p/3d-gltf/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* global THREE */

import {setStyle} from '../../src/style';
import {setStyle} from '../../src/core/dom/style';
import AnimationLoop from './animation-loop';

const CAMERA_DISTANCE_FACTOR = 1;
Expand Down
2 changes: 1 addition & 1 deletion 3p/beopinion.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {loadScript} from './3p';
import {setStyles} from '../src/style';
import {setStyles} from '../src/core/dom/style';

/**
* Produces the Twitter API object for the passed in callback. If the current
Expand Down
2 changes: 1 addition & 1 deletion 3p/bodymovinanimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {dict} from '../src/core/types/object';
import {getData} from '../src/event-helper';
import {loadScript} from './3p';
import {parseJson} from '../src/core/types/object/json';
import {setStyles} from '../src/style';
import {setStyles} from '../src/core/dom/style';

const libSourceUrl = dict({
'canvas':
Expand Down
2 changes: 1 addition & 1 deletion 3p/embedly.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {hasOwn} from '../src/core/types/object';
import {loadScript} from './3p';
import {setStyle} from '../src/style';
import {setStyle} from '../src/core/dom/style';

/**
* Embedly platform library url to create cards.
Expand Down
2 changes: 1 addition & 1 deletion 3p/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {devAssert} from '../src/log';
import {dict} from '../src/core/types/object';
import {isEnumValue} from '../src/core/types/enum';
import {loadScript} from './3p';
import {setStyle} from '../src/style';
import {setStyle} from '../src/core/dom/style';

/** @const @enum {string} */
export const FacebookEmbedType = {
Expand Down
2 changes: 1 addition & 1 deletion 3p/mathml.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {setStyle} from '../src/style';
import {setStyle} from '../src/core/dom/style';
import {userAssert} from '../src/log';
import {writeScript} from './3p';

Expand Down
2 changes: 1 addition & 1 deletion 3p/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// TODO(malteubl) Move somewhere else since this is not an ad.

import {loadScript} from './3p';
import {setStyles} from '../src/style';
import {setStyles} from '../src/core/dom/style';

/**
* Produces the Twitter API object for the passed in callback. If the current
Expand Down
2 changes: 1 addition & 1 deletion ads/alp/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import {closest} from '../../src/core/dom/query';
import {dev} from '../../src/log';
import {dict} from '../../src/core/types/object';
import {openWindowDialog} from '../../src/dom';
import {openWindowDialog} from '../../src/open-window-dialog';
import {parseQueryString} from '../../src/core/types/string/url';
import {urls} from '../../src/config';

Expand Down
2 changes: 1 addition & 1 deletion ads/google/a4a/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {GEO_IN_GROUP} from '../../../../extensions/amp-geo/0.1/amp-geo-in-group'
import {MockA4AImpl} from '../../../../extensions/amp-a4a/0.1/test/utils';
import {Services} from '../../../../src/services';
import {buildUrl} from '../shared/url-builder';
import {createElementWithAttributes} from '../../../../src/dom';
import {createElementWithAttributes} from '../../../../src/core/dom';
import {createIframePromise} from '../../../../testing/iframe';
import {installDocService} from '../../../../src/service/ampdoc-impl';
import {installExtensionsService} from '../../../../src/service/extensions-impl';
Expand Down
2 changes: 1 addition & 1 deletion ads/google/a4a/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {getPageLayoutBoxBlocking} from '../../../src/core/dom/page-layout-box';
import {getTimingDataSync} from '../../../src/service/variable-source';
import {internalRuntimeVersion} from '../../../src/internal-version';
import {parseJson} from '../../../src/core/types/object/json';
import {whenUpgradedToCustomElement} from '../../../src/dom';
import {whenUpgradedToCustomElement} from '../../../src/amp-element-helpers';

/** @type {string} */
const AMP_ANALYTICS_HEADER = 'X-AmpAnalytics';
Expand Down
8 changes: 6 additions & 2 deletions ads/google/ima/ima-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

import {CONSENT_POLICY_STATE} from '../../../src/core/constants/consent-state';
import {ImaPlayerData} from './ima-player-data';
import {camelCaseToTitleCase, setStyle, toggle} from '../../../src/style';
import {
camelCaseToTitleCase,
setStyle,
toggle,
} from '../../../src/core/dom/style';
import {getData} from '../../../src/event-helper';
import {htmlFor, htmlRefs, svgFor} from '../../../src/static-template';
import {htmlFor, htmlRefs, svgFor} from '../../../src/core/dom/static-template';
import {isArray, isObject} from '../../../src/core/types';
import {loadScript} from '../../../3p/3p';
import {throttle} from '../../../src/core/types/function';
Expand Down
4 changes: 2 additions & 2 deletions ads/inabox/frame-overlay-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
centerFrameUnderVsyncMutate,
collapseFrameUnderVsyncMutate,
expandFrameUnderVsyncMutate,
} from '../../src/full-overlay-frame-helper';
import {resetStyles, setImportantStyles} from '../../src/style';
} from './full-overlay-frame-helper';
import {resetStyles, setImportantStyles} from '../../src/core/dom/style';
import {restrictedVsync, timer} from './util';

const CENTER_TRANSITION_TIME_MS = 150;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {px, resetStyles, setStyles, translate} from './style';
import {px, resetStyles, setStyles, translate} from '../../src/core/dom/style';

/**
* Centers a frame with a translate transition.
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/_fakedelayed_.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';
import {validateData, writeScript} from '../../3p/3p';

/**
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/adspirit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';
import {validateData} from '../../3p/3p';

/**
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/adverticum.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {setStyle} from '../../src/style';
import {setStyle} from '../../src/core/dom/style';
import {validateData, writeScript} from '../../3p/3p';
/**
* @param {!Window} global
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/appnexus.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {loadScript, validateData, writeScript} from '../../3p/3p';
import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';

const APPNEXUS_AST_URL = 'https://acdn.adnxs.com/ast/ast.js';

Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/cedato.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {parseUrlDeprecated} from '../../src/url';
import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';
import {validateData} from '../../3p/3p';

/**
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/csa.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import {devAssert} from '../../src/log';
import {getStyle, setStyle, setStyles} from '../../src/style';
import {getStyle, setStyle, setStyles} from '../../src/core/dom/style';
import {loadScript, validateData} from '../../3p/3p';
import {tryParseJson} from '../../src/core/types/object/json';

Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/feedad.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {loadScript, validateData} from '../../3p/3p';
import {setStyle} from '../../src/style';
import {setStyle} from '../../src/core/dom/style';

/**
* @typedef FeedAdGlobal
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/gumgum.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {loadScript, validateData} from '../../3p/3p';
import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';

/**
* @param {!Window} global
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/inmobi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {setStyle} from '../../src/style';
import {setStyle} from '../../src/core/dom/style';
import {validateData, writeScript} from '../../3p/3p';

/**
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/medyanet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';
import {validateData} from '../../3p/3p';

/**
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/mytarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {loadScript, validateData} from '../../3p/3p';
import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';

/**
* @param {!Window} global
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/ssp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {computeInMasterFrame, loadScript, validateData} from '../../3p/3p';
import {parseJson} from '../../src/core/types/object/json';
import {setStyle, setStyles} from '../../src/style';
import {setStyle, setStyles} from '../../src/core/dom/style';

/*
* How to develop:
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/uas.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {hasOwn} from '../../src/core/types/object';
import {loadScript, validateData} from '../../3p/3p';
import {setStyles} from '../../src/style';
import {setStyles} from '../../src/core/dom/style';

/**
* @param {!Object} theObject
Expand Down
13 changes: 6 additions & 7 deletions build-system/eslint-rules/no-import-rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ const path = require('path');
// otherName()

const imports = {
'src/assert-display': ['assertDoesNotContainDisplay', 'assertNotDisplay'],
'src/core/types/object': ['dict'],
'src/static-template': ['htmlFor'],
'src/experiments': ['isExperimentOn'],
'src/style': [
'assertDoesNotContainDisplay',
'assertNotDisplay',
'src/core/dom/css': ['escapeCssSelectorIdent', 'escapeCssSelectorNth'],
'src/core/dom/query': ['scopedQuerySelector', 'scopedQuerySelectorAll'],
'src/core/dom/static-template': ['htmlFor'],
'src/core/dom/style': [
'resetStyles',
'setImportantStyles',
'setStyle',
'setStyles',
],
'src/core/dom/css': ['escapeCssSelectorIdent', 'escapeCssSelectorNth'],
'src/dom': ['scopedQuerySelector', 'scopedQuerySelectorAll'],
'src/experiments': ['isExperimentOn'],
'src/log': ['user', 'dev'],
'src/mode': ['getMode'],
};
Expand Down
4 changes: 2 additions & 2 deletions build-system/eslint-rules/no-style-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ module.exports = function (context) {

const displayMessage = [
'Do not set the display property using setStyle.',
'Only the `toggle` helper in `src/style.js` is permitted to change the `display: none` style of an element.',
'Only the `toggle` helper in `src/core/dom/style.js` is permitted to change the `display: none` style of an element.',
'Or use `setInitialDisplay` to setup an initial `display: block`, `inline-block`, etc., if it is not possible to do so in CSS.',
].join('\n\t');

return {
[setStyleCall]: function (node) {
const filePath = context.getFilename();
if (filePath.endsWith('src/style.js')) {
if (filePath.endsWith('src/core/dom/style.js')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion build-system/eslint-rules/query-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = function (context) {
'globally and filtered to just the elements inside the element. ' +
'This leads to obscure bugs if you attempt to match a descendant ' +
'of a descendant (ie querySelector("div div")). Instead, use the ' +
'scopedQuerySelector in src/dom.js',
'scopedQuerySelector in src/core/dom/query.js',
});
}

Expand Down
6 changes: 0 additions & 6 deletions build-system/externs/amp.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,6 @@ class FeaturePolicy {
getAllowlistForFeature(feature) {}
}

/** @type {boolean} */
HTMLVideoElement.prototype.playsInline;

/**
* Going through the standardization process now.
*
Expand All @@ -1105,9 +1102,6 @@ HTMLVideoElement.prototype.playsInline;
*/
CSSStyleSheet.prototype.replaceSync = function (cssText) {};

/** @type {?function(!MediaQueryListEvent)} */
MediaQueryList.prototype.onchange;

/** @type {!Array<!CSSStyleSheet>|undefined} */
ShadowRoot.prototype.adoptedStyleSheets;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import '../amp-__component_name_hyphenated__';
import {htmlFor} from '../../../../src/static-template';
import {htmlFor} from '../../../../src/core/dom/static-template';
import {toggleExperiment} from '../../../../src/experiments';
import {waitFor} from '../../../../testing/test-helper';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import '../amp-__component_name_hyphenated__';
import {htmlFor} from '../../../../src/static-template';
import {htmlFor} from '../../../../src/core/dom/static-template';

describes.realWin(
'amp-__component_name_hyphenated__-v__component_version__',
Expand Down
8 changes: 4 additions & 4 deletions build-system/test-configs/conformance-config.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ requirement: {

requirement: {
type: BANNED_PROPERTY_READ
error_message: 'Use getStyle, setStyle, or setStyles in src/style.js'
error_message: 'Use getStyle, setStyle, or setStyles in src/core/dom/style.js'
value: 'Element.prototype.style'
allowlist: 'src/style.js'
allowlist: 'src/core/dom/style.js'
allowlist: 'src/layout.js'
}

Expand All @@ -34,9 +34,9 @@ requirement: {

requirement: {
type: BANNED_PROPERTY_CALL
error_message: 'Use setStyle or setStyles in src/style.js'
error_message: 'Use setStyle or setStyles in src/core/dom/style.js'
value: 'CSSStyleDeclaration.prototype.setProperty'
allowlist: 'src/style.js'
allowlist: 'src/core/dom/style.js'
}

# History
Expand Down
8 changes: 4 additions & 4 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports.rules = [
'3p/**->src/core/types/string/index.js',
'3p/**->src/core/types/string/url.js',
'3p/**->src/log.js',
'3p/**->src/style.js',
'3p/**->src/core/dom/style.js',
'3p/**->src/url.js',
'3p/**->src/config.js',
'3p/**->src/mode.js',
Expand Down Expand Up @@ -133,14 +133,14 @@ exports.rules = [
'ads/**->src/log.js',
'ads/**->src/mode.js',
'ads/**->src/url.js',
'ads/**->src/static-template.js',
'ads/**->src/style.js',
'ads/**->src/core/dom/static-template.js',
'ads/**->src/core/dom/style.js',
'ads/**->src/internal-version.js',
// ads/google/a4a doesn't contain 3P ad code and should probably move
// somewhere else at some point
'ads/google/a4a/**->src/ad-cid.js',
'ads/google/a4a/**->src/consent.js',
'ads/google/a4a/**->src/dom.js',
'ads/google/a4a/**->src/amp-element-helpers.js',
'ads/google/a4a/**->src/experiments/index.js',
'ads/google/a4a/**->src/services.js',
'ads/google/a4a/utils.js->src/service/variable-source.js',
Expand Down
Loading