@next/third-parties 13.5.6-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/ThirdPartyScriptEmbed.d.ts +9 -0
- package/dist/ThirdPartyScriptEmbed.js +15 -0
- package/dist/google/google-maps-embed.d.ts +3 -0
- package/dist/google/google-maps-embed.js +15 -0
- package/dist/google/gtm.d.ts +17 -0
- package/dist/google/gtm.js +44 -0
- package/dist/google/index.d.ts +3 -0
- package/dist/google/index.js +13 -0
- package/dist/google/youtube-embed.d.ts +3 -0
- package/dist/google/youtube-embed.js +20 -0
- package/dist/types/google.d.ts +21 -0
- package/dist/types/google.js +2 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Experimental `@next/third-parties`
|
|
2
|
+
|
|
3
|
+
`@next/third-parties` is a collection of components and utilities that can be used to efficiently load third-party libraries into your Next.js application.
|
|
4
|
+
|
|
5
|
+
> Note: `@next/third-parties` is still experimental and under active development.
|
|
6
|
+
|
|
7
|
+
# Usage
|
|
8
|
+
|
|
9
|
+
## Google Third-Parties
|
|
10
|
+
|
|
11
|
+
### YouTube Embed
|
|
12
|
+
|
|
13
|
+
The `YouTubeEmbed` component is used to load and display a YouTube embed. This component loads faster by using [lite-youtube-embed](https://github.com/paulirish/lite-youtube-embed) under the hood.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { YouTubeEmbed } from '@next/third-parties/google'
|
|
17
|
+
|
|
18
|
+
export default function Page() {
|
|
19
|
+
return <YouTubeEmbed videoid="ogfYd705cRs" height={400} />
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Google Maps Embed
|
|
24
|
+
|
|
25
|
+
The `GoogleMapsEmbed` component can be used to add a [Google Maps Embed](https://developers.google.com/maps/documentation/embed/get-started) to your page. By default, it uses the `loading` attribute to lazy-load below the fold.
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { GoogleMapsEmbed } from '@next/third-parties/google'
|
|
29
|
+
|
|
30
|
+
export default function Page() {
|
|
31
|
+
return (
|
|
32
|
+
<GoogleMapsEmbed
|
|
33
|
+
apiKey="XYZ"
|
|
34
|
+
height={200}
|
|
35
|
+
width="100%"
|
|
36
|
+
mode="place"
|
|
37
|
+
q="Brooklyn+Bridge,New+York,NY"
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To get a better idea of how these components work, take a look at this [demo](https://test-next-script-housseindjirdeh.vercel.app/). <!--- TODO: Replace with a better demo page -->
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type ScriptEmbed = {
|
|
3
|
+
html?: string | null;
|
|
4
|
+
height?: number | null;
|
|
5
|
+
width?: number | null;
|
|
6
|
+
children?: React.ReactElement | React.ReactElement[];
|
|
7
|
+
dataNtpc?: string;
|
|
8
|
+
};
|
|
9
|
+
export default function ThirdPartyScriptEmbed({ html, height, width, children, dataNtpc, }: ScriptEmbed): React.JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
function ThirdPartyScriptEmbed({ html, height = null, width = null, children, dataNtpc = '', }) {
|
|
8
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
9
|
+
children,
|
|
10
|
+
html ? (react_1.default.createElement("div", { style: {
|
|
11
|
+
height: height != null ? `${height}px` : 'auto',
|
|
12
|
+
width: width != null ? `${width}px` : 'auto',
|
|
13
|
+
}, "data-ntpc": dataNtpc, dangerouslySetInnerHTML: { __html: html } })) : null));
|
|
14
|
+
}
|
|
15
|
+
exports.default = ThirdPartyScriptEmbed;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const third_party_capital_1 = require("third-party-capital");
|
|
8
|
+
const ThirdPartyScriptEmbed_1 = __importDefault(require("../ThirdPartyScriptEmbed"));
|
|
9
|
+
function GoogleMapsEmbed(props) {
|
|
10
|
+
const { apiKey, ...restProps } = props;
|
|
11
|
+
const formattedProps = { ...restProps, key: apiKey };
|
|
12
|
+
const { html } = (0, third_party_capital_1.GoogleMapsEmbed)(formattedProps);
|
|
13
|
+
return (react_1.default.createElement(ThirdPartyScriptEmbed_1.default, { height: formattedProps.height || null, width: formattedProps.width || null, html: html, dataNtpc: "GoogleMapsEmbed" }));
|
|
14
|
+
}
|
|
15
|
+
exports.default = GoogleMapsEmbed;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
dataLayer?: Object[];
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
type GTMParams = {
|
|
9
|
+
gtmId: string;
|
|
10
|
+
dataLayer: string[];
|
|
11
|
+
dataLayerName: string;
|
|
12
|
+
auth: string;
|
|
13
|
+
preview: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function GoogleTagManager(props: GTMParams): React.JSX.Element;
|
|
16
|
+
export declare const sendGTMEvent: (data: Object) => void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.sendGTMEvent = exports.GoogleTagManager = void 0;
|
|
8
|
+
// TODO: Evaluate import 'client only'
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const script_1 = __importDefault(require("next/script"));
|
|
11
|
+
let currDataLayerName = undefined;
|
|
12
|
+
function GoogleTagManager(props) {
|
|
13
|
+
const { gtmId, dataLayerName = 'dataLayer', auth, preview, dataLayer } = props;
|
|
14
|
+
if (currDataLayerName === undefined) {
|
|
15
|
+
currDataLayerName = dataLayerName;
|
|
16
|
+
}
|
|
17
|
+
const gtmLayer = dataLayerName !== 'dataLayer' ? `$l=${dataLayerName}` : '';
|
|
18
|
+
const gtmAuth = auth ? `>m_auth=${auth}` : '';
|
|
19
|
+
const gtmPreview = preview ? `>m_preview=${preview}>m_cookies_win=x` : '';
|
|
20
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
21
|
+
react_1.default.createElement(script_1.default, { id: "_next-gtm-init", dangerouslySetInnerHTML: {
|
|
22
|
+
__html: `
|
|
23
|
+
(function(w,l){
|
|
24
|
+
w[l]=w[l]||[];
|
|
25
|
+
w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});
|
|
26
|
+
${dataLayer ? `w[l].push(${JSON.stringify(dataLayer)})` : ''}
|
|
27
|
+
})(window,'${dataLayerName}');`,
|
|
28
|
+
} }),
|
|
29
|
+
react_1.default.createElement(script_1.default, { id: "_next-gtm", src: `https://www.googletagmanager.com/gtm.js?id=${gtmId}${gtmLayer}${gtmAuth}${gtmPreview}` })));
|
|
30
|
+
}
|
|
31
|
+
exports.GoogleTagManager = GoogleTagManager;
|
|
32
|
+
const sendGTMEvent = (data) => {
|
|
33
|
+
if (currDataLayerName === undefined) {
|
|
34
|
+
console.warn(`@next/third-parties: GTM has not been initialized`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (window[currDataLayerName]) {
|
|
38
|
+
window[currDataLayerName].push(data);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.warn(`@next/third-parties: GTM dataLayer ${currDataLayerName} does not exist`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.sendGTMEvent = sendGTMEvent;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendGTMEvent = exports.GoogleTagManager = exports.YouTubeEmbed = exports.GoogleMapsEmbed = void 0;
|
|
7
|
+
var google_maps_embed_1 = require("./google-maps-embed");
|
|
8
|
+
Object.defineProperty(exports, "GoogleMapsEmbed", { enumerable: true, get: function () { return __importDefault(google_maps_embed_1).default; } });
|
|
9
|
+
var youtube_embed_1 = require("./youtube-embed");
|
|
10
|
+
Object.defineProperty(exports, "YouTubeEmbed", { enumerable: true, get: function () { return __importDefault(youtube_embed_1).default; } });
|
|
11
|
+
var gtm_1 = require("./gtm");
|
|
12
|
+
Object.defineProperty(exports, "GoogleTagManager", { enumerable: true, get: function () { return gtm_1.GoogleTagManager; } });
|
|
13
|
+
Object.defineProperty(exports, "sendGTMEvent", { enumerable: true, get: function () { return gtm_1.sendGTMEvent; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const script_1 = __importDefault(require("next/script"));
|
|
8
|
+
const third_party_capital_1 = require("third-party-capital");
|
|
9
|
+
const ThirdPartyScriptEmbed_1 = __importDefault(require("../ThirdPartyScriptEmbed"));
|
|
10
|
+
const scriptStrategy = {
|
|
11
|
+
server: 'beforeInteractive',
|
|
12
|
+
client: 'afterInteractive',
|
|
13
|
+
idle: 'lazyOnload',
|
|
14
|
+
worker: 'worker',
|
|
15
|
+
};
|
|
16
|
+
function YouTubeEmbed(props) {
|
|
17
|
+
const { html, scripts, stylesheets } = (0, third_party_capital_1.YouTubeEmbed)(props);
|
|
18
|
+
return (react_1.default.createElement(ThirdPartyScriptEmbed_1.default, { height: props.height || null, width: props.width || null, html: html, dataNtpc: "YouTubeEmbed" }, scripts === null || scripts === void 0 ? void 0 : scripts.map((script) => (react_1.default.createElement(script_1.default, { src: script.url, strategy: scriptStrategy[script.strategy], stylesheets: stylesheets })))));
|
|
19
|
+
}
|
|
20
|
+
exports.default = YouTubeEmbed;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type GoogleMapsEmbed = {
|
|
2
|
+
height?: number;
|
|
3
|
+
width?: number;
|
|
4
|
+
mode: 'place' | 'view' | 'directions' | 'streetview' | 'search';
|
|
5
|
+
apiKey: string;
|
|
6
|
+
style: string;
|
|
7
|
+
allowfullscreen: boolean;
|
|
8
|
+
loading: 'eager' | 'lazy';
|
|
9
|
+
q?: string;
|
|
10
|
+
center?: string;
|
|
11
|
+
zoom?: string;
|
|
12
|
+
maptype?: string;
|
|
13
|
+
language?: string;
|
|
14
|
+
region?: string;
|
|
15
|
+
};
|
|
16
|
+
export type YouTubeEmbed = {
|
|
17
|
+
height?: number;
|
|
18
|
+
width?: number;
|
|
19
|
+
videoid: string;
|
|
20
|
+
playlabel?: string;
|
|
21
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@next/third-parties",
|
|
3
|
+
"version": "13.5.6-canary.4",
|
|
4
|
+
"repository": {
|
|
5
|
+
"url": "vercel/next.js",
|
|
6
|
+
"directory": "packages/third-parties"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
"./google": "./dist/google/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "node ../../scripts/rm.mjs dist && tsc -d -p tsconfig.json",
|
|
17
|
+
"prepublishOnly": "cd ../../ && turbo run build",
|
|
18
|
+
"dev": "tsc -d -w -p tsconfig.json",
|
|
19
|
+
"typescript": "tsec --noEmit -p tsconfig.json"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"third-party-capital": "1.0.20"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"next": "13.5.6-canary.4",
|
|
26
|
+
"outdent": "0.8.0",
|
|
27
|
+
"prettier": "2.5.1"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"next": "^13.0.0",
|
|
31
|
+
"react": "^18.2.0"
|
|
32
|
+
}
|
|
33
|
+
}
|