@manuscripts/body-editor 3.12.31 → 3.12.33

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.
@@ -137,7 +137,7 @@ const AuthorDetailsForm = ({ values, onChange, onSave, actionsRef, isEmailRequir
137
137
  (0, formik_1.getIn)(formik.errors, 'ORCID');
138
138
  return (react_1.default.createElement(react_1.default.Fragment, null,
139
139
  react_1.default.createElement(style_guide_1.Label, { htmlFor: "orcid" }, "ORCID"),
140
- react_1.default.createElement(TextFieldWithError, { id: 'orcid', type: "url", placeholder: 'https://orcid.org/...', ...props.field, pattern: ORCID_INPUT_PATTERN, title: "Please enter a valid ORCID URL: https://orcid.org/xxxx-xxxx-xxxx-xxxx", error: hasError }),
140
+ react_1.default.createElement(TextFieldWithError, { id: 'orcid', disabled: values.isAuthenticated, type: "url", placeholder: 'https://orcid.org/...', ...props.field, pattern: ORCID_INPUT_PATTERN, title: "Please enter a valid ORCID URL: https://orcid.org/xxxx-xxxx-xxxx-xxxx", error: hasError }),
141
141
  hasError && (react_1.default.createElement(style_guide_1.InputErrorText, null, (0, formik_1.getIn)(formik.errors, 'ORCID')))));
142
142
  })),
143
143
  react_1.default.createElement(style_guide_1.FormRow, null,
@@ -58,6 +58,7 @@ const react_dnd_1 = require("react-dnd");
58
58
  const styled_components_1 = __importDefault(require("styled-components"));
59
59
  const authors_1 = require("../../lib/authors");
60
60
  const dnd_1 = require("../../lib/dnd");
61
+ const styled_components_2 = require("../references/ReferenceForm/styled-components");
61
62
  const AuthorContainer = (0, style_guide_1.withNavigableListItem)(styled_components_1.default.div `
62
63
  padding: ${(props) => props.theme.grid.unit * 2}px 0
63
64
  ${(props) => props.theme.grid.unit * 2}px;
@@ -125,11 +126,9 @@ const DragHandle = (0, styled_components_1.default)(style_guide_1.DraggableIcon)
125
126
  margin-left: -4px;
126
127
  margin-right: -12px;
127
128
  `;
128
- const RemoveButton = (0, styled_components_1.default)(style_guide_1.SecondaryIconButton) `
129
- svg {
130
- path[fill='white'] {
131
- fill: white;
132
- }
129
+ const RemoveButton = (0, styled_components_1.default)(styled_components_2.DeleteButton) `
130
+ .icon_element {
131
+ fill: ${(props) => (props.disabled && '#c9c9c9') || '#6E6E6E'} !important;
133
132
  }
134
133
  `;
135
134
  const StyledCrclTickAnimation = (0, styled_components_1.default)(style_guide_1.CrclTickAnimation) `
@@ -34,7 +34,7 @@ function DrawerGroup({ removeItem, selectedItems, onSelect, items, showDrawer, s
34
34
  })), onRemove: removeItem, placeholder: `No ${title} assigned` }),
35
35
  showDrawer && (react_1.default.createElement(Drawer, { items: items, selectedItems: selectedItems, title: title, onSelect: onSelect, onBack: () => setShowDrawer(false), width: "100%" }))));
36
36
  }
37
- exports.AssignButton = styled_components_1.default.button `
37
+ exports.AssignButton = (0, styled_components_1.default)(style_guide_1.IconButton) `
38
38
  color: ${(props) => props.theme.colors.brand.default};
39
39
  background: none;
40
40
  border: none;
@@ -43,10 +43,16 @@ exports.AssignButton = styled_components_1.default.button `
43
43
  font: ${(props) => props.theme.font.weight.normal}
44
44
  ${(props) => props.theme.font.size.normal}
45
45
  ${(props) => props.theme.font.family.sans};
46
- display: flex;
47
- align-items: center;
48
46
  gap: 4px;
49
- margin-bottom: ${(props) => props.theme.grid.unit * 2}px;
47
+ width: auto;
48
+ height: 24px;
49
+
50
+ &:disabled {
51
+ color: #c9c9c9 !important;
52
+ background-color: unset !important;
53
+ border: unset;
54
+ }
55
+
50
56
  &:hover {
51
57
  opacity: 0.8;
52
58
  }
@@ -56,7 +56,6 @@ const style_guide_1 = require("@manuscripts/style-guide");
56
56
  const react_1 = __importStar(require("react"));
57
57
  const styled_components_1 = __importDefault(require("styled-components"));
58
58
  const commands_1 = require("../../commands");
59
- const oembed_1 = require("../../lib/oembed");
60
59
  const url_1 = require("../../lib/url");
61
60
  const use_do_with_debounce_1 = require("../../lib/use-do-with-debounce");
62
61
  const editor_props_1 = require("../../plugins/editor-props");
@@ -98,8 +97,10 @@ const InsertEmbedDialog = ({ state, dispatch, pos, }) => {
98
97
  };
99
98
  (0, react_1.useEffect)(() => {
100
99
  debounce(async () => {
101
- const html = await (0, oembed_1.getOEmbedHTML)(url, 368, 217);
102
- setOEmbedHTML(html);
100
+ if (url && (0, url_1.allowedHref)(url)) {
101
+ const html = await (0, editor_props_1.getEditorProps)(state).fetchOEmbedHtml(url, 368, 217);
102
+ setOEmbedHTML(html);
103
+ }
103
104
  });
104
105
  }, [url]);
105
106
  const operation = pos !== undefined && attrs?.href ? 'Update' : 'Insert';
@@ -43,6 +43,7 @@ const buildProps = (doc) => ({
43
43
  category.id,
44
44
  category,
45
45
  ])),
46
+ fetchOEmbedHtml: async () => undefined,
46
47
  });
47
48
  describe('editor view', () => {
48
49
  const doc = transform_1.schema.nodeFromJSON(doc_json_1.default);
@@ -28,6 +28,7 @@ const normalizeAuthor = (author) => {
28
28
  email: trim(author.email),
29
29
  isCorresponding: author.isCorresponding || false,
30
30
  ORCID: trim(author.ORCID),
31
+ isAuthenticated: author.isAuthenticated || false,
31
32
  priority: author.priority,
32
33
  isJointContributor: author.isJointContributor || false,
33
34
  degrees: author.degrees || [],
@@ -63,4 +63,5 @@ exports.defaultEditorProps = {
63
63
  category.id,
64
64
  category,
65
65
  ])),
66
+ fetchOEmbedHtml: async () => undefined,
66
67
  };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '3.12.31';
4
+ exports.VERSION = '3.12.33';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -9,7 +9,6 @@ const prosemirror_state_1 = require("prosemirror-state");
9
9
  const InsertEmbedDialog_1 = require("../components/toolbar/InsertEmbedDialog");
10
10
  const get_media_type_1 = require("../lib/get-media-type");
11
11
  const media_1 = require("../lib/media");
12
- const oembed_1 = require("../lib/oembed");
13
12
  const url_1 = require("../lib/url");
14
13
  const block_view_1 = __importDefault(require("./block_view"));
15
14
  const creators_1 = require("./creators");
@@ -204,7 +203,7 @@ class EmbedView extends block_view_1.default {
204
203
  const container = document.createElement('div');
205
204
  container.classList.add('embed-preview');
206
205
  try {
207
- const html = await (0, oembed_1.getOEmbedHTML)(this.node.attrs.href, 643, 363);
206
+ const html = await this.props.fetchOEmbedHtml(this.node.attrs.href, 643, 363);
208
207
  if (html) {
209
208
  container.innerHTML = html;
210
209
  }
@@ -98,7 +98,7 @@ export const AuthorDetailsForm = ({ values, onChange, onSave, actionsRef, isEmai
98
98
  getIn(formik.errors, 'ORCID');
99
99
  return (React.createElement(React.Fragment, null,
100
100
  React.createElement(Label, { htmlFor: "orcid" }, "ORCID"),
101
- React.createElement(TextFieldWithError, { id: 'orcid', type: "url", placeholder: 'https://orcid.org/...', ...props.field, pattern: ORCID_INPUT_PATTERN, title: "Please enter a valid ORCID URL: https://orcid.org/xxxx-xxxx-xxxx-xxxx", error: hasError }),
101
+ React.createElement(TextFieldWithError, { id: 'orcid', disabled: values.isAuthenticated, type: "url", placeholder: 'https://orcid.org/...', ...props.field, pattern: ORCID_INPUT_PATTERN, title: "Please enter a valid ORCID URL: https://orcid.org/xxxx-xxxx-xxxx-xxxx", error: hasError }),
102
102
  hasError && (React.createElement(InputErrorText, null, getIn(formik.errors, 'ORCID')))));
103
103
  })),
104
104
  React.createElement(FormRow, null,
@@ -13,12 +13,13 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Avatar, CorrespondingAuthorIcon, CrclTickAnimation, DeleteIcon, DraggableIcon, SecondaryIconButton, withNavigableListItem, } from '@manuscripts/style-guide';
16
+ import { Avatar, CorrespondingAuthorIcon, CrclTickAnimation, DeleteIcon, DraggableIcon, withNavigableListItem, } from '@manuscripts/style-guide';
17
17
  import React, { useRef, useState } from 'react';
18
18
  import { useDrag, useDrop } from 'react-dnd';
19
19
  import styled from 'styled-components';
20
20
  import { authorLabel } from '../../lib/authors';
21
21
  import { getDropSide } from '../../lib/dnd';
22
+ import { DeleteButton } from '../references/ReferenceForm/styled-components';
22
23
  const AuthorContainer = withNavigableListItem(styled.div `
23
24
  padding: ${(props) => props.theme.grid.unit * 2}px 0
24
25
  ${(props) => props.theme.grid.unit * 2}px;
@@ -86,11 +87,9 @@ const DragHandle = styled(DraggableIcon) `
86
87
  margin-left: -4px;
87
88
  margin-right: -12px;
88
89
  `;
89
- const RemoveButton = styled(SecondaryIconButton) `
90
- svg {
91
- path[fill='white'] {
92
- fill: white;
93
- }
90
+ const RemoveButton = styled(DeleteButton) `
91
+ .icon_element {
92
+ fill: ${(props) => (props.disabled && '#c9c9c9') || '#6E6E6E'} !important;
94
93
  }
95
94
  `;
96
95
  const StyledCrclTickAnimation = styled(CrclTickAnimation) `
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { outlineStyle, SelectedItemsBox, } from '@manuscripts/style-guide';
16
+ import { outlineStyle, SelectedItemsBox, IconButton, } from '@manuscripts/style-guide';
17
17
  import React from 'react';
18
18
  import styled from 'styled-components';
19
19
  export function DrawerGroup({ removeItem, selectedItems, onSelect, items, showDrawer, setShowDrawer, title, labelField, Drawer, cy, Icon, buttonText, }) {
@@ -27,7 +27,7 @@ export function DrawerGroup({ removeItem, selectedItems, onSelect, items, showDr
27
27
  })), onRemove: removeItem, placeholder: `No ${title} assigned` }),
28
28
  showDrawer && (React.createElement(Drawer, { items: items, selectedItems: selectedItems, title: title, onSelect: onSelect, onBack: () => setShowDrawer(false), width: "100%" }))));
29
29
  }
30
- export const AssignButton = styled.button `
30
+ export const AssignButton = styled(IconButton) `
31
31
  color: ${(props) => props.theme.colors.brand.default};
32
32
  background: none;
33
33
  border: none;
@@ -36,10 +36,16 @@ export const AssignButton = styled.button `
36
36
  font: ${(props) => props.theme.font.weight.normal}
37
37
  ${(props) => props.theme.font.size.normal}
38
38
  ${(props) => props.theme.font.family.sans};
39
- display: flex;
40
- align-items: center;
41
39
  gap: 4px;
42
- margin-bottom: ${(props) => props.theme.grid.unit * 2}px;
40
+ width: auto;
41
+ height: 24px;
42
+
43
+ &:disabled {
44
+ color: #c9c9c9 !important;
45
+ background-color: unset !important;
46
+ border: unset;
47
+ }
48
+
43
49
  &:hover {
44
50
  opacity: 0.8;
45
51
  }
@@ -17,7 +17,6 @@ import { ButtonGroup, DialogModalBody, MessageContainer, PrimaryBoldHeading, Pri
17
17
  import React, { useEffect, useState } from 'react';
18
18
  import styled from 'styled-components';
19
19
  import { insertEmbed } from '../../commands';
20
- import { getOEmbedHTML } from '../../lib/oembed';
21
20
  import { allowedHref } from '../../lib/url';
22
21
  import { useDoWithDebounce } from '../../lib/use-do-with-debounce';
23
22
  import { getEditorProps } from '../../plugins/editor-props';
@@ -59,8 +58,10 @@ export const InsertEmbedDialog = ({ state, dispatch, pos, }) => {
59
58
  };
60
59
  useEffect(() => {
61
60
  debounce(async () => {
62
- const html = await getOEmbedHTML(url, 368, 217);
63
- setOEmbedHTML(html);
61
+ if (url && allowedHref(url)) {
62
+ const html = await getEditorProps(state).fetchOEmbedHtml(url, 368, 217);
63
+ setOEmbedHTML(html);
64
+ }
64
65
  });
65
66
  }, [url]);
66
67
  const operation = pos !== undefined && attrs?.href ? 'Update' : 'Insert';
@@ -38,6 +38,7 @@ const buildProps = (doc) => ({
38
38
  category.id,
39
39
  category,
40
40
  ])),
41
+ fetchOEmbedHtml: async () => undefined,
41
42
  });
42
43
  describe('editor view', () => {
43
44
  const doc = schema.nodeFromJSON(jsonDoc);
@@ -25,6 +25,7 @@ export const normalizeAuthor = (author) => {
25
25
  email: trim(author.email),
26
26
  isCorresponding: author.isCorresponding || false,
27
27
  ORCID: trim(author.ORCID),
28
+ isAuthenticated: author.isAuthenticated || false,
28
29
  priority: author.priority,
29
30
  isJointContributor: author.isJointContributor || false,
30
31
  degrees: author.degrees || [],
@@ -57,4 +57,5 @@ export const defaultEditorProps = {
57
57
  category.id,
58
58
  category,
59
59
  ])),
60
+ fetchOEmbedHtml: async () => undefined,
60
61
  };
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.12.31';
1
+ export const VERSION = '3.12.33';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -3,7 +3,6 @@ import { NodeSelection } from 'prosemirror-state';
3
3
  import { NoPreviewMessageWithLink, openEmbedDialog, } from '../components/toolbar/InsertEmbedDialog';
4
4
  import { getMediaTypeInfo } from '../lib/get-media-type';
5
5
  import { addInteractionHandlers, createFileHandlers, createFileUploader, createMediaPlaceholder, createReactTools, createUnsupportedFormat, MediaType, } from '../lib/media';
6
- import { getOEmbedHTML } from '../lib/oembed';
7
6
  import { allowedHref } from '../lib/url';
8
7
  import BlockView from './block_view';
9
8
  import { createEditableNodeView } from './creators';
@@ -198,7 +197,7 @@ export class EmbedView extends BlockView {
198
197
  const container = document.createElement('div');
199
198
  container.classList.add('embed-preview');
200
199
  try {
201
- const html = await getOEmbedHTML(this.node.attrs.href, 643, 363);
200
+ const html = await this.props.fetchOEmbedHtml(this.node.attrs.href, 643, 363);
202
201
  if (html) {
203
202
  container.innerHTML = html;
204
203
  }
@@ -39,5 +39,15 @@ interface EmbeddedDrawerProps<T extends Base> {
39
39
  onSelect: (id: string) => void;
40
40
  }
41
41
  export declare function DrawerGroup<T extends Base>({ removeItem, selectedItems, onSelect, items, showDrawer, setShowDrawer, title, labelField, Drawer, cy, Icon, buttonText, }: DrawerGroupProps<T>): React.JSX.Element;
42
- export declare const AssignButton: import("styled-components").StyledComponent<"button", any, {}, never>;
42
+ export declare const AssignButton: import("styled-components").StyledComponent<"button", any, {
43
+ type: "button" | "submit" | "reset";
44
+ } & {
45
+ danger?: boolean;
46
+ disabled?: boolean;
47
+ mini?: boolean;
48
+ } & {
49
+ defaultColor?: boolean;
50
+ size?: number;
51
+ iconColor?: string;
52
+ }, "type">;
43
53
  export {};
@@ -25,6 +25,7 @@ import { Language } from '../lib/languages';
25
25
  import { Capabilities } from '../lib/capabilities';
26
26
  import { FileAttachment, FileManagement } from '../lib/files';
27
27
  import { PopperManager } from '../lib/popper';
28
+ export type FetchOEmbedHtml = (url: string, maxWidth: number, maxHeight: number) => Promise<string | undefined>;
28
29
  export type CSLProps = {
29
30
  style?: string;
30
31
  locale?: string;
@@ -56,6 +57,7 @@ export interface EditorProps {
56
57
  lockBody: boolean;
57
58
  isViewingMode?: boolean;
58
59
  hiddenNodeTypes?: ManuscriptNodeType[] | undefined;
60
+ fetchOEmbedHtml: FetchOEmbedHtml;
59
61
  }
60
62
  export type ExternalProps = Omit<EditorProps, 'popper' | 'dispatch'>;
61
63
  export declare const createEditorState: (props: EditorProps) => EditorState;
@@ -32,6 +32,7 @@ export * from './lib/footnotes';
32
32
  export * from './lib/template';
33
33
  export * from './lib/doc';
34
34
  export * from './lib/media';
35
+ export type { FetchOEmbedHtml } from './configs/ManuscriptsEditor';
35
36
  export * from './plugins/comments';
36
37
  export { selectedSuggestionKey } from './plugins/selected-suggestion';
37
38
  export * from './selection';
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.12.31";
1
+ export declare const VERSION = "3.12.33";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/body-editor",
3
3
  "description": "Prosemirror components for editing and viewing manuscripts",
4
- "version": "3.12.31",
4
+ "version": "3.12.33",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -37,9 +37,9 @@
37
37
  "@citation-js/plugin-pubmed": "0.3.0",
38
38
  "@citation-js/plugin-ris": "0.7.18",
39
39
  "@iarna/word-count": "1.1.2",
40
- "@manuscripts/style-guide": "3.5.10",
40
+ "@manuscripts/style-guide": "3.5.11",
41
41
  "@manuscripts/track-changes-plugin": "2.3.10",
42
- "@manuscripts/transform": "4.3.37",
42
+ "@manuscripts/transform": "4.3.38",
43
43
  "@popperjs/core": "2.11.8",
44
44
  "citeproc": "2.4.63",
45
45
  "codemirror": "5.65.19",
@@ -50,7 +50,6 @@
50
50
  "history": "5.3.0",
51
51
  "lodash": "4.17.21",
52
52
  "mathjax": "3.2.2",
53
- "oembed-providers": "1.0.20250430",
54
53
  "prosemirror-collab": "1.3.1",
55
54
  "prosemirror-commands": "1.7.1",
56
55
  "prosemirror-dropcursor": "1.8.2",
@@ -1,84 +0,0 @@
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.getOEmbedHTML = exports.getOEmbedUrl = void 0;
7
- const oembed_providers_1 = __importDefault(require("oembed-providers"));
8
- const getOEmbedUrl = async (url, width, height) => {
9
- let oembedUrl;
10
- for (const provider of oembed_providers_1.default) {
11
- if (provider) {
12
- const { provider_url, endpoints } = provider;
13
- for (const endpoint of endpoints) {
14
- if (endpoint.schemes &&
15
- endpoint.schemes.find((schema) => globToRegex(schema).test(url))) {
16
- oembedUrl = endpoint.url.replace('{format}', 'json');
17
- break;
18
- }
19
- else if (!endpoint.schemes && url.startsWith(provider_url)) {
20
- oembedUrl = endpoint.url.replace('{format}', 'json');
21
- break;
22
- }
23
- }
24
- }
25
- }
26
- if (oembedUrl) {
27
- const params = new URLSearchParams();
28
- params.append('url', url);
29
- params.set('format', 'json');
30
- params.append('maxwidth', width.toString());
31
- params.append('maxheight', height.toString());
32
- return `${oembedUrl}?${params.toString()}`;
33
- }
34
- else {
35
- try {
36
- const response = await fetch(url, { method: 'HEAD' });
37
- let oembedUrl;
38
- const linkHeader = response.headers.get('link');
39
- if (linkHeader) {
40
- linkHeader.split(',').map((link) => {
41
- const typeMatch = /type="([^"]*)"/.exec(link);
42
- if (typeMatch &&
43
- (typeMatch[1] === 'application/json+oembed' ||
44
- typeMatch[1] === 'text/xml+oembed')) {
45
- oembedUrl = /<([^>]*)>/.exec(link);
46
- }
47
- });
48
- }
49
- return oembedUrl;
50
- }
51
- catch (e) {
52
- return undefined;
53
- }
54
- }
55
- };
56
- exports.getOEmbedUrl = getOEmbedUrl;
57
- const globToRegex = (glob) => {
58
- const regex = glob
59
- .replace(/\./g, '\\.')
60
- .replace(/\*/g, '.*');
61
- return new RegExp(`^${regex}$`);
62
- };
63
- const getOEmbedHTML = async (url, width, height) => {
64
- try {
65
- const oembedUrl = await (0, exports.getOEmbedUrl)(url, width, height);
66
- if (!oembedUrl) {
67
- return;
68
- }
69
- const response = await fetch(oembedUrl);
70
- if (response.status === 200) {
71
- const json = await response.json();
72
- return json.html || renderAlternativeHTML(json);
73
- }
74
- }
75
- catch (e) {
76
- return;
77
- }
78
- };
79
- exports.getOEmbedHTML = getOEmbedHTML;
80
- const renderAlternativeHTML = (oembed) => {
81
- if (oembed.type === 'photo') {
82
- return `<img src="${oembed.url}">`;
83
- }
84
- };
@@ -1,76 +0,0 @@
1
- import providers from 'oembed-providers';
2
- export const getOEmbedUrl = async (url, width, height) => {
3
- let oembedUrl;
4
- for (const provider of providers) {
5
- if (provider) {
6
- const { provider_url, endpoints } = provider;
7
- for (const endpoint of endpoints) {
8
- if (endpoint.schemes &&
9
- endpoint.schemes.find((schema) => globToRegex(schema).test(url))) {
10
- oembedUrl = endpoint.url.replace('{format}', 'json');
11
- break;
12
- }
13
- else if (!endpoint.schemes && url.startsWith(provider_url)) {
14
- oembedUrl = endpoint.url.replace('{format}', 'json');
15
- break;
16
- }
17
- }
18
- }
19
- }
20
- if (oembedUrl) {
21
- const params = new URLSearchParams();
22
- params.append('url', url);
23
- params.set('format', 'json');
24
- params.append('maxwidth', width.toString());
25
- params.append('maxheight', height.toString());
26
- return `${oembedUrl}?${params.toString()}`;
27
- }
28
- else {
29
- try {
30
- const response = await fetch(url, { method: 'HEAD' });
31
- let oembedUrl;
32
- const linkHeader = response.headers.get('link');
33
- if (linkHeader) {
34
- linkHeader.split(',').map((link) => {
35
- const typeMatch = /type="([^"]*)"/.exec(link);
36
- if (typeMatch &&
37
- (typeMatch[1] === 'application/json+oembed' ||
38
- typeMatch[1] === 'text/xml+oembed')) {
39
- oembedUrl = /<([^>]*)>/.exec(link);
40
- }
41
- });
42
- }
43
- return oembedUrl;
44
- }
45
- catch (e) {
46
- return undefined;
47
- }
48
- }
49
- };
50
- const globToRegex = (glob) => {
51
- const regex = glob
52
- .replace(/\./g, '\\.')
53
- .replace(/\*/g, '.*');
54
- return new RegExp(`^${regex}$`);
55
- };
56
- export const getOEmbedHTML = async (url, width, height) => {
57
- try {
58
- const oembedUrl = await getOEmbedUrl(url, width, height);
59
- if (!oembedUrl) {
60
- return;
61
- }
62
- const response = await fetch(oembedUrl);
63
- if (response.status === 200) {
64
- const json = await response.json();
65
- return json.html || renderAlternativeHTML(json);
66
- }
67
- }
68
- catch (e) {
69
- return;
70
- }
71
- };
72
- const renderAlternativeHTML = (oembed) => {
73
- if (oembed.type === 'photo') {
74
- return `<img src="${oembed.url}">`;
75
- }
76
- };
@@ -1,8 +0,0 @@
1
- export type ProviderJson = {
2
- type: 'photo' | 'video' | 'link' | 'rich';
3
- html?: string;
4
- url?: string;
5
- title?: string;
6
- };
7
- export declare const getOEmbedUrl: (url: string, width: number, height: number) => Promise<string | undefined>;
8
- export declare const getOEmbedHTML: (url: string, width: number, height: number) => Promise<any>;