@procore/text-editor 0.5.0 → 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 +30 -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/NormalizeTableWidthPlugin/NormalizeTableWidthPlugin.d.ts +15 -0
- package/dist/TextEditor/plugins/NormalizeTableWidthPlugin/NormalizeTableWidthPlugin.js +72 -0
- package/dist/TextEditor/plugins/NormalizeTableWidthPlugin/NormalizeTableWidthPlugin.js.map +1 -0
- package/dist/TextEditor/plugins/NormalizeTableWidthPlugin/index.d.ts +1 -0
- package/dist/TextEditor/plugins/NormalizeTableWidthPlugin/index.js +2 -0
- package/dist/TextEditor/plugins/NormalizeTableWidthPlugin/index.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 +25 -10
- 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/dist/utils/debounce.js +4 -4
- package/dist/utils/debounce.js.map +1 -1
- 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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ACFC,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,15 @@
|
|
|
1
|
+
import { Plugin } from 'ckeditor5';
|
|
2
|
+
/**
|
|
3
|
+
* Fixes broken table widths injected when pasting from a spreadsheet
|
|
4
|
+
* (Excel / Google Sheets). Such content arrives with `width:0px` on the table
|
|
5
|
+
* figure/table and can produce `width:NaN%` columns, collapsing the table.
|
|
6
|
+
*
|
|
7
|
+
* We intercept the clipboard `inputTransformation` (runs on the pasted view
|
|
8
|
+
* fragment, before it becomes editor content) and normalize widths at the
|
|
9
|
+
* source, so the bogus values never enter the model — keeping both the editing
|
|
10
|
+
* view and the saved data correct.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NormalizeTableWidthPlugin extends Plugin {
|
|
13
|
+
static get pluginName(): string;
|
|
14
|
+
init(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
3
|
+
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); } }
|
|
4
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), 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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
8
|
+
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); }
|
|
9
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
10
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
12
|
+
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); }
|
|
13
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
14
|
+
import { Plugin, UpcastWriter } from 'ckeditor5';
|
|
15
|
+
var isInvalidWidth = function isInvalidWidth(width) {
|
|
16
|
+
if (!width) return false;
|
|
17
|
+
if (/nan/i.test(width)) return true;
|
|
18
|
+
var numeric = Number.parseFloat(width);
|
|
19
|
+
return Number.isNaN(numeric) || numeric === 0;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fixes broken table widths injected when pasting from a spreadsheet
|
|
24
|
+
* (Excel / Google Sheets). Such content arrives with `width:0px` on the table
|
|
25
|
+
* figure/table and can produce `width:NaN%` columns, collapsing the table.
|
|
26
|
+
*
|
|
27
|
+
* We intercept the clipboard `inputTransformation` (runs on the pasted view
|
|
28
|
+
* fragment, before it becomes editor content) and normalize widths at the
|
|
29
|
+
* source, so the bogus values never enter the model — keeping both the editing
|
|
30
|
+
* view and the saved data correct.
|
|
31
|
+
*/
|
|
32
|
+
export var NormalizeTableWidthPlugin = /*#__PURE__*/function (_Plugin) {
|
|
33
|
+
function NormalizeTableWidthPlugin() {
|
|
34
|
+
_classCallCheck(this, NormalizeTableWidthPlugin);
|
|
35
|
+
return _callSuper(this, NormalizeTableWidthPlugin, arguments);
|
|
36
|
+
}
|
|
37
|
+
_inherits(NormalizeTableWidthPlugin, _Plugin);
|
|
38
|
+
return _createClass(NormalizeTableWidthPlugin, [{
|
|
39
|
+
key: "init",
|
|
40
|
+
value: function init() {
|
|
41
|
+
var editor = this.editor;
|
|
42
|
+
var clipboardPipeline = editor.plugins.get('ClipboardPipeline');
|
|
43
|
+
clipboardPipeline.on('inputTransformation', function (_evt, data) {
|
|
44
|
+
var writer = new UpcastWriter(editor.editing.view.document);
|
|
45
|
+
normalizeNode(data.content, writer);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}], [{
|
|
49
|
+
key: "pluginName",
|
|
50
|
+
get: function get() {
|
|
51
|
+
return 'NormalizeTableWidth';
|
|
52
|
+
}
|
|
53
|
+
}]);
|
|
54
|
+
}(Plugin);
|
|
55
|
+
function normalizeNode(node, writer) {
|
|
56
|
+
var _element$getChildren;
|
|
57
|
+
var element = node;
|
|
58
|
+
if (element.is('element', 'figure') || element.is('element', 'table')) {
|
|
59
|
+
if (isInvalidWidth(element.getStyle('width'))) {
|
|
60
|
+
writer.removeStyle('width', element);
|
|
61
|
+
writer.setStyle('width', '100%', element);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var children = (_element$getChildren = element.getChildren) === null || _element$getChildren === void 0 ? void 0 : _element$getChildren.call(element);
|
|
65
|
+
if (children) {
|
|
66
|
+
for (var _i = 0, _Array$from = Array.from(children); _i < _Array$from.length; _i++) {
|
|
67
|
+
var child = _Array$from[_i];
|
|
68
|
+
normalizeNode(child, writer);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=NormalizeTableWidthPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NormalizeTableWidthPlugin.js","names":["Plugin","UpcastWriter","isInvalidWidth","width","test","numeric","Number","parseFloat","isNaN","NormalizeTableWidthPlugin","_Plugin","_classCallCheck","_callSuper","arguments","_inherits","_createClass","key","value","init","editor","clipboardPipeline","plugins","get","on","_evt","data","writer","editing","view","document","normalizeNode","content","node","_element$getChildren","element","is","getStyle","removeStyle","setStyle","children","getChildren","call","_i","_Array$from","Array","from","length","child"],"sources":["../../../../src/TextEditor/plugins/NormalizeTableWidthPlugin/NormalizeTableWidthPlugin.ts"],"sourcesContent":["import type { ViewDocumentFragment, ViewElement, ViewNode } from 'ckeditor5'\nimport { Plugin, UpcastWriter } from 'ckeditor5'\n\nconst isInvalidWidth = (width: string | undefined): boolean => {\n if (!width) return false\n if (/nan/i.test(width)) return true\n const numeric = Number.parseFloat(width)\n return Number.isNaN(numeric) || numeric === 0\n}\n\n/**\n * Fixes broken table widths injected when pasting from a spreadsheet\n * (Excel / Google Sheets). Such content arrives with `width:0px` on the table\n * figure/table and can produce `width:NaN%` columns, collapsing the table.\n *\n * We intercept the clipboard `inputTransformation` (runs on the pasted view\n * fragment, before it becomes editor content) and normalize widths at the\n * source, so the bogus values never enter the model — keeping both the editing\n * view and the saved data correct.\n */\nexport class NormalizeTableWidthPlugin extends Plugin {\n static get pluginName() {\n return 'NormalizeTableWidth'\n }\n\n init() {\n const editor = this.editor\n const clipboardPipeline = editor.plugins.get('ClipboardPipeline')\n clipboardPipeline.on('inputTransformation', (_evt, data) => {\n const writer = new UpcastWriter(editor.editing.view.document)\n normalizeNode(data.content, writer)\n })\n }\n}\n\nfunction normalizeNode(\n node: ViewNode | ViewDocumentFragment,\n writer: UpcastWriter\n): void {\n const element = node as ViewElement\n\n if (element.is('element', 'figure') || element.is('element', 'table')) {\n if (isInvalidWidth(element.getStyle('width'))) {\n writer.removeStyle('width', element)\n writer.setStyle('width', '100%', element)\n }\n }\n\n const children = element.getChildren?.()\n if (children) {\n for (const child of Array.from(children)) {\n normalizeNode(child, writer)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AACA,SAASA,MAAM,EAAEC,YAAY,QAAQ,WAAW;AAEhD,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,KAAyB,EAAc;EAC7D,IAAI,CAACA,KAAK,EAAE,OAAO,KAAK;EACxB,IAAI,MAAM,CAACC,IAAI,CAACD,KAAK,CAAC,EAAE,OAAO,IAAI;EACnC,IAAME,OAAO,GAAGC,MAAM,CAACC,UAAU,CAACJ,KAAK,CAAC;EACxC,OAAOG,MAAM,CAACE,KAAK,CAACH,OAAO,CAAC,IAAIA,OAAO,KAAK,CAAC;AAC/C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAaI,yBAAyB,0BAAAC,OAAA;EAAA,SAAAD,0BAAA;IAAAE,eAAA,OAAAF,yBAAA;IAAA,OAAAG,UAAA,OAAAH,yBAAA,EAAAI,SAAA;EAAA;EAAAC,SAAA,CAAAL,yBAAA,EAAAC,OAAA;EAAA,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K,CAACC,IAAI,CAACN,QAAQ,CAAC,EAAAG,EAAA,GAAAC,WAAA,CAAAG,MAAA,EAAAJ,EAAA,IAAE;MAArC,IAAMK,KAAK,GAAAJ,WAAA,CAAAD,EAAA;MACdZ,aAAa,CAACiB,KAAK,EAAErB,MAAM,CAAC;IAC9B;EACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NormalizeTableWidthPlugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/TextEditor/plugins/NormalizeTableWidthPlugin/index.ts"],"sourcesContent":["export * from './NormalizeTableWidthPlugin'\n"],"mappings":"AAAA,cAAc,6BAA6B"}
|
|
@@ -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 {};
|