@procore/text-editor 0.5.1 → 1.0.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/.jest/ckeditorMock.js +47 -23
- package/CHANGELOG.md +19 -0
- package/README.md +96 -7
- package/dist/TextEditor/CKTextEditor.d.ts +3 -0
- package/dist/TextEditor/CKTextEditor.js +312 -0
- package/dist/TextEditor/CKTextEditor.js.map +1 -0
- package/dist/TextEditor/Providers/FeatureFlagProvider.d.ts +5 -0
- package/dist/TextEditor/Providers/FeatureFlagProvider.js +34 -0
- package/dist/TextEditor/Providers/FeatureFlagProvider.js.map +1 -0
- package/dist/TextEditor/TextEditor.d.ts +1 -1
- package/dist/TextEditor/TextEditor.js +16 -232
- package/dist/TextEditor/TextEditor.js.map +1 -1
- package/dist/TextEditor/TextEditor.styles.d.ts +14 -1
- package/dist/TextEditor/TextEditor.styles.js +18 -5
- package/dist/TextEditor/TextEditor.styles.js.map +1 -1
- package/dist/TextEditor/TextEditor.types.d.ts +82 -1
- package/dist/TextEditor/TextEditor.types.js.map +1 -1
- package/dist/TextEditor/TextEditorI18nProvider.d.ts +2 -0
- package/dist/TextEditor/TextEditorI18nProvider.js +27 -0
- package/dist/TextEditor/TextEditorI18nProvider.js.map +1 -0
- package/dist/TextEditor/TinyMCETextEditor.d.ts +3 -0
- package/dist/TextEditor/TinyMCETextEditor.js +63 -0
- package/dist/TextEditor/TinyMCETextEditor.js.map +1 -0
- package/dist/TextEditor/plugins/ProcoreImageUploadPlugin/ProcoreImageUploadPlugin.d.ts +48 -0
- package/dist/TextEditor/plugins/ProcoreImageUploadPlugin/ProcoreImageUploadPlugin.js +441 -0
- package/dist/TextEditor/plugins/ProcoreImageUploadPlugin/ProcoreImageUploadPlugin.js.map +1 -0
- package/dist/TextEditor/plugins/ProcoreImageUploadPlugin/index.d.ts +1 -0
- package/dist/TextEditor/plugins/ProcoreImageUploadPlugin/index.js +2 -0
- package/dist/TextEditor/plugins/ProcoreImageUploadPlugin/index.js.map +1 -0
- package/dist/TextEditor/utils/config.d.ts +6 -1
- package/dist/TextEditor/utils/config.js +23 -9
- package/dist/TextEditor/utils/config.js.map +1 -1
- package/dist/TextEditor/utils/imageAttributes.d.ts +6 -0
- package/dist/TextEditor/utils/imageAttributes.js +17 -0
- package/dist/TextEditor/utils/imageAttributes.js.map +1 -0
- package/dist/TextEditor/utils/imageUrls.d.ts +2 -0
- package/dist/TextEditor/utils/imageUrls.js +36 -0
- package/dist/TextEditor/utils/imageUrls.js.map +1 -0
- package/dist/TextEditor/utils/richTextEditorHandlers.d.ts +9 -0
- package/dist/TextEditor/utils/richTextEditorHandlers.js +234 -0
- package/dist/TextEditor/utils/richTextEditorHandlers.js.map +1 -0
- package/dist/TextEditorOutput/TextEditorOutput.styles.js +2 -2
- package/dist/TextEditorOutput/TextEditorOutput.styles.js.map +1 -1
- package/dist/TextEditorOutput/TextEditorOutput.utils.d.ts +1 -1
- package/dist/TextEditorOutput/TextEditorOutput.utils.js +150 -6
- package/dist/TextEditorOutput/TextEditorOutput.utils.js.map +1 -1
- package/dist/_typedoc/TextEditor/TextEditor.types.json +215 -17
- package/dist/_typedoc/TextEditor/TextEditorProvider.types.json +2 -2
- package/dist/_typedoc/TextEditorOutput/TextEditorOutput.types.json +3 -3
- package/dist/ckeditor5-premium-features.d.js +2 -0
- package/dist/ckeditor5-premium-features.d.js.map +1 -0
- package/dist/locales/en.json +17 -0
- package/dist/locales/pseudo.json +17 -0
- package/package.json +8 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
11
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
|
+
import { TextEditor as TinyMCEEditor, tinyMCE } from '@procore/core-react';
|
|
14
|
+
import React, { useMemo } from 'react';
|
|
15
|
+
import { sanitizeTextEditorHtml } from '../TextEditorOutput/TextEditorOutput.utils';
|
|
16
|
+
import { StyledReadOnlyValue } from './TextEditor.styles';
|
|
17
|
+
export var TinyMCETextEditor = function TinyMCETextEditor(props) {
|
|
18
|
+
var id = props.id,
|
|
19
|
+
value = props.value,
|
|
20
|
+
disabled = props.disabled,
|
|
21
|
+
error = props.error,
|
|
22
|
+
readonly = props.readonly,
|
|
23
|
+
placeholder = props.placeholder,
|
|
24
|
+
rows = props.rows,
|
|
25
|
+
onChange = props.onChange,
|
|
26
|
+
onBlur = props.onBlur,
|
|
27
|
+
onFocus = props.onFocus,
|
|
28
|
+
onKeyDown = props.onKeyDown,
|
|
29
|
+
init = props.init;
|
|
30
|
+
var baseHeight = 74;
|
|
31
|
+
var rowHeight = 22;
|
|
32
|
+
var height = rows === undefined ? undefined : rows * rowHeight + baseHeight;
|
|
33
|
+
var sanitizedValue = useMemo(function () {
|
|
34
|
+
return sanitizeTextEditorHtml(value || '') || '--';
|
|
35
|
+
}, [value]);
|
|
36
|
+
if (readonly) {
|
|
37
|
+
return /*#__PURE__*/React.createElement(StyledReadOnlyValue, null, /*#__PURE__*/React.createElement("div", {
|
|
38
|
+
dangerouslySetInnerHTML: {
|
|
39
|
+
__html: sanitizedValue
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
return /*#__PURE__*/React.createElement(TinyMCEEditor, {
|
|
44
|
+
id: id,
|
|
45
|
+
value: value,
|
|
46
|
+
disabled: disabled,
|
|
47
|
+
error: error,
|
|
48
|
+
"aria-label": props['aria-label'],
|
|
49
|
+
textareaName: props['aria-label'],
|
|
50
|
+
plugins: [].concat(_toConsumableArray(tinyMCE.defaultPlugins), ['link', 'table']),
|
|
51
|
+
init: _objectSpread({
|
|
52
|
+
contextmenu: false,
|
|
53
|
+
min_height: height,
|
|
54
|
+
max_height: height,
|
|
55
|
+
placeholder: placeholder
|
|
56
|
+
}, init),
|
|
57
|
+
onChange: onChange,
|
|
58
|
+
onBlur: onBlur,
|
|
59
|
+
onFocus: onFocus,
|
|
60
|
+
onKeyDown: onKeyDown
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=TinyMCETextEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TinyMCETextEditor.js","names":["TextEditor","TinyMCEEditor","tinyMCE","React","useMemo","sanitizeTextEditorHtml","StyledReadOnlyValue","TinyMCETextEditor","props","id","value","disabled","error","readonly","placeholder","rows","onChange","onBlur","onFocus","onKeyDown","init","baseHeight","rowHeight","height","undefined","sanitizedValue","createElement","dangerouslySetInnerHTML","__html","textareaName","plugins","concat","_toConsumableArray","defaultPlugins","_objectSpread","contextmenu","min_height","max_height"],"sources":["../../src/TextEditor/TinyMCETextEditor.tsx"],"sourcesContent":["import { TextEditor as TinyMCEEditor, tinyMCE } from '@procore/core-react'\nimport React, { useMemo } from 'react'\nimport { sanitizeTextEditorHtml } from '../TextEditorOutput/TextEditorOutput.utils'\nimport { StyledReadOnlyValue } from './TextEditor.styles'\nimport type { TextEditorProps } from './TextEditor.types'\n\nexport const TinyMCETextEditor = (props: TextEditorProps) => {\n const {\n id,\n value,\n disabled,\n error,\n readonly,\n placeholder,\n rows,\n onChange,\n onBlur,\n onFocus,\n onKeyDown,\n init,\n } = props\n\n const baseHeight = 74\n const rowHeight = 22\n const height = rows === undefined ? undefined : rows * rowHeight + baseHeight\n\n const sanitizedValue = useMemo(\n () => sanitizeTextEditorHtml(value || '') || '--',\n [value]\n )\n\n if (readonly) {\n return (\n <StyledReadOnlyValue>\n <div dangerouslySetInnerHTML={{ __html: sanitizedValue }} />\n </StyledReadOnlyValue>\n )\n }\n\n return (\n <TinyMCEEditor\n id={id}\n value={value}\n disabled={disabled}\n error={error}\n aria-label={props['aria-label']}\n textareaName={props['aria-label']}\n plugins={[...tinyMCE.defaultPlugins, 'link', 'table']}\n init={{\n contextmenu: false,\n min_height: height,\n max_height: height,\n placeholder,\n ...init,\n }}\n onChange={onChange}\n onBlur={onBlur as React.ComponentProps<typeof TinyMCEEditor>['onBlur']}\n onFocus={onFocus as React.ComponentProps<typeof TinyMCEEditor>['onFocus']}\n onKeyDown={\n onKeyDown as React.ComponentProps<typeof TinyMCEEditor>['onKeyDown']\n }\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAASA,UAAU,IAAIC,aAAa,EAAEC,OAAO,QAAQ,qBAAqB;AAC1E,OAAOC,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,sBAAsB,QAAQ,4CAA4C;AACnF,SAASC,mBAAmB,QAAQ,qBAAqB;AAGzD,OAAO,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAIC,KAAsB,EAAK;EAC3D,IACEC,EAAE,GAYAD,KAAK,CAZPC,EAAE;IACFC,KAAK,GAWHF,KAAK,CAXPE,KAAK;IACLC,QAAQ,GAUNH,KAAK,CAVPG,QAAQ;IACRC,KAAK,GASHJ,KAAK,CATPI,KAAK;IACLC,QAAQ,GAQNL,KAAK,CARPK,QAAQ;IACRC,WAAW,GAOTN,KAAK,CAPPM,WAAW;IACXC,IAAI,GAMFP,KAAK,CANPO,IAAI;IACJC,QAAQ,GAKNR,KAAK,CALPQ,QAAQ;IACRC,MAAM,GAIJT,KAAK,CAJPS,MAAM;IACNC,OAAO,GAGLV,KAAK,CAHPU,OAAO;IACPC,SAAS,GAEPX,KAAK,CAFPW,SAAS;IACTC,IAAI,GACFZ,KAAK,CADPY,IAAI;EAGN,IAAMC,UAAU,GAAG,EAAE;EACrB,IAAMC,SAAS,GAAG,EAAE;EACpB,IAAMC,MAAM,GAAGR,IAAI,KAAKS,SAAS,GAAGA,SAAS,GAAGT,IAAI,GAAGO,SAAS,GAAGD,UAAU;EAE7E,IAAMI,cAAc,GAAGrB,OAAO,CAC5B;IAAA,OAAMC,sBAAsB,CAACK,KAAK,IAAI,EAAE,CAAC,IAAI,IAAI;EAAA,GACjD,CAACA,KAAK,CACR,CAAC;EAED,IAAIG,QAAQ,EAAE;IACZ,oBACEV,KAAA,CAAAuB,aAAA,CAACpB,mBAAmB,qBAClBH,KAAA,CAAAuB,aAAA;MAAKC,uBAAuB,EAAE;QAAEC,MAAM,EAAEH;MAAe;IAAE,CAAE,CACxC,CAAC;EAE1B;EAEA,oBACEtB,KAAA,CAAAuB,aAAA,CAACzB,aAAa;IACZQ,EAAE,EAAEA,EAAG;IACPC,KAAK,EAAEA,KAAM;IACbC,QAAQ,EAAEA,QAAS;IACnBC,KAAK,EAAEA,KAAM;IACb,cAAYJ,KAAK,CAAC,YAAY,CAAE;IAChCqB,YAAY,EAAErB,KAAK,CAAC,YAAY,CAAE;IAClCsB,OAAO,KAAAC,MAAA,CAAAC,kBAAA,CAAM9B,OAAO,CAAC+B,cAAc,IAAE,MAAM,EAAE,OAAO,EAAE;IACtDb,IAAI,EAAAc,aAAA;MACFC,WAAW,EAAE,KAAK;MAClBC,UAAU,EAAEb,MAAM;MAClBc,UAAU,EAAEd,MAAM;MAClBT,WAAW,EAAXA;IAAW,GACRM,IAAI,CACP;IACFJ,QAAQ,EAAEA,QAAS;IACnBC,MAAM,EAAEA,MAA+D;IACvEC,OAAO,EAAEA,OAAiE;IAC1EC,SAAS,EACPA;EACD,CACF,CAAC;AAEN,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { UploadAdapter } from 'ckeditor5';
|
|
2
|
+
import { FileRepository, ImageUploadEditing, Plugin } from 'ckeditor5';
|
|
3
|
+
import type { TextEditorImageUploadHandlers } from '../../TextEditor.types';
|
|
4
|
+
interface UploadLoader {
|
|
5
|
+
file: Promise<File | null>;
|
|
6
|
+
uploaded?: number;
|
|
7
|
+
uploadTotal?: number | null;
|
|
8
|
+
}
|
|
9
|
+
declare type CkEditorUploadResponse = {
|
|
10
|
+
urls: {
|
|
11
|
+
default: string;
|
|
12
|
+
};
|
|
13
|
+
prostoreFileId: number | string;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
};
|
|
17
|
+
export declare class ProcoreImageUploadAdapter implements UploadAdapter {
|
|
18
|
+
private readonly loader;
|
|
19
|
+
private readonly imageUpload;
|
|
20
|
+
private readonly getEmbeddedImageCount?;
|
|
21
|
+
private abortController?;
|
|
22
|
+
private abortUpload?;
|
|
23
|
+
constructor(loader: UploadLoader, imageUpload: TextEditorImageUploadHandlers, getEmbeddedImageCount?: (() => number | undefined) | undefined);
|
|
24
|
+
upload(): Promise<CkEditorUploadResponse>;
|
|
25
|
+
abort(): void;
|
|
26
|
+
private validateFile;
|
|
27
|
+
private warnPdfUnsupportedFile;
|
|
28
|
+
private validateReadableImage;
|
|
29
|
+
private validateImageCount;
|
|
30
|
+
private toCkEditorResponse;
|
|
31
|
+
private get i18n();
|
|
32
|
+
private fileTypeLabel;
|
|
33
|
+
private uploadFile;
|
|
34
|
+
private fail;
|
|
35
|
+
private toSilentUploadError;
|
|
36
|
+
}
|
|
37
|
+
export declare class ProcoreImageUploadPlugin extends Plugin {
|
|
38
|
+
static get pluginName(): string;
|
|
39
|
+
static get requires(): (typeof FileRepository | typeof ImageUploadEditing)[];
|
|
40
|
+
init(): void;
|
|
41
|
+
private configureUploadAdapter;
|
|
42
|
+
private configureProstoreFileIdConversion;
|
|
43
|
+
private configurePastedImageLimit;
|
|
44
|
+
private configureUnsupportedFileDrop;
|
|
45
|
+
private canExtendSchemaElement;
|
|
46
|
+
private currentEmbeddedImageCountOrUndefined;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
3
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
4
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
5
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
6
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
7
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
8
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
9
|
+
function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
|
|
10
|
+
function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
|
|
11
|
+
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
|
|
12
|
+
function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
|
|
13
|
+
function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
|
|
14
|
+
function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
|
|
15
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
16
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
|
|
17
|
+
function _OverloadYield(e, d) { this.v = e, this.k = d; }
|
|
18
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
19
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
20
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
21
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
22
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
24
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
25
|
+
import { ClipboardPipeline, FileRepository, ImageUploadEditing, Plugin } from 'ckeditor5';
|
|
26
|
+
import { DEFAULT_ALLOWED_MIME_TYPES, IMAGE_TYPE_LABELS, MAX_IMAGE_UPLOAD_FILE_SIZE_BYTES, MAX_RICH_TEXT_IMAGES, PDF_UNSUPPORTED_MIME_TYPES, RICH_TEXT_EDITOR_FILE_ID_ATTRIBUTE } from '../../utils/imageAttributes';
|
|
27
|
+
import { canonicalizeTextEditorImageUrl } from '../../utils/imageUrls';
|
|
28
|
+
var REPORTED_UPLOAD_ERROR = '';
|
|
29
|
+
var exceedsImageLimit = function exceedsImageLimit(currentImageCount) {
|
|
30
|
+
var newImageCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
31
|
+
return currentImageCount + newImageCount > MAX_RICH_TEXT_IMAGES;
|
|
32
|
+
};
|
|
33
|
+
export var ProcoreImageUploadAdapter = /*#__PURE__*/function () {
|
|
34
|
+
function ProcoreImageUploadAdapter(loader, imageUpload, getEmbeddedImageCount) {
|
|
35
|
+
_classCallCheck(this, ProcoreImageUploadAdapter);
|
|
36
|
+
this.loader = loader;
|
|
37
|
+
this.imageUpload = imageUpload;
|
|
38
|
+
this.getEmbeddedImageCount = getEmbeddedImageCount;
|
|
39
|
+
}
|
|
40
|
+
return _createClass(ProcoreImageUploadAdapter, [{
|
|
41
|
+
key: "upload",
|
|
42
|
+
value: function () {
|
|
43
|
+
var _upload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
44
|
+
var file, result;
|
|
45
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
46
|
+
while (1) switch (_context.prev = _context.next) {
|
|
47
|
+
case 0:
|
|
48
|
+
this.abortController = new AbortController();
|
|
49
|
+
_context.prev = 1;
|
|
50
|
+
_context.next = 4;
|
|
51
|
+
return this.loader.file;
|
|
52
|
+
case 4:
|
|
53
|
+
file = _context.sent;
|
|
54
|
+
if (file) {
|
|
55
|
+
_context.next = 7;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.noFile'));
|
|
59
|
+
case 7:
|
|
60
|
+
this.validateFile(file);
|
|
61
|
+
this.warnPdfUnsupportedFile(file);
|
|
62
|
+
_context.next = 11;
|
|
63
|
+
return this.validateReadableImage(file);
|
|
64
|
+
case 11:
|
|
65
|
+
this.validateImageCount();
|
|
66
|
+
_context.next = 14;
|
|
67
|
+
return this.uploadFile(file);
|
|
68
|
+
case 14:
|
|
69
|
+
result = _context.sent;
|
|
70
|
+
if (!this.abortController.signal.aborted) {
|
|
71
|
+
_context.next = 17;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.aborted'));
|
|
75
|
+
case 17:
|
|
76
|
+
return _context.abrupt("return", this.toCkEditorResponse(result));
|
|
77
|
+
case 20:
|
|
78
|
+
_context.prev = 20;
|
|
79
|
+
_context.t0 = _context["catch"](1);
|
|
80
|
+
throw this.toSilentUploadError(_context.t0);
|
|
81
|
+
case 23:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context.stop();
|
|
84
|
+
}
|
|
85
|
+
}, _callee, this, [[1, 20]]);
|
|
86
|
+
}));
|
|
87
|
+
function upload() {
|
|
88
|
+
return _upload.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
return upload;
|
|
91
|
+
}()
|
|
92
|
+
}, {
|
|
93
|
+
key: "abort",
|
|
94
|
+
value: function abort() {
|
|
95
|
+
var _this$abortController, _this$abortUpload;
|
|
96
|
+
(_this$abortController = this.abortController) === null || _this$abortController === void 0 ? void 0 : _this$abortController.abort();
|
|
97
|
+
(_this$abortUpload = this.abortUpload) === null || _this$abortUpload === void 0 ? void 0 : _this$abortUpload.call(this);
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "validateFile",
|
|
101
|
+
value: function validateFile(file) {
|
|
102
|
+
if (!DEFAULT_ALLOWED_MIME_TYPES.has(file.type)) {
|
|
103
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.unsupportedType', {
|
|
104
|
+
type: this.fileTypeLabel(file)
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
if (file.size > MAX_IMAGE_UPLOAD_FILE_SIZE_BYTES) {
|
|
108
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.fileTooLarge'));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "warnPdfUnsupportedFile",
|
|
113
|
+
value: function warnPdfUnsupportedFile(file) {
|
|
114
|
+
var _this$imageUpload$onW, _this$imageUpload;
|
|
115
|
+
if (!PDF_UNSUPPORTED_MIME_TYPES.has(file.type)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
(_this$imageUpload$onW = (_this$imageUpload = this.imageUpload).onWarning) === null || _this$imageUpload$onW === void 0 ? void 0 : _this$imageUpload$onW.call(_this$imageUpload, this.i18n.t('textEditor.imageUpload.pdfUnsupportedType', {
|
|
119
|
+
type: this.fileTypeLabel(file)
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "validateReadableImage",
|
|
124
|
+
value: function () {
|
|
125
|
+
var _validateReadableImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(file) {
|
|
126
|
+
var url, image;
|
|
127
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
128
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
129
|
+
case 0:
|
|
130
|
+
url = URL.createObjectURL(file);
|
|
131
|
+
_context2.prev = 1;
|
|
132
|
+
image = new Image();
|
|
133
|
+
_context2.next = 5;
|
|
134
|
+
return new Promise(function (resolve, reject) {
|
|
135
|
+
image.onload = function () {
|
|
136
|
+
return resolve();
|
|
137
|
+
};
|
|
138
|
+
image.onerror = function () {
|
|
139
|
+
return reject(new Error());
|
|
140
|
+
};
|
|
141
|
+
image.src = url;
|
|
142
|
+
});
|
|
143
|
+
case 5:
|
|
144
|
+
_context2.next = 10;
|
|
145
|
+
break;
|
|
146
|
+
case 7:
|
|
147
|
+
_context2.prev = 7;
|
|
148
|
+
_context2.t0 = _context2["catch"](1);
|
|
149
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.unreadable'));
|
|
150
|
+
case 10:
|
|
151
|
+
_context2.prev = 10;
|
|
152
|
+
URL.revokeObjectURL(url);
|
|
153
|
+
return _context2.finish(10);
|
|
154
|
+
case 13:
|
|
155
|
+
case "end":
|
|
156
|
+
return _context2.stop();
|
|
157
|
+
}
|
|
158
|
+
}, _callee2, this, [[1, 7, 10, 13]]);
|
|
159
|
+
}));
|
|
160
|
+
function validateReadableImage(_x) {
|
|
161
|
+
return _validateReadableImage.apply(this, arguments);
|
|
162
|
+
}
|
|
163
|
+
return validateReadableImage;
|
|
164
|
+
}()
|
|
165
|
+
}, {
|
|
166
|
+
key: "validateImageCount",
|
|
167
|
+
value: function validateImageCount() {
|
|
168
|
+
var _this$getEmbeddedImag;
|
|
169
|
+
var embeddedImageCount = (_this$getEmbeddedImag = this.getEmbeddedImageCount) === null || _this$getEmbeddedImag === void 0 ? void 0 : _this$getEmbeddedImag.call(this);
|
|
170
|
+
if (embeddedImageCount !== undefined && exceedsImageLimit(embeddedImageCount)) {
|
|
171
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.imageLimit', {
|
|
172
|
+
count: MAX_RICH_TEXT_IMAGES
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, {
|
|
177
|
+
key: "toCkEditorResponse",
|
|
178
|
+
value: function toCkEditorResponse(result) {
|
|
179
|
+
if (!result.prostoreFileId || !/^[\w-]+$/.test(String(result.prostoreFileId))) {
|
|
180
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.invalidProstoreFileId'));
|
|
181
|
+
}
|
|
182
|
+
var defaultUrl = canonicalizeTextEditorImageUrl(result.urls["default"]);
|
|
183
|
+
if (!defaultUrl) {
|
|
184
|
+
throw this.fail(this.i18n.t('textEditor.imageUpload.invalidImageUrl'));
|
|
185
|
+
}
|
|
186
|
+
var response = {
|
|
187
|
+
urls: {
|
|
188
|
+
"default": defaultUrl
|
|
189
|
+
},
|
|
190
|
+
prostoreFileId: result.prostoreFileId,
|
|
191
|
+
width: result.width,
|
|
192
|
+
height: result.height
|
|
193
|
+
};
|
|
194
|
+
return response;
|
|
195
|
+
}
|
|
196
|
+
}, {
|
|
197
|
+
key: "i18n",
|
|
198
|
+
get: function get() {
|
|
199
|
+
return this.imageUpload.i18n;
|
|
200
|
+
}
|
|
201
|
+
}, {
|
|
202
|
+
key: "fileTypeLabel",
|
|
203
|
+
value: function fileTypeLabel(file) {
|
|
204
|
+
return _fileTypeLabel(file);
|
|
205
|
+
}
|
|
206
|
+
}, {
|
|
207
|
+
key: "uploadFile",
|
|
208
|
+
value: function uploadFile(file) {
|
|
209
|
+
var _this = this;
|
|
210
|
+
return new Promise(function (resolve, reject) {
|
|
211
|
+
_this.abortUpload = function () {
|
|
212
|
+
return reject(_this.fail(_this.i18n.t('textEditor.imageUpload.aborted')));
|
|
213
|
+
};
|
|
214
|
+
_this.imageUpload.upload(file, {
|
|
215
|
+
signal: _this.abortController.signal
|
|
216
|
+
}, {
|
|
217
|
+
onProgress: function onProgress(uploaded, total) {
|
|
218
|
+
_this.loader.uploaded = uploaded;
|
|
219
|
+
if (total !== undefined) {
|
|
220
|
+
_this.loader.uploadTotal = total;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}).then(resolve)["catch"](reject);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}, {
|
|
227
|
+
key: "fail",
|
|
228
|
+
value: function fail(message) {
|
|
229
|
+
var _this$imageUpload$onE, _this$imageUpload2;
|
|
230
|
+
(_this$imageUpload$onE = (_this$imageUpload2 = this.imageUpload).onError) === null || _this$imageUpload$onE === void 0 ? void 0 : _this$imageUpload$onE.call(_this$imageUpload2, message);
|
|
231
|
+
return REPORTED_UPLOAD_ERROR;
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "toSilentUploadError",
|
|
235
|
+
value: function toSilentUploadError(error) {
|
|
236
|
+
if (error === REPORTED_UPLOAD_ERROR) {
|
|
237
|
+
return error;
|
|
238
|
+
}
|
|
239
|
+
if (error instanceof Error && error.message) {
|
|
240
|
+
return this.fail(error.message);
|
|
241
|
+
}
|
|
242
|
+
return this.fail(this.i18n.t('textEditor.imageUpload.failed'));
|
|
243
|
+
}
|
|
244
|
+
}]);
|
|
245
|
+
}();
|
|
246
|
+
export var ProcoreImageUploadPlugin = /*#__PURE__*/function (_Plugin) {
|
|
247
|
+
function ProcoreImageUploadPlugin() {
|
|
248
|
+
_classCallCheck(this, ProcoreImageUploadPlugin);
|
|
249
|
+
return _callSuper(this, ProcoreImageUploadPlugin, arguments);
|
|
250
|
+
}
|
|
251
|
+
_inherits(ProcoreImageUploadPlugin, _Plugin);
|
|
252
|
+
return _createClass(ProcoreImageUploadPlugin, [{
|
|
253
|
+
key: "init",
|
|
254
|
+
value: function init() {
|
|
255
|
+
var imageUpload = this.editor.config.get('procoreImageUpload');
|
|
256
|
+
if (!imageUpload) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this.configureProstoreFileIdConversion();
|
|
260
|
+
this.configureUploadAdapter(imageUpload);
|
|
261
|
+
this.configureUnsupportedFileDrop(imageUpload);
|
|
262
|
+
this.configurePastedImageLimit(imageUpload);
|
|
263
|
+
}
|
|
264
|
+
}, {
|
|
265
|
+
key: "configureUploadAdapter",
|
|
266
|
+
value: function configureUploadAdapter(imageUpload) {
|
|
267
|
+
var _this2 = this;
|
|
268
|
+
var fileRepository = this.editor.plugins.get(FileRepository);
|
|
269
|
+
fileRepository.createUploadAdapter = function (loader) {
|
|
270
|
+
return new ProcoreImageUploadAdapter(loader, imageUpload, function () {
|
|
271
|
+
return _this2.currentEmbeddedImageCountOrUndefined();
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
var imageUploadEditing = this.editor.plugins.get(ImageUploadEditing);
|
|
275
|
+
imageUploadEditing.on('uploadComplete', function (_event, _ref) {
|
|
276
|
+
var data = _ref.data,
|
|
277
|
+
imageElement = _ref.imageElement;
|
|
278
|
+
if (!imageElement || !(data !== null && data !== void 0 && data.prostoreFileId)) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
var prostoreFileId = String(data.prostoreFileId);
|
|
282
|
+
_this2.editor.model.change(function (writer) {
|
|
283
|
+
writer.setAttribute('prostoreFileId', prostoreFileId, imageElement);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}, {
|
|
288
|
+
key: "configureProstoreFileIdConversion",
|
|
289
|
+
value: function configureProstoreFileIdConversion() {
|
|
290
|
+
var _this3 = this;
|
|
291
|
+
var imageModelNames = ['imageBlock', 'imageInline'];
|
|
292
|
+
imageModelNames.forEach(function (imageModelName) {
|
|
293
|
+
if (_this3.canExtendSchemaElement(imageModelName)) {
|
|
294
|
+
_this3.editor.model.schema.extend(imageModelName, {
|
|
295
|
+
allowAttributes: ['prostoreFileId']
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
this.editor.conversion["for"]('upcast').attributeToAttribute({
|
|
300
|
+
view: {
|
|
301
|
+
name: 'figure',
|
|
302
|
+
key: RICH_TEXT_EDITOR_FILE_ID_ATTRIBUTE
|
|
303
|
+
},
|
|
304
|
+
model: 'prostoreFileId'
|
|
305
|
+
});
|
|
306
|
+
this.editor.conversion["for"]('upcast').attributeToAttribute({
|
|
307
|
+
view: {
|
|
308
|
+
name: 'img',
|
|
309
|
+
key: RICH_TEXT_EDITOR_FILE_ID_ATTRIBUTE
|
|
310
|
+
},
|
|
311
|
+
model: 'prostoreFileId'
|
|
312
|
+
});
|
|
313
|
+
this.editor.conversion["for"]('downcast').attributeToAttribute({
|
|
314
|
+
model: 'prostoreFileId',
|
|
315
|
+
view: function view(value) {
|
|
316
|
+
return {
|
|
317
|
+
key: RICH_TEXT_EDITOR_FILE_ID_ATTRIBUTE,
|
|
318
|
+
value: String(value)
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}, {
|
|
324
|
+
key: "configurePastedImageLimit",
|
|
325
|
+
value: function configurePastedImageLimit(imageUpload) {
|
|
326
|
+
var _this4 = this;
|
|
327
|
+
var clipboardPipeline = this.editor.plugins.get(ClipboardPipeline);
|
|
328
|
+
clipboardPipeline.on('inputTransformation', function (event, data) {
|
|
329
|
+
var currentImageCount = _this4.currentEmbeddedImageCountOrUndefined();
|
|
330
|
+
if (currentImageCount === undefined) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
var pastedImageCount = countImages(data.content);
|
|
334
|
+
if (exceedsImageLimit(currentImageCount, pastedImageCount)) {
|
|
335
|
+
var _event$stop, _imageUpload$onError;
|
|
336
|
+
(_event$stop = event.stop) === null || _event$stop === void 0 ? void 0 : _event$stop.call(event);
|
|
337
|
+
(_imageUpload$onError = imageUpload.onError) === null || _imageUpload$onError === void 0 ? void 0 : _imageUpload$onError.call(imageUpload, imageUpload.i18n.t('textEditor.imageUpload.imageLimit', {
|
|
338
|
+
count: MAX_RICH_TEXT_IMAGES
|
|
339
|
+
}));
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}, {
|
|
344
|
+
key: "configureUnsupportedFileDrop",
|
|
345
|
+
value: function configureUnsupportedFileDrop(imageUpload) {
|
|
346
|
+
this.listenTo(this.editor.editing.view.document, 'clipboardInput', function (event, data) {
|
|
347
|
+
var _imageUpload$onError2;
|
|
348
|
+
var files = data.dataTransfer.files;
|
|
349
|
+
if (files.length === 0) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
var unsupportedFile = files.find(function (file) {
|
|
353
|
+
return !DEFAULT_ALLOWED_MIME_TYPES.has(file.type);
|
|
354
|
+
});
|
|
355
|
+
if (!unsupportedFile) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
(_imageUpload$onError2 = imageUpload.onError) === null || _imageUpload$onError2 === void 0 ? void 0 : _imageUpload$onError2.call(imageUpload, imageUpload.i18n.t('textEditor.imageUpload.unsupportedType', {
|
|
359
|
+
type: _fileTypeLabel(unsupportedFile)
|
|
360
|
+
}));
|
|
361
|
+
if (files.every(function (file) {
|
|
362
|
+
return !DEFAULT_ALLOWED_MIME_TYPES.has(file.type);
|
|
363
|
+
})) {
|
|
364
|
+
event.stop();
|
|
365
|
+
}
|
|
366
|
+
}, {
|
|
367
|
+
priority: 'high'
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}, {
|
|
371
|
+
key: "canExtendSchemaElement",
|
|
372
|
+
value: function canExtendSchemaElement(imageModelName) {
|
|
373
|
+
var schema = this.editor.model.schema;
|
|
374
|
+
return typeof schema.isRegistered === 'function' ? schema.isRegistered(imageModelName) : true;
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "currentEmbeddedImageCountOrUndefined",
|
|
378
|
+
value: function currentEmbeddedImageCountOrUndefined() {
|
|
379
|
+
var _this5 = this;
|
|
380
|
+
try {
|
|
381
|
+
return this.editor.model.document.getRootNames().reduce(function (total, rootName) {
|
|
382
|
+
var root = _this5.editor.model.document.getRoot(rootName);
|
|
383
|
+
return root ? total + countModelImages(root) : total;
|
|
384
|
+
}, 0);
|
|
385
|
+
} catch (_error) {
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}], [{
|
|
390
|
+
key: "pluginName",
|
|
391
|
+
get: function get() {
|
|
392
|
+
return 'ProcoreImageUploadPlugin';
|
|
393
|
+
}
|
|
394
|
+
}, {
|
|
395
|
+
key: "requires",
|
|
396
|
+
get: function get() {
|
|
397
|
+
return [FileRepository, ImageUploadEditing];
|
|
398
|
+
}
|
|
399
|
+
}]);
|
|
400
|
+
}(Plugin);
|
|
401
|
+
function countImages(node) {
|
|
402
|
+
if (!node.is('element') && !node.is('documentFragment')) {
|
|
403
|
+
return 0;
|
|
404
|
+
}
|
|
405
|
+
var imageCount = 0;
|
|
406
|
+
for (var _i = 0, _Array$from = Array.from(node.getChildren()); _i < _Array$from.length; _i++) {
|
|
407
|
+
var child = _Array$from[_i];
|
|
408
|
+
if (child.is('element', 'img')) {
|
|
409
|
+
imageCount += 1;
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
imageCount += countImages(child);
|
|
413
|
+
}
|
|
414
|
+
return imageCount;
|
|
415
|
+
}
|
|
416
|
+
function countModelImages(node) {
|
|
417
|
+
var imageCount = isImageModelElement(node) ? 1 : 0;
|
|
418
|
+
for (var _i2 = 0, _Array$from2 = Array.from(node.getChildren()); _i2 < _Array$from2.length; _i2++) {
|
|
419
|
+
var child = _Array$from2[_i2];
|
|
420
|
+
if (child.is('element')) {
|
|
421
|
+
imageCount += countModelImages(child);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return imageCount;
|
|
425
|
+
}
|
|
426
|
+
function isImageModelElement(item) {
|
|
427
|
+
return item.is('element', 'imageBlock') || item.is('element', 'imageInline');
|
|
428
|
+
}
|
|
429
|
+
function _fileTypeLabel(file) {
|
|
430
|
+
var _IMAGE_TYPE_LABELS$fi;
|
|
431
|
+
var fileType = (_IMAGE_TYPE_LABELS$fi = IMAGE_TYPE_LABELS[file.type]) !== null && _IMAGE_TYPE_LABELS$fi !== void 0 ? _IMAGE_TYPE_LABELS$fi : fileExtensionLabel(file.name);
|
|
432
|
+
return fileType ? "".concat(fileType, " ") : '';
|
|
433
|
+
}
|
|
434
|
+
function fileExtensionLabel(fileName) {
|
|
435
|
+
var extension = fileName.split('.').pop();
|
|
436
|
+
if (!extension || extension === fileName) {
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
return extension.toUpperCase();
|
|
440
|
+
}
|
|
441
|
+
//# sourceMappingURL=ProcoreImageUploadPlugin.js.map
|