Skip to content

Commit

Permalink
♻️ Move builtins/ under src/ (ampproject#35139)
Browse files Browse the repository at this point in the history
* builtins/ -> src/builtins/

* Move builtins into src

* Update presubmit configs

* Update imports into src

* Fix Markdown links

* Whitespace

* Enable import/order in builtins

* Lint autofix
  • Loading branch information
rcebulko authored Jul 12, 2021
1 parent 1594e79 commit 9ec218b
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion build-system/tasks/storybook/amp-env/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

module.exports = {
stories: [
'../../../../builtins/storybook/*.amp.js',
'../../../../src/builtins/storybook/*.amp.js',
'../../../../extensions/**/*.*/storybook/*.amp.js',
],
addons: [
Expand Down
2 changes: 1 addition & 1 deletion build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ exports.rules = [
filesMatching: '**/*.js',
mustNotDependOn: 'src/service/custom-element-registry.js',
allowlist: [
'builtins/**->src/service/custom-element-registry.js',
'src/builtins/**->src/service/custom-element-registry.js',
'src/amp.js->src/service/custom-element-registry.js',
'src/runtime.js->src/service/custom-element-registry.js',
'src/service/extensions-impl.js->src/service/custom-element-registry.js',
Expand Down
2 changes: 1 addition & 1 deletion build-system/test-configs/forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ const forbiddenTermsSrcInclusive = {
message: measurementApiDeprecated,
allowlist: [
'build-system/externs/amp.extern.js',
'builtins/amp-img/amp-img.js',
'src/builtins/amp-img/amp-img.js',
'src/base-element.js',
'src/custom-element.js',
'src/iframe-helper.js',
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/amp-html-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ In these cases, services may set up endpoints that produce data that conforms to

## Components

Built-in components include [amp-img](../../builtins/amp-img/amp-img.md), [amp-layout](../../builtins/amp-layout/amp-layout.md) and [amp-pixel](../../builtins/amp-pixel/amp-pixel.md).
Built-in components include [amp-img](../../src/builtins/amp-img/amp-img.md), [amp-layout](../../src/builtins/amp-layout/amp-layout.md) and [amp-pixel](../../src/builtins/amp-pixel/amp-pixel.md).

AMP HTML extensions include [extended components](../../extensions) and extended templates.
16 changes: 8 additions & 8 deletions docs/spec/amp-var-substitutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following table lists the features that enable variable substitutions, as we
<td width="25%">None</td>
</tr>
<tr>
<td width="25%"><code>amp-pixel</code><br><a href="/ampproject/amphtml/blob/main/builtins/amp-pixel/amp-pixel.md#substitutions">Detailed documentation</a></td>
<td width="25%"><code>amp-pixel</code><br><a href="/ampproject/amphtml/blob/main/src/builtins/amp-pixel/amp-pixel.md#substitutions">Detailed documentation</a></td>
<td width="25%">Requests must be HTTPS URLs (not a requirement specific to variable substitutions)</td>
<td width="25%">No</td>
<td width="25%">None</td>
Expand Down Expand Up @@ -499,7 +499,7 @@ Provides the `amp-carousel` slide from which the traversal happens. The value is
- **platform variable**: N/A
- **amp-analytics variable**: `${fromSlide}`

For more information on analytics for `amp-carousel`, see [AMP Carousel and Analytics](../extensions/amp-carousel/amp-carousel-analytics.md).
For more information on analytics for `amp-carousel`, see [AMP Carousel and Analytics](../../extensions/amp-carousel/amp-carousel-analytics.md).

#### Carousel To Slide

Expand All @@ -508,7 +508,7 @@ Provides the `amp-carousel` slide to which the traversal happens. The value is e
- **platform variable**: N/A
- **amp-analytics variable**: `${toSlide}`

For more information on analytics for `amp-carousel`, see [AMP Carousel and Analytics](../extensions/amp-carousel/amp-carousel-analytics.md).
For more information on analytics for `amp-carousel`, see [AMP Carousel and Analytics](../../extensions/amp-carousel/amp-carousel-analytics.md).

#### Client ID

Expand Down Expand Up @@ -549,7 +549,7 @@ Provides a per document-source-origin (the origin of the website where you publi
You can pass the following arguments into the Client ID variable like a function. Spaces between arguments and values are not allowed.

- `cid scope` (Required): The namespace for the Client ID.
- `amp-user-notification id` (Optional): Use this argument to make the Client ID substitution dependent on the dismissal of a user notification shown to the visitor of the page. In amp-analytics, this is the same as using the [`data-consent-notification-id`](../extensions/amp-analytics/amp-analytics.md) attribute -- you may choose to use either one for the amp-analytics component.
- `amp-user-notification id` (Optional): Use this argument to make the Client ID substitution dependent on the dismissal of a user notification shown to the visitor of the page. In amp-analytics, this is the same as using the [`data-consent-notification-id`](../../extensions/amp-analytics/amp-analytics.md) attribute -- you may choose to use either one for the amp-analytics component.
- `cookie name` (Optional): The name of the fallback cookie when the document is not served by an AMP proxy. If not provided, `cid scope` will be used as the cookie name.
- `disable backup` (Optional): If set to `true`, then will opt-out of storing the AMP generated CID in Storage as a backup when the document is not served by an AMP proxy. Otherwise, will default into this behavior.

Expand Down Expand Up @@ -700,7 +700,7 @@ Analytics vendor might prefer this value to Document Referrer for better session

#### Extra URL Parameters

Provides all the parameters that are defined in the [`extraUrlParams`](../extensions/amp-analytics/amp-analytics.md#extra-url-params) block of the amp-analytics config as a variable. If you use the `extraUrlParams` variable, the parameters are not appended to the end of the URL.
Provides all the parameters that are defined in the [`extraUrlParams`](../../extensions/amp-analytics/amp-analytics.md#extra-url-params) block of the amp-analytics config as a variable. If you use the `extraUrlParams` variable, the parameters are not appended to the end of the URL.

- **platform variable**: N/A
- **amp-analytics variable**: `${extraUrlParams}`
Expand All @@ -722,7 +722,7 @@ Provides the time when the element met visibility conditions for the first time

#### Geolocation

Provides the approximate, country level, location of the user provided by the [`amp-geo`](../extensions/amp-geo/amp-geo.md#variable-substitution) extension.
Provides the approximate, country level, location of the user provided by the [`amp-geo`](../../extensions/amp-geo/amp-geo.md#variable-substitution) extension.

- **platform variable**: AMP_GEO
- Example: <br>
Expand Down Expand Up @@ -1211,15 +1211,15 @@ Provides the user's IANA time-zone code (if available).

#### Total Engaged Time

Provides the total time (in seconds) the user has been engaged with the page since the page first became visible in the viewport. Total engaged time will be 0 until the page first becomes visible. This variable requires the [amp-analytics](../extensions/amp-analytics/amp-analytics.md) extension to be present on the page.
Provides the total time (in seconds) the user has been engaged with the page since the page first became visible in the viewport. Total engaged time will be 0 until the page first becomes visible. This variable requires the [amp-analytics](../../extensions/amp-analytics/amp-analytics.md) extension to be present on the page.

- **platform variable**: `TOTAL_ENGAGED_TIME`
- **amp-analytics variable**: `${totalEngagedTime}`
- Example value: `36`

#### Incremental Engaged Time

Provides the time (in seconds) the user has been engaged with the page since the last time it was reset. It takes two arguments. The first is the name of the timer, the second is whether or not to reset it (it is optional and defaults to true). Incremental engaged time will be 0 until the page first becomes visible. This variable requires the [amp-analytics](../extensions/amp-analytics/amp-analytics.md) extension to be present on the page.
Provides the time (in seconds) the user has been engaged with the page since the last time it was reset. It takes two arguments. The first is the name of the timer, the second is whether or not to reset it (it is optional and defaults to true). Incremental engaged time will be 0 until the page first becomes visible. This variable requires the [amp-analytics](../../extensions/amp-analytics/amp-analytics.md) extension to be present on the page.

- **platform variable**: `INCREMENTAL_ENGAGED_TIME`
- **amp-analytics variable**: `${incrementalEngagedTime(foo,false)}`
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-bind/amp-bind.md
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ Some AMP components and HTML elements have specific bindable attributes. They ar
- `[src]`
- `[srcset]`

Bind to `[srcset]` instead of `[src]` to support responsive images. See corresponding [`amp-img` attributes](../../builtins/amp-img/amp-img.md#attributes).
Bind to `[srcset]` instead of `[src]` to support responsive images. See corresponding [`amp-img` attributes](../../src/builtins/amp-img/amp-img.md#attributes).
[/filter] <!-- formats="websites, ads" -->
[filter formats="email"]

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-nested-menu/amp-nested-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ limitations under the License.

The `<amp-nested-menu>` component must be placed inside `<amp-sidebar>`. The component may contain the following AMP elements:

- [`<amp-img>`](../../builtins/amp-img/amp-img.md)
- [`<amp-img>`](../../src/builtins/amp-img/amp-img.md)
- [`<amp-list>`](../amp-list/amp-list.md)
- [`<amp-accordion>`](../amp-accordion/amp-accordion.md)

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-next-page/0.1/amp-next-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ component will render a maximum of three documents (total) on screen at one sing

[tip type="important"]
**Important** [`<amp-analytics>`](../../amp-analytics/amp-analytics.md) is [currently unsupported](https://github.com/ampproject/amphtml/issues/15807) on pages users land on through `<amp-next-page>`.
Tracking page views is supported through [`<amp-pixel>`](../../../builtins/amp-pixel/amp-pixel.md) or `<amp-analytics>` on the host page.
Tracking page views is supported through [`<amp-pixel>`](../../../src/builtins/amp-pixel/amp-pixel.md) or `<amp-analytics>` on the host page.
[/tip]

### Configuration spec
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-next-page/amp-next-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ Each document loads with a full-width gray horizontal line to separate it from t
The `<amp-next-page>` component supports analytics on the hosted page as well as on subsequently loaded articles. We recommend using the same analytics triggers used on standalone articles, including scroll-bound triggers.

[tip type="important"]
Tracking page views is supported through [`<amp-pixel>`](../../builtins/amp-pixel/amp-pixel.md) or `<amp-analytics>` on the host page. It is recommended to use the `useInitialPageSize` property of `<amp-analytics>` to get a more accurate measurement of the scroll triggers otherwise the host page's `100%` trigger point would only be fired after the user scrolled past all sub-documents. Note that this will also ignore the size changes caused by other extensions (such as expanding embedded content) so some scroll events might fire prematurely instead.
Tracking page views is supported through [`<amp-pixel>`](../../src/builtins/amp-pixel/amp-pixel.md) or `<amp-analytics>` on the host page. It is recommended to use the `useInitialPageSize` property of `<amp-analytics>` to get a more accurate measurement of the scroll triggers otherwise the host page's `100%` trigger point would only be fired after the user scrolled past all sub-documents. Note that this will also ignore the size changes caused by other extensions (such as expanding embedded content) so some scroll events might fire prematurely instead.
[/tip]

Two custom analytics events are also provided on the host page to indicate transitioning between pages. These events can be tracked in the [amp-analytics](https://amp.dev/documentation/components/amp-analytics) config as follows:
Expand Down
9 changes: 3 additions & 6 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ module.exports = {
'rules': {'import/no-nodejs-modules': 0},
},
{
'files': [
'core/**/*.js',
'preact/**/*.js',
],
'rules': {'import/order': 2}
}
'files': ['builtins/**/*.js', 'core/**/*.js', 'preact/**/*.js'],
'rules': {'import/order': 2},
},
],
};
File renamed without changes.
16 changes: 9 additions & 7 deletions builtins/amp-img/amp-img.js → src/builtins/amp-img/amp-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
* limitations under the License.
*/

import {BaseElement} from '../../src/base-element';
import {Layout, applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {ReadyState} from '#core/constants/ready-state';
import {Services} from '#service';
import {dev} from '../../src/log';
import {removeElement} from '#core/dom';
import {guaranteeSrcForSrcsetUnsupportedBrowsers} from '#core/dom/img';
import {listen} from '../../src/event-helper';
import {Layout, applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {propagateAttributes} from '#core/dom/propagate-attributes';
import {scopedQuerySelector} from '#core/dom/query';
import {propagateObjectFitStyles, setImportantStyles} from '#core/dom/style';

import {Services} from '#service';
import {registerElement} from '#service/custom-element-registry';
import {removeElement} from '#core/dom';
import {scopedQuerySelector} from '#core/dom/query';

import {BaseElement} from '../../base-element';
import {listen} from '../../event-helper';
import {dev} from '../../log';

/** @const {string} */
const TAG = 'amp-img';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ the `layout` attribute.
[tip type="read-on"]

Learn more about layouts in the
[AMP HTML Layout System](../../docs/spec/amp-html-layout.md)
[AMP HTML Layout System](../../../docs/spec/amp-html-layout.md)
spec and
[Supported Layouts](https://amp.dev/documentation/guides-and-tutorials/develop/style_and_layout/control_layout.html#the-layout-attribute).

Expand Down Expand Up @@ -362,7 +362,7 @@ amp-img {
[filter formats="email"]

Enable a lightbox effect on `amp-img` in email by using the
[`amp-image-lightbox`](../../extensions/amp-image-lightbox/amp-image-lightbox.md)
[`amp-image-lightbox`](../../../extensions/amp-image-lightbox/amp-image-lightbox.md)
component with the `on` action.

[/filter] <!-- formats="email" -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

import {BaseElement} from '../../src/base-element';
import {Layout, applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {realChildNodes} from '#core/dom/query';

import {registerElement} from '#service/custom-element-registry';

import {BaseElement} from '../../base-element';

class AmpLayout extends BaseElement {
/** @override @nocollapse */
static prerenderAllowed() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {BaseElement} from '../../src/base-element';
import {Services} from '#service';
import {createPixel} from '../../src/pixel';
import {dev, userAssert} from '../../src/log';
import {registerElement} from '#service/custom-element-registry';

import {BaseElement} from '../../base-element';
import {dev, userAssert} from '../../log';
import {createPixel} from '../../pixel';

const TAG = 'amp-pixel';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ When processing AMP URLs in the referrer header of analytics requests, strip out
### Substitutions

The `amp-pixel` allows all standard URL variable substitutions.
See the [Substitutions Guide](../../docs/spec/amp-var-substitutions.md) for more information.
See the [Substitutions Guide](../../../docs/spec/amp-var-substitutions.md) for more information.

In the following example, a request might be made to something like `https://foo.com/pixel?0.8390278471201` where the RANDOM value is randomly generated upon each impression.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

import * as Preact from '#preact';
import {number, withKnobs} from '@storybook/addon-knobs';
import {withAmp} from '@ampproject/storybook-addon';
import {number, withKnobs} from '@storybook/addon-knobs';

import * as Preact from '#preact';

export default {
title: '0/amp-layout with aspect ratio CSS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

import * as Preact from '#preact';
import {number, withKnobs} from '@storybook/addon-knobs';
import {withAmp} from '@ampproject/storybook-addon';
import {number, withKnobs} from '@storybook/addon-knobs';

import * as Preact from '#preact';

export default {
title: '0/amp-layout',
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"#3p/*": ["./3p/*"],
"#ads/*": ["./ads/*"],
"#build/*": ["./build/*"],
"#builtins/*": ["./builtins/*"],

"#builtins/*": ["./src/builtins/*"],
"#core/*": ["./src/core/*"],
"#experiments/*": ["./src/experiments/*"],
"#inabox/*": ["./src/inabox/*"],
Expand Down

0 comments on commit 9ec218b

Please sign in to comment.