@manuscripts/body-editor 3.12.32 → 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.
@@ -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);
@@ -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.32';
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
  }
@@ -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);
@@ -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.32';
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
  }
@@ -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.32";
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.32",
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",
@@ -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>;