react-datocms 7.0.3 → 8.0.0-1
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 +1 -1
- package/dist/cjs/VideoPlayer/index.js +7 -7
- package/dist/cjs/VideoPlayer/index.js.map +1 -1
- package/dist/cjs/VideoPlayer/lazy.js +35 -0
- package/dist/cjs/VideoPlayer/lazy.js.map +1 -0
- package/dist/esm/VideoPlayer/index.js +9 -9
- package/dist/esm/VideoPlayer/index.js.map +1 -1
- package/dist/esm/VideoPlayer/lazy.js +9 -0
- package/dist/esm/VideoPlayer/lazy.js.map +1 -0
- package/dist/types/VideoPlayer/index.d.ts +6 -4
- package/dist/types/VideoPlayer/lazy.d.ts +6 -0
- package/package.json +11 -3
- package/src/VideoPlayer/index.tsx +19 -14
- package/src/VideoPlayer/lazy.tsx +26 -0
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ This package offers different components and hooks. Please refer to one of the f
|
|
|
26
26
|
|
|
27
27
|
* [`<SRCImage />` and `<Image />` components for responsive/progressive images](./docs/image.md)
|
|
28
28
|
* [`<StructuredText />` component](./docs/structured-text.md)
|
|
29
|
-
* [`<VideoPlayer />` component](./docs/video-player.md)
|
|
29
|
+
* [`<VideoPlayer />` component](./docs/video-player.md) (lazy version available)
|
|
30
30
|
* [`useQuerySubscription()` hook for live, real-time updates of content](./docs/live-real-time-updates.md)
|
|
31
31
|
* [`useSiteSearch()` hook to render a DatoCMS Site Search form widget](./docs/site-search.md)
|
|
32
32
|
* [`renderMetaTags()` and other helpers to render social share, SEO and Favicon meta tags](./docs/meta-tags.md)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
"use client";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -48,20 +48,20 @@ exports.VideoPlayer = void 0;
|
|
|
48
48
|
// [1]: https://www.mux.com/player
|
|
49
49
|
const react_1 = __importStar(require("react"));
|
|
50
50
|
// React MUX player is made available in two flavours: eager and lazy loaded. We
|
|
51
|
-
// choose to use the
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
const lazy_1 = __importDefault(require("@mux/mux-player-react/lazy"));
|
|
51
|
+
// choose to use the eager loading version as the default approch, but
|
|
52
|
+
// we also provide a lazy loading version..
|
|
53
|
+
const mux_player_react_1 = __importDefault(require("@mux/mux-player-react"));
|
|
55
54
|
// The core of this component is the `useVideoPlayer` hook: it takes
|
|
56
55
|
// data from DatoCMS GraphQL API and returns props as expected by the
|
|
57
56
|
// `<MuxPlayer />` component.
|
|
58
57
|
const index_js_1 = require("../useVideoPlayer/index.js");
|
|
59
58
|
exports.VideoPlayer = (0, react_1.forwardRef)((props, ref) => {
|
|
60
|
-
const { data = {}, disableCookies = true, preload =
|
|
59
|
+
const { data = {}, disableCookies = true, disableTracking = true, preload = "metadata", style: styleFromProps } = props, rest = __rest(props, ["data", "disableCookies", "disableTracking", "preload", "style"]);
|
|
61
60
|
const { title, playbackId, style: styleFromHook, placeholder, } = (0, index_js_1.useVideoPlayer)({
|
|
62
61
|
data,
|
|
63
62
|
});
|
|
64
63
|
const style = Object.assign(Object.assign({}, styleFromHook), styleFromProps);
|
|
65
|
-
return (react_1.default.createElement(
|
|
64
|
+
return (react_1.default.createElement(mux_player_react_1.default, Object.assign({ ref: ref, streamType: "on-demand", preload: preload, title: title, disableCookies: disableCookies, disableTracking: disableTracking, playbackId: playbackId, style: style, placeholder: placeholder }, rest)));
|
|
66
65
|
});
|
|
66
|
+
exports.default = exports.VideoPlayer;
|
|
67
67
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/VideoPlayer/index.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;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AAK,EACZ,WAAW,EAAE,WAAW,IACpB,IAAI,EACR,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,kBAAe,mBAAW,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.VideoPlayer = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
const LazyLoadedVideoPlayer = react_1.default.lazy(() => Promise.resolve().then(() => __importStar(require("./index.js"))));
|
|
29
|
+
exports.VideoPlayer = (0, react_1.forwardRef)((props, ref) => {
|
|
30
|
+
const { className, style } = props;
|
|
31
|
+
return (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement("div", { className: className, style: style }) },
|
|
32
|
+
react_1.default.createElement(LazyLoadedVideoPlayer, Object.assign({}, props, { ref: ref }))));
|
|
33
|
+
});
|
|
34
|
+
exports.default = exports.VideoPlayer;
|
|
35
|
+
//# sourceMappingURL=lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../../../src/VideoPlayer/lazy.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAoD;AAMpD,MAAM,qBAAqB,GAAG,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,mDAAQ,YAAY,GAAC,CAAC,CAAC;AAMxD,QAAA,WAAW,GAAoB,IAAA,kBAAU,EAGpD,CAAC,KAAuB,EAAE,GAAG,EAAE,EAAE;IACjC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAEnC,OAAO,CACL,8BAAC,gBAAQ,IAAC,QAAQ,EAAE,uCAAK,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAI;QAC7D,8BAAC,qBAAqB,oBAAK,KAAK,IAAE,GAAG,EAAE,GAAG,IAAI,CACrC,CACZ,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,kBAAe,mBAAW,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
3
|
var t = {};
|
|
4
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -17,22 +17,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
17
17
|
// The React player written by MUX is an adapter for a web component.
|
|
18
18
|
//
|
|
19
19
|
// [1]: https://www.mux.com/player
|
|
20
|
-
import React, { forwardRef } from
|
|
20
|
+
import React, { forwardRef } from "react";
|
|
21
21
|
// React MUX player is made available in two flavours: eager and lazy loaded. We
|
|
22
|
-
// choose to use the
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
import MuxPlayer from '@mux/mux-player-react/lazy';
|
|
22
|
+
// choose to use the eager loading version as the default approch, but
|
|
23
|
+
// we also provide a lazy loading version..
|
|
24
|
+
import MuxPlayer from "@mux/mux-player-react";
|
|
26
25
|
// The core of this component is the `useVideoPlayer` hook: it takes
|
|
27
26
|
// data from DatoCMS GraphQL API and returns props as expected by the
|
|
28
27
|
// `<MuxPlayer />` component.
|
|
29
|
-
import { useVideoPlayer } from
|
|
28
|
+
import { useVideoPlayer } from "../useVideoPlayer/index.js";
|
|
30
29
|
export const VideoPlayer = forwardRef((props, ref) => {
|
|
31
|
-
const { data = {}, disableCookies = true, preload =
|
|
30
|
+
const { data = {}, disableCookies = true, disableTracking = true, preload = "metadata", style: styleFromProps } = props, rest = __rest(props, ["data", "disableCookies", "disableTracking", "preload", "style"]);
|
|
32
31
|
const { title, playbackId, style: styleFromHook, placeholder, } = useVideoPlayer({
|
|
33
32
|
data,
|
|
34
33
|
});
|
|
35
34
|
const style = Object.assign(Object.assign({}, styleFromHook), styleFromProps);
|
|
36
|
-
return (React.createElement(MuxPlayer, Object.assign({ ref: ref, streamType: "on-demand", preload: preload, title: title, disableCookies: disableCookies, playbackId: playbackId, style: style, placeholder: placeholder }, rest)));
|
|
35
|
+
return (React.createElement(MuxPlayer, Object.assign({ ref: ref, streamType: "on-demand", preload: preload, title: title, disableCookies: disableCookies, disableTracking: disableTracking, playbackId: playbackId, style: style, placeholder: placeholder }, rest)));
|
|
37
36
|
});
|
|
37
|
+
export default VideoPlayer;
|
|
38
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/VideoPlayer/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,gFAAgF;AAChF,8EAA8E;AAC9E,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UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,IACpB,IAAI,EACR,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React, { Suspense, forwardRef } from "react";
|
|
2
|
+
const LazyLoadedVideoPlayer = React.lazy(() => import("./index.js"));
|
|
3
|
+
export const VideoPlayer = forwardRef((props, ref) => {
|
|
4
|
+
const { className, style } = props;
|
|
5
|
+
return (React.createElement(Suspense, { fallback: React.createElement("div", { className: className, style: style }) },
|
|
6
|
+
React.createElement(LazyLoadedVideoPlayer, Object.assign({}, props, { ref: ref }))));
|
|
7
|
+
});
|
|
8
|
+
export default VideoPlayer;
|
|
9
|
+
//# sourceMappingURL=lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../../../src/VideoPlayer/lazy.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAMpD,MAAM,qBAAqB,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;AAMrE,MAAM,CAAC,MAAM,WAAW,GAAoB,UAAU,CAGpD,CAAC,KAAuB,EAAE,GAAG,EAAE,EAAE;IACjC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAEnC,OAAO,CACL,oBAAC,QAAQ,IAAC,QAAQ,EAAE,6BAAK,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAI;QAC7D,oBAAC,qBAAqB,oBAAK,KAAK,IAAE,GAAG,EAAE,GAAG,IAAI,CACrC,CACZ,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type MuxPlayerElement from "@mux/mux-player";
|
|
3
|
+
import type { MuxPlayerProps } from "@mux/mux-player-react";
|
|
3
4
|
type Maybe<T> = T | null;
|
|
4
5
|
type Possibly<T> = Maybe<T> | undefined;
|
|
5
6
|
export type Video = {
|
|
@@ -22,5 +23,6 @@ export type VideoPlayerProps = MuxPlayerProps & {
|
|
|
22
23
|
/** The actual response you get from a DatoCMS `video` GraphQL query */
|
|
23
24
|
data?: Video;
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
-
export
|
|
26
|
+
type VideoPlayerType = React.ForwardRefExoticComponent<VideoPlayerProps & React.RefAttributes<MuxPlayerElement>>;
|
|
27
|
+
export declare const VideoPlayer: VideoPlayerType;
|
|
28
|
+
export default VideoPlayer;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type MuxPlayerElement from "@mux/mux-player";
|
|
3
|
+
import type { VideoPlayerProps } from "./index";
|
|
4
|
+
type VideoPlayerType = React.ForwardRefExoticComponent<VideoPlayerProps & React.RefAttributes<MuxPlayerElement>>;
|
|
5
|
+
export declare const VideoPlayer: VideoPlayerType;
|
|
6
|
+
export default VideoPlayer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-datocms",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=8.0.0"
|
|
6
6
|
},
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
"import": "./dist/esm/Image/index.js",
|
|
25
25
|
"types": "./dist/types/Image/index.d.ts"
|
|
26
26
|
},
|
|
27
|
+
"./video-player/lazy": {
|
|
28
|
+
"require": "./dist/cjs/VideoPlayer/lazy.js",
|
|
29
|
+
"import": "./dist/esm/VideoPlayer/lazy.js",
|
|
30
|
+
"types": "./dist/types/VideoPlayer/lazy.d.ts"
|
|
31
|
+
},
|
|
27
32
|
"./video-player": {
|
|
28
33
|
"require": "./dist/cjs/VideoPlayer/index.js",
|
|
29
34
|
"import": "./dist/esm/VideoPlayer/index.js",
|
|
@@ -64,6 +69,9 @@
|
|
|
64
69
|
"video-player": [
|
|
65
70
|
"./dist/types/VideoPlayer/index.d.ts"
|
|
66
71
|
],
|
|
72
|
+
"video-player/lazy": [
|
|
73
|
+
"./dist/types/VideoPlayer/lazy.d.ts"
|
|
74
|
+
],
|
|
67
75
|
"structured-text": [
|
|
68
76
|
"./dist/types/StructuredText/index.d.ts"
|
|
69
77
|
],
|
|
@@ -95,7 +103,7 @@
|
|
|
95
103
|
"homepage": "https://github.com/datocms/react-datocms",
|
|
96
104
|
"devDependencies": {
|
|
97
105
|
"@biomejs/biome": "^1.6.3",
|
|
98
|
-
"@mux/mux-player-react": "
|
|
106
|
+
"@mux/mux-player-react": "^2.0.0",
|
|
99
107
|
"@types/enzyme": "^3.10.8",
|
|
100
108
|
"@types/enzyme-to-json": "^1.5.4",
|
|
101
109
|
"@types/jest": "^29.5.11",
|
|
@@ -139,6 +147,6 @@
|
|
|
139
147
|
"react-intersection-observer": "^9.4.3",
|
|
140
148
|
"react-string-replace": "^1.1.0",
|
|
141
149
|
"use-deep-compare-effect": "^1.6.1",
|
|
142
|
-
"@mux/mux-player-react": "
|
|
150
|
+
"@mux/mux-player-react": "^2.0.0"
|
|
143
151
|
}
|
|
144
152
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
|
|
3
3
|
// This file defines a React component that easily displays a video player using
|
|
4
4
|
// data stored on DatoCMS and retrieved via DatoCMS GraphQL API. The component
|
|
@@ -8,25 +8,24 @@
|
|
|
8
8
|
//
|
|
9
9
|
// [1]: https://www.mux.com/player
|
|
10
10
|
|
|
11
|
-
import React, { forwardRef } from
|
|
11
|
+
import React, { forwardRef } from "react";
|
|
12
12
|
|
|
13
13
|
// We use and extend Typescript types defined in the MUX player.
|
|
14
14
|
|
|
15
|
-
import type MuxPlayerElement from
|
|
16
|
-
import type { MuxPlayerProps } from
|
|
15
|
+
import type MuxPlayerElement from "@mux/mux-player";
|
|
16
|
+
import type { MuxPlayerProps } from "@mux/mux-player-react";
|
|
17
17
|
|
|
18
18
|
// React MUX player is made available in two flavours: eager and lazy loaded. We
|
|
19
|
-
// choose to use the
|
|
20
|
-
//
|
|
21
|
-
// `React.lazy()`.
|
|
19
|
+
// choose to use the eager loading version as the default approch, but
|
|
20
|
+
// we also provide a lazy loading version..
|
|
22
21
|
|
|
23
|
-
import MuxPlayer from
|
|
22
|
+
import MuxPlayer from "@mux/mux-player-react";
|
|
24
23
|
|
|
25
24
|
// The core of this component is the `useVideoPlayer` hook: it takes
|
|
26
25
|
// data from DatoCMS GraphQL API and returns props as expected by the
|
|
27
26
|
// `<MuxPlayer />` component.
|
|
28
27
|
|
|
29
|
-
import { useVideoPlayer } from
|
|
28
|
+
import { useVideoPlayer } from "../useVideoPlayer/index.js";
|
|
30
29
|
|
|
31
30
|
type Maybe<T> = T | null;
|
|
32
31
|
type Possibly<T> = Maybe<T> | undefined;
|
|
@@ -63,16 +62,19 @@ export type VideoPlayerProps = MuxPlayerProps & {
|
|
|
63
62
|
data?: Video;
|
|
64
63
|
};
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
type VideoPlayerType = React.ForwardRefExoticComponent<
|
|
66
|
+
VideoPlayerProps & React.RefAttributes<MuxPlayerElement>
|
|
67
|
+
>;
|
|
68
|
+
|
|
69
|
+
export const VideoPlayer: VideoPlayerType = forwardRef<
|
|
69
70
|
MuxPlayerElement,
|
|
70
71
|
VideoPlayerProps
|
|
71
|
-
>((props, ref) => {
|
|
72
|
+
>((props: VideoPlayerProps, ref) => {
|
|
72
73
|
const {
|
|
73
74
|
data = {},
|
|
74
75
|
disableCookies = true,
|
|
75
|
-
|
|
76
|
+
disableTracking = true,
|
|
77
|
+
preload = "metadata",
|
|
76
78
|
style: styleFromProps,
|
|
77
79
|
...rest
|
|
78
80
|
} = props;
|
|
@@ -98,6 +100,7 @@ export const VideoPlayer: (
|
|
|
98
100
|
preload={preload}
|
|
99
101
|
title={title}
|
|
100
102
|
disableCookies={disableCookies}
|
|
103
|
+
disableTracking={disableTracking}
|
|
101
104
|
playbackId={playbackId}
|
|
102
105
|
style={style}
|
|
103
106
|
placeholder={placeholder}
|
|
@@ -105,3 +108,5 @@ export const VideoPlayer: (
|
|
|
105
108
|
/>
|
|
106
109
|
);
|
|
107
110
|
});
|
|
111
|
+
|
|
112
|
+
export default VideoPlayer;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { Suspense, forwardRef } from "react";
|
|
2
|
+
import type MuxPlayerElement from "@mux/mux-player";
|
|
3
|
+
import type MuxPlayer from "@mux/mux-player-react/.";
|
|
4
|
+
|
|
5
|
+
import type { VideoPlayerProps } from "./index";
|
|
6
|
+
|
|
7
|
+
const LazyLoadedVideoPlayer = React.lazy(() => import("./index.js"));
|
|
8
|
+
|
|
9
|
+
type VideoPlayerType = React.ForwardRefExoticComponent<
|
|
10
|
+
VideoPlayerProps & React.RefAttributes<MuxPlayerElement>
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
export const VideoPlayer: VideoPlayerType = forwardRef<
|
|
14
|
+
MuxPlayerElement,
|
|
15
|
+
VideoPlayerProps
|
|
16
|
+
>((props: VideoPlayerProps, ref) => {
|
|
17
|
+
const { className, style } = props;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Suspense fallback={<div className={className} style={style} />}>
|
|
21
|
+
<LazyLoadedVideoPlayer {...props} ref={ref} />
|
|
22
|
+
</Suspense>
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export default VideoPlayer;
|