@uxf/wysiwyg 11.72.0 → 11.73.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/wysiwyg",
3
- "version": "11.72.0",
3
+ "version": "11.73.0",
4
4
  "description": "UXF Wysiwyg editor",
5
5
  "author": "Robin Dvorak <dvorak@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/wysiwyg",
@@ -25,9 +25,9 @@
25
25
  "@udecode/plate-reset-node": "20.7.2",
26
26
  "@udecode/plate-select": "20.7.2",
27
27
  "@udecode/plate-trailing-block": "20.7.2",
28
- "@uxf/core": "11.70.0",
29
- "@uxf/core-react": "11.71.0",
30
- "@uxf/ui": "11.72.0",
28
+ "@uxf/core": "11.72.3",
29
+ "@uxf/core-react": "11.72.3",
30
+ "@uxf/ui": "11.72.3",
31
31
  "slate": "0.90.0",
32
32
  "slate-history": "0.86.0",
33
33
  "slate-hyperscript": "0.77.0",
@@ -1,2 +1,2 @@
1
- import { UxfEditor } from "../../../types";
2
- export declare const insertVideo: (editor: UxfEditor, url: string, embeddedUrl: string, provider: string, videoId: string) => void;
1
+ import { UxfEditor, type UxfVideoMetaData } from "../../../types";
2
+ export declare const insertVideo: (editor: UxfEditor, url: string, embeddedUrl: string, provider: string, videoId: string, metaData: UxfVideoMetaData | null) => void;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.insertVideo = void 0;
4
4
  const utils_1 = require("../../../utils");
5
5
  const create_video_plugin_1 = require("./create-video-plugin");
6
- const insertVideo = (editor, url, embeddedUrl, provider, videoId) => {
6
+ const insertVideo = (editor, url, embeddedUrl, provider, videoId, metaData) => {
7
7
  const text = { text: "" };
8
8
  const element = {
9
9
  type: create_video_plugin_1.ELEMENT_VIDEO_EMBED,
@@ -12,6 +12,7 @@ const insertVideo = (editor, url, embeddedUrl, provider, videoId) => {
12
12
  provider,
13
13
  videoId,
14
14
  children: [text],
15
+ metaData,
15
16
  };
16
17
  (0, utils_1.insertVoid)(editor, element);
17
18
  };
@@ -1,2 +1,2 @@
1
- import { UxfEditor } from "../../../types";
2
- export declare const updateVideo: (editor: UxfEditor, url: string, embeddedUrl: string, provider: string, videoId: string) => void;
1
+ import { UxfEditor, type UxfVideoMetaData } from "../../../types";
2
+ export declare const updateVideo: (editor: UxfEditor, url: string, embeddedUrl: string, provider: string, videoId: string, metaData: UxfVideoMetaData | null) => void;
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateVideo = void 0;
4
4
  const plate_common_1 = require("@udecode/plate-common");
5
- const updateVideo = (editor, url, embeddedUrl, provider, videoId) => (0, plate_common_1.setNodes)(editor, {
5
+ const updateVideo = (editor, url, embeddedUrl, provider, videoId, metaData) => (0, plate_common_1.setNodes)(editor, {
6
6
  url,
7
7
  embeddedUrl,
8
8
  provider,
9
9
  videoId,
10
+ metaData,
10
11
  });
11
12
  exports.updateVideo = updateVideo;
package/types.d.ts CHANGED
@@ -58,6 +58,21 @@ export interface UxfOrderedListElement extends UxfBlockElement {
58
58
  type: "ol";
59
59
  children: LiElement[];
60
60
  }
61
+ export type UxfVideoMetaData = {
62
+ title: string;
63
+ description: string;
64
+ authorName: string;
65
+ authorUrl: string;
66
+ width: number;
67
+ height: number;
68
+ duration: number;
69
+ uploadDate: string;
70
+ thumbnail: {
71
+ width: number;
72
+ height: number;
73
+ url: string;
74
+ };
75
+ };
61
76
  export interface UxfVideoElement extends UxfBlockElement {
62
77
  type: "video";
63
78
  url: string;
@@ -65,6 +80,7 @@ export interface UxfVideoElement extends UxfBlockElement {
65
80
  provider: string;
66
81
  videoId: string;
67
82
  children: [EmptyText];
83
+ metaData?: Partial<UxfVideoMetaData> | null;
68
84
  }
69
85
  export interface UxfButtonElement extends UxfBlockElement {
70
86
  type: "button";
@@ -30,6 +30,7 @@ const utils_1 = require("../../plugins/embedded/utils");
30
30
  const insert_video_1 = require("../../plugins/embedded/video/insert-video");
31
31
  const update_video_1 = require("../../plugins/embedded/video/update-video");
32
32
  const context_1 = require("../../translations/context");
33
+ const get_video_meta_data_1 = require("../../utils/get-video-meta-data");
33
34
  const modal_buttons_1 = require("../components/modal/modal-buttons");
34
35
  const modal_content_1 = require("../components/modal/modal-content");
35
36
  const utils_2 = require("../utils");
@@ -43,18 +44,19 @@ const InsertVideoModalContent = ({ editor, editedVideo }) => {
43
44
  ? { id: editedVideo.videoId, provider: editedVideo.provider, url: editedVideo.embeddedUrl }
44
45
  : undefined);
45
46
  const [error, setError] = (0, react_1.useState)();
46
- const onSubmit = (0, react_1.useCallback)((event) => {
47
+ const onSubmit = (0, react_1.useCallback)(async (event) => {
47
48
  event.preventDefault();
48
49
  setEmbedUrl((0, utils_1.parseVideoUrl)(url));
49
50
  if (!((embedUrl === null || embedUrl === void 0 ? void 0 : embedUrl.url) && embedUrl.provider && embedUrl.id)) {
50
51
  setError("Neplatná URL adresa.");
51
52
  return;
52
53
  }
54
+ const metaData = await (0, get_video_meta_data_1.getVideoMetaData)(embedUrl.provider, embedUrl.id);
53
55
  if (editedVideo) {
54
- (0, update_video_1.updateVideo)(editor, url, embedUrl.url, embedUrl.provider, embedUrl.id);
56
+ (0, update_video_1.updateVideo)(editor, url, embedUrl.url, embedUrl.provider, embedUrl.id, metaData);
55
57
  }
56
58
  else {
57
- (0, insert_video_1.insertVideo)(editor, url, embedUrl.url, embedUrl.provider, embedUrl.id);
59
+ (0, insert_video_1.insertVideo)(editor, url, embedUrl.url, embedUrl.provider, embedUrl.id, metaData);
58
60
  }
59
61
  (0, utils_2.closeModalWithFocus)(editor);
60
62
  }, [editedVideo, editor, embedUrl, url]);
@@ -0,0 +1,2 @@
1
+ import type { UxfVideoMetaData } from "../types";
2
+ export declare function getVideoMetaData(provider: string, id: string): Promise<UxfVideoMetaData | null>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVideoMetaData = getVideoMetaData;
4
+ function getOembedEndpoint(provider, id) {
5
+ switch (provider) {
6
+ case "youtube":
7
+ return `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${id}&format=json`;
8
+ case "vimeo":
9
+ return `https://vimeo.com/api/oembed.json?url=https://vimeo.com/${id}`;
10
+ default:
11
+ return null;
12
+ }
13
+ }
14
+ async function getVideoMetaData(provider, id) {
15
+ const endpoint = getOembedEndpoint(provider, id);
16
+ if (endpoint === null) {
17
+ return null;
18
+ }
19
+ return fetch(endpoint)
20
+ .then((res) => res.json())
21
+ .then((data) => ({
22
+ authorName: data.author_name,
23
+ authorUrl: data.author_url,
24
+ width: data.width,
25
+ height: data.height,
26
+ description: data.description,
27
+ duration: data.duration,
28
+ uploadDate: data.upload_date,
29
+ thumbnail: {
30
+ width: data.thumbnail_width,
31
+ height: data.thumbnail_height,
32
+ url: data.thumbnail_url,
33
+ },
34
+ title: data.title,
35
+ }))
36
+ .catch((e) => {
37
+ // eslint-disable-next-line no-console
38
+ console.error(e);
39
+ return null;
40
+ });
41
+ }