@procore/text-editor 0.0.1
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 +67 -0
- package/.jest/esToolkitMock.js +23 -0
- package/.jest/setupTests.js +33 -0
- package/.jest/styleMock.js +1 -0
- package/.jest/svgTransform.js +10 -0
- package/.jest/translationFileMock.js +4 -0
- package/.jest/translationMock.js +12 -0
- package/LICENSE +84 -0
- package/README.md +107 -0
- package/codemod/__fixtures__/hammer.config.mjs +15 -0
- package/codemod/__fixtures__/jest.config.js +6 -0
- package/codemod/__fixtures__/procore.config.js +12 -0
- package/codemod/__fixtures__/src/components/ComplexEditor.tsx +21 -0
- package/codemod/__fixtures__/src/components/FormWithRichText.tsx +10 -0
- package/codemod/__fixtures__/src/components/MultilineFormRichText.tsx +14 -0
- package/codemod/__fixtures__/src/components/NoTextEditor.tsx +11 -0
- package/codemod/__fixtures__/src/components/ReadOnlyRichText.tsx +10 -0
- package/codemod/__fixtures__/src/components/SimpleEditor.tsx +11 -0
- package/codemod/__fixtures__/src/components/TypeImportEditor.tsx +17 -0
- package/codemod/text-editor-migrate.js +509 -0
- package/codemod/text-editor-migrate.test.js +225 -0
- package/dist/TextEditor/EditorError.js +9 -0
- package/dist/TextEditor/EditorError.js.map +1 -0
- package/dist/TextEditor/StickyToolbar/index.js +2 -0
- package/dist/TextEditor/StickyToolbar/index.js.map +1 -0
- package/dist/TextEditor/StickyToolbar/useStickyToolbar.js +59 -0
- package/dist/TextEditor/StickyToolbar/useStickyToolbar.js.map +1 -0
- package/dist/TextEditor/StickyToolbar/useStickyToolbar.types.js +2 -0
- package/dist/TextEditor/StickyToolbar/useStickyToolbar.types.js.map +1 -0
- package/dist/TextEditor/TextEditor.js +226 -0
- package/dist/TextEditor/TextEditor.js.map +1 -0
- package/dist/TextEditor/TextEditor.styles.js +26 -0
- package/dist/TextEditor/TextEditor.styles.js.map +1 -0
- package/dist/TextEditor/TextEditor.types.js +2 -0
- package/dist/TextEditor/TextEditor.types.js.map +1 -0
- package/dist/TextEditor/TextEditorProvider.js +17 -0
- package/dist/TextEditor/TextEditorProvider.js.map +1 -0
- package/dist/TextEditor/TextEditorProvider.types.js +2 -0
- package/dist/TextEditor/TextEditorProvider.types.js.map +1 -0
- package/dist/TextEditor/index.js +4 -0
- package/dist/TextEditor/index.js.map +1 -0
- package/dist/TextEditor/license_key.js +3 -0
- package/dist/TextEditor/license_key.js.map +1 -0
- package/dist/TextEditor/plugins/CutPlugin/CutCommand.js +99 -0
- package/dist/TextEditor/plugins/CutPlugin/CutCommand.js.map +1 -0
- package/dist/TextEditor/plugins/CutPlugin/CutPlugin.js +56 -0
- package/dist/TextEditor/plugins/CutPlugin/CutPlugin.js.map +1 -0
- package/dist/TextEditor/plugins/CutPlugin/index.js +2 -0
- package/dist/TextEditor/plugins/CutPlugin/index.js.map +1 -0
- package/dist/TextEditor/plugins/IndentPaddingToMarginPlugin/IndentPaddingToMarginPlugin.js +40 -0
- package/dist/TextEditor/plugins/IndentPaddingToMarginPlugin/IndentPaddingToMarginPlugin.js.map +1 -0
- package/dist/TextEditor/plugins/IndentPaddingToMarginPlugin/index.js +2 -0
- package/dist/TextEditor/plugins/IndentPaddingToMarginPlugin/index.js.map +1 -0
- package/dist/TextEditor/plugins/PasteAsTextPlugin/PasteAsTextCommand.js +86 -0
- package/dist/TextEditor/plugins/PasteAsTextPlugin/PasteAsTextCommand.js.map +1 -0
- package/dist/TextEditor/plugins/PasteAsTextPlugin/PasteAsTextPlugin.js +56 -0
- package/dist/TextEditor/plugins/PasteAsTextPlugin/PasteAsTextPlugin.js.map +1 -0
- package/dist/TextEditor/plugins/PasteAsTextPlugin/index.js +2 -0
- package/dist/TextEditor/plugins/PasteAsTextPlugin/index.js.map +1 -0
- package/dist/TextEditor/plugins/PastePlugin/PasteCommand.js +149 -0
- package/dist/TextEditor/plugins/PastePlugin/PasteCommand.js.map +1 -0
- package/dist/TextEditor/plugins/PastePlugin/PastePlugin.js +56 -0
- package/dist/TextEditor/plugins/PastePlugin/PastePlugin.js.map +1 -0
- package/dist/TextEditor/plugins/PastePlugin/index.js +2 -0
- package/dist/TextEditor/plugins/PastePlugin/index.js.map +1 -0
- package/dist/TextEditor/plugins/TabSpacesPlugin/TabSpacesPlugin.js +87 -0
- package/dist/TextEditor/plugins/TabSpacesPlugin/TabSpacesPlugin.js.map +1 -0
- package/dist/TextEditor/plugins/TabSpacesPlugin/index.js +2 -0
- package/dist/TextEditor/plugins/TabSpacesPlugin/index.js.map +1 -0
- package/dist/TextEditor/textEditorTheming/icons.js +24 -0
- package/dist/TextEditor/textEditorTheming/icons.js.map +1 -0
- package/dist/TextEditor/textEditorTheming/index.js +2 -0
- package/dist/TextEditor/textEditorTheming/index.js.map +1 -0
- package/dist/TextEditor/textEditorTheming/textEditorTheming.styles.js +10 -0
- package/dist/TextEditor/textEditorTheming/textEditorTheming.styles.js.map +1 -0
- package/dist/TextEditor/useCKEditorCss.js +36 -0
- package/dist/TextEditor/useCKEditorCss.js.map +1 -0
- package/dist/TextEditor/useTabAsNavigation.js +29 -0
- package/dist/TextEditor/useTabAsNavigation.js.map +1 -0
- package/dist/TextEditor/utils/config.js +179 -0
- package/dist/TextEditor/utils/config.js.map +1 -0
- package/dist/TextEditor/utils/index.js +3 -0
- package/dist/TextEditor/utils/index.js.map +1 -0
- package/dist/TextEditor/utils/locale.js +102 -0
- package/dist/TextEditor/utils/locale.js.map +1 -0
- package/dist/TextEditor/utils/plugins.js +184 -0
- package/dist/TextEditor/utils/plugins.js.map +1 -0
- package/dist/TextEditorOutput/TextEditorOutput.js +29 -0
- package/dist/TextEditorOutput/TextEditorOutput.js.map +1 -0
- package/dist/TextEditorOutput/TextEditorOutput.styles.js +6 -0
- package/dist/TextEditorOutput/TextEditorOutput.styles.js.map +1 -0
- package/dist/TextEditorOutput/TextEditorOutput.types.js +2 -0
- package/dist/TextEditorOutput/TextEditorOutput.types.js.map +1 -0
- package/dist/TextEditorOutput/TextEditorOutput.utils.js +59 -0
- package/dist/TextEditorOutput/TextEditorOutput.utils.js.map +1 -0
- package/dist/TextEditorOutput/index.js +2 -0
- package/dist/TextEditorOutput/index.js.map +1 -0
- package/dist/_storyHelpers/constants.js +48 -0
- package/dist/_storyHelpers/constants.js.map +1 -0
- package/dist/_typedoc/TextEditor/TextEditor.types.json +227 -0
- package/dist/_typedoc/TextEditor/TextEditorProvider.types.json +28 -0
- package/dist/_typedoc/TextEditorOutput/TextEditorOutput.types.json +38 -0
- package/dist/_typedoc/deprecations.json +1 -0
- package/dist/_utils/propsTypedoc.js +4 -0
- package/dist/_utils/propsTypedoc.js.map +1 -0
- package/dist/codemod/__fixtures__/src/components/ComplexEditor.d.ts +2 -0
- package/dist/codemod/__fixtures__/src/components/FormWithRichText.d.ts +2 -0
- package/dist/codemod/__fixtures__/src/components/MultilineFormRichText.d.ts +2 -0
- package/dist/codemod/__fixtures__/src/components/NoTextEditor.d.ts +2 -0
- package/dist/codemod/__fixtures__/src/components/ReadOnlyRichText.d.ts +2 -0
- package/dist/codemod/__fixtures__/src/components/SimpleEditor.d.ts +2 -0
- package/dist/codemod/__fixtures__/src/components/TypeImportEditor.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/src/TextEditor/EditorError.d.ts +2 -0
- package/dist/src/TextEditor/StickyToolbar/index.d.ts +2 -0
- package/dist/src/TextEditor/StickyToolbar/useStickyToolbar.d.ts +2 -0
- package/dist/src/TextEditor/StickyToolbar/useStickyToolbar.types.d.ts +8 -0
- package/dist/src/TextEditor/TextEditor.d.ts +44 -0
- package/dist/src/TextEditor/TextEditor.styles.d.ts +7 -0
- package/dist/src/TextEditor/TextEditor.types.d.ts +155 -0
- package/dist/src/TextEditor/TextEditorProvider.d.ts +4 -0
- package/dist/src/TextEditor/TextEditorProvider.types.d.ts +14 -0
- package/dist/src/TextEditor/index.d.ts +4 -0
- package/dist/src/TextEditor/license_key.d.ts +2 -0
- package/dist/src/TextEditor/plugins/CutPlugin/CutCommand.d.ts +5 -0
- package/dist/src/TextEditor/plugins/CutPlugin/CutPlugin.d.ts +5 -0
- package/dist/src/TextEditor/plugins/CutPlugin/index.d.ts +1 -0
- package/dist/src/TextEditor/plugins/IndentPaddingToMarginPlugin/IndentPaddingToMarginPlugin.d.ts +5 -0
- package/dist/src/TextEditor/plugins/IndentPaddingToMarginPlugin/index.d.ts +1 -0
- package/dist/src/TextEditor/plugins/PasteAsTextPlugin/PasteAsTextCommand.d.ts +5 -0
- package/dist/src/TextEditor/plugins/PasteAsTextPlugin/PasteAsTextPlugin.d.ts +5 -0
- package/dist/src/TextEditor/plugins/PasteAsTextPlugin/index.d.ts +1 -0
- package/dist/src/TextEditor/plugins/PastePlugin/PasteCommand.d.ts +5 -0
- package/dist/src/TextEditor/plugins/PastePlugin/PastePlugin.d.ts +5 -0
- package/dist/src/TextEditor/plugins/PastePlugin/index.d.ts +1 -0
- package/dist/src/TextEditor/plugins/TabSpacesPlugin/TabSpacesPlugin.d.ts +6 -0
- package/dist/src/TextEditor/plugins/TabSpacesPlugin/index.d.ts +1 -0
- package/dist/src/TextEditor/textEditorTheming/icons.d.ts +23 -0
- package/dist/src/TextEditor/textEditorTheming/index.d.ts +1 -0
- package/dist/src/TextEditor/textEditorTheming/textEditorTheming.styles.d.ts +2 -0
- package/dist/src/TextEditor/useCKEditorCss.d.ts +3 -0
- package/dist/src/TextEditor/useTabAsNavigation.d.ts +11 -0
- package/dist/src/TextEditor/utils/config.d.ts +3 -0
- package/dist/src/TextEditor/utils/index.d.ts +2 -0
- package/dist/src/TextEditor/utils/locale.d.ts +3 -0
- package/dist/src/TextEditor/utils/plugins.d.ts +7 -0
- package/dist/src/TextEditorOutput/TextEditorOutput.d.ts +8 -0
- package/dist/src/TextEditorOutput/TextEditorOutput.styles.d.ts +2 -0
- package/dist/src/TextEditorOutput/TextEditorOutput.types.d.ts +21 -0
- package/dist/src/TextEditorOutput/TextEditorOutput.utils.d.ts +2 -0
- package/dist/src/TextEditorOutput/index.d.ts +2 -0
- package/dist/src/_storyHelpers/constants.d.ts +14 -0
- package/dist/src/_utils/propsTypedoc.d.ts +3 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/stories/util.d.ts +21 -0
- package/dist/stories/util.js +86 -0
- package/dist/stories/util.js.map +1 -0
- package/jestConfig.d.ts +1 -0
- package/jestConfig.js +66 -0
- package/package.json +146 -0
|
@@ -0,0 +1,184 @@
|
|
|
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 { Alignment, Autoformat, AutoLink, Autosave, BlockQuote, Bold, Bookmark, Code, CodeBlock, Emoji, FindAndReplace, FontBackgroundColor, FontColor, FontSize, Fullscreen, Heading, Highlight, HorizontalLine, Image, Indent, Italic, Link, List, MediaEmbed, PageBreak, RemoveFormat, RestrictedEditingModeEditing, ShowBlocks, SourceEditing, SpecialCharacters, Strikethrough, Subscript, Superscript, Table, TextPartLanguage, Underline, WordCount } from 'ckeditor5';
|
|
14
|
+
import { PasteAsTextPlugin } from '../plugins/PasteAsTextPlugin';
|
|
15
|
+
import { PastePlugin } from '../plugins/PastePlugin';
|
|
16
|
+
|
|
17
|
+
/** Maps TinyMCE string plugin names to CKEditor plugin objects */
|
|
18
|
+
var PLUGINS_MAP = {
|
|
19
|
+
bold: Bold,
|
|
20
|
+
italic: Italic,
|
|
21
|
+
underline: Underline,
|
|
22
|
+
strikethrough: Strikethrough,
|
|
23
|
+
list: List,
|
|
24
|
+
lists: List,
|
|
25
|
+
advlist: List,
|
|
26
|
+
link: Link,
|
|
27
|
+
table: Table,
|
|
28
|
+
image: Image,
|
|
29
|
+
imagetools: Image,
|
|
30
|
+
alignment: Alignment,
|
|
31
|
+
fontsize: FontSize,
|
|
32
|
+
fontcolor: FontColor,
|
|
33
|
+
fontbackgroundcolor: FontBackgroundColor,
|
|
34
|
+
indent: Indent,
|
|
35
|
+
autolink: AutoLink,
|
|
36
|
+
anchor: Bookmark,
|
|
37
|
+
autosave: Autosave,
|
|
38
|
+
charmap: SpecialCharacters,
|
|
39
|
+
code: Code,
|
|
40
|
+
codesample: CodeBlock,
|
|
41
|
+
directionality: TextPartLanguage,
|
|
42
|
+
emoticons: Emoji,
|
|
43
|
+
fullscreen: Fullscreen,
|
|
44
|
+
hr: HorizontalLine,
|
|
45
|
+
media: MediaEmbed,
|
|
46
|
+
noneditable: RestrictedEditingModeEditing,
|
|
47
|
+
pagebreak: PageBreak,
|
|
48
|
+
searchreplace: FindAndReplace,
|
|
49
|
+
textpattern: Autoformat,
|
|
50
|
+
visualblocks: ShowBlocks,
|
|
51
|
+
wordcount: WordCount,
|
|
52
|
+
blockquote: BlockQuote,
|
|
53
|
+
subscript: Subscript,
|
|
54
|
+
superscript: Superscript,
|
|
55
|
+
heading: Heading,
|
|
56
|
+
headings: Heading,
|
|
57
|
+
highlight: Highlight,
|
|
58
|
+
removeformat: RemoveFormat,
|
|
59
|
+
source: SourceEditing,
|
|
60
|
+
sourceedit: SourceEditing,
|
|
61
|
+
autoformat: Autoformat,
|
|
62
|
+
nonbreaking: SpecialCharacters,
|
|
63
|
+
paste: PastePlugin,
|
|
64
|
+
pastetext: PasteAsTextPlugin,
|
|
65
|
+
pasteastext: PasteAsTextPlugin,
|
|
66
|
+
// Part of CKEditor core
|
|
67
|
+
autoresize: null,
|
|
68
|
+
spellchecker: null,
|
|
69
|
+
tabfocus: null
|
|
70
|
+
};
|
|
71
|
+
var UNSUPPORTED_PLUGINS = [
|
|
72
|
+
// Would need custom implementation
|
|
73
|
+
'help', 'visualchars', 'insertdatetime', 'save', 'template',
|
|
74
|
+
// Not directly supported
|
|
75
|
+
'importcss',
|
|
76
|
+
// CKEditor uses explicit style definitions instead of scanning styles for classes
|
|
77
|
+
'print',
|
|
78
|
+
// Could be substituted with ExportPdf, but needs cloud services
|
|
79
|
+
'preview',
|
|
80
|
+
// Could be substituted with ExportPdf, but needs cloud services
|
|
81
|
+
'toc',
|
|
82
|
+
// Would need TableOfContents premium plugin
|
|
83
|
+
|
|
84
|
+
// Has been removed in TinyMCE 6
|
|
85
|
+
'bbcode', 'colorpicker', 'contextmenu', 'fullpage', 'legacyoutput'];
|
|
86
|
+
|
|
87
|
+
/** Maps TinyMCE toolbar button names to CKEditor command names */
|
|
88
|
+
var TOOLBAR_MAP = {
|
|
89
|
+
link: 'link',
|
|
90
|
+
table: 'insertTable',
|
|
91
|
+
image: 'insertImageViaUrl',
|
|
92
|
+
blockquote: 'blockQuote',
|
|
93
|
+
code: 'code',
|
|
94
|
+
codesample: 'codeBlock',
|
|
95
|
+
hr: 'horizontalLine',
|
|
96
|
+
media: 'mediaEmbed',
|
|
97
|
+
pagebreak: 'pageBreak',
|
|
98
|
+
subscript: 'subscript',
|
|
99
|
+
superscript: 'superscript',
|
|
100
|
+
removeformat: 'removeFormat',
|
|
101
|
+
heading: 'heading',
|
|
102
|
+
headings: 'heading',
|
|
103
|
+
highlight: 'highlight',
|
|
104
|
+
charmap: 'specialCharacters',
|
|
105
|
+
searchreplace: 'findAndReplace',
|
|
106
|
+
source: 'sourceEditing',
|
|
107
|
+
sourceedit: 'sourceEditing',
|
|
108
|
+
visualblocks: 'showBlocks',
|
|
109
|
+
wordcount: 'wordCount',
|
|
110
|
+
emoticons: 'emoji',
|
|
111
|
+
fullscreen: 'fullscreen',
|
|
112
|
+
anchor: 'bookmark',
|
|
113
|
+
toc: 'tableOfContents'
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** Gets CKEditor plugin objects from TinyMCE string plugin names */
|
|
117
|
+
export var getPluginsFromStringArray = function getPluginsFromStringArray() {
|
|
118
|
+
var pluginNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
119
|
+
var unsupportedPlugins = pluginNames.filter(function (name) {
|
|
120
|
+
return UNSUPPORTED_PLUGINS.includes(name.toLowerCase());
|
|
121
|
+
});
|
|
122
|
+
if (unsupportedPlugins.length) {
|
|
123
|
+
var pluginsList = unsupportedPlugins.join(', ');
|
|
124
|
+
throw new Error("The following editor plugins are not supported: ".concat(pluginsList, "."));
|
|
125
|
+
}
|
|
126
|
+
var plugins = pluginNames.map(function (name) {
|
|
127
|
+
return PLUGINS_MAP[name.toLowerCase()];
|
|
128
|
+
}).filter(function (plugin, index, array) {
|
|
129
|
+
return plugin !== null &&
|
|
130
|
+
// Remove duplicates
|
|
131
|
+
array.indexOf(plugin) === index;
|
|
132
|
+
});
|
|
133
|
+
return plugins;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** Gets toolbar items that should be added for the given string plugin names. */
|
|
137
|
+
export var getToolbarItemsFromStringArray = function getToolbarItemsFromStringArray() {
|
|
138
|
+
var pluginNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
139
|
+
return pluginNames.map(function (name) {
|
|
140
|
+
return TOOLBAR_MAP[name.toLowerCase()];
|
|
141
|
+
}).filter(Boolean);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** Enhances an editor config by adding plugins and toolbar items from TinyMCE string array */
|
|
145
|
+
export var addPluginsFromStringArray = function addPluginsFromStringArray(config) {
|
|
146
|
+
var pluginNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
147
|
+
if (!pluginNames.length) {
|
|
148
|
+
return config;
|
|
149
|
+
}
|
|
150
|
+
var additionalPlugins = getPluginsFromStringArray(pluginNames);
|
|
151
|
+
var additionalToolbarItems = getToolbarItemsFromStringArray(pluginNames);
|
|
152
|
+
var currentPlugins = config.plugins || [];
|
|
153
|
+
var enhancedPlugins = Array.from(new Set([].concat(_toConsumableArray(currentPlugins), _toConsumableArray(additionalPlugins))));
|
|
154
|
+
var currentToolbar = Array.isArray(config.toolbar) ? config.toolbar : [];
|
|
155
|
+
var enhancedToolbar = currentToolbar;
|
|
156
|
+
if (additionalToolbarItems.length > 0) {
|
|
157
|
+
// Remove undo/redo buttons temporarily
|
|
158
|
+
var toolbarWithoutUndo = currentToolbar.filter(function (item) {
|
|
159
|
+
return item !== 'undo' && item !== 'redo';
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Combine toolbar items
|
|
163
|
+
var combinedItems = [].concat(_toConsumableArray(toolbarWithoutUndo), _toConsumableArray(additionalToolbarItems), ['|', 'undo', 'redo']);
|
|
164
|
+
|
|
165
|
+
// Deduplicate items while preserving separators
|
|
166
|
+
var seenButtons = new Set();
|
|
167
|
+
enhancedToolbar = combinedItems.filter(function (item) {
|
|
168
|
+
if (item === '|') {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
var itemKey = typeof item === 'string' ? item : JSON.stringify(item);
|
|
172
|
+
if (seenButtons.has(itemKey)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
seenButtons.add(itemKey);
|
|
176
|
+
return true;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
180
|
+
plugins: enhancedPlugins,
|
|
181
|
+
toolbar: enhancedToolbar
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","names":["Alignment","Autoformat","AutoLink","Autosave","BlockQuote","Bold","Bookmark","Code","CodeBlock","Emoji","FindAndReplace","FontBackgroundColor","FontColor","FontSize","Fullscreen","Heading","Highlight","HorizontalLine","Image","Indent","Italic","Link","List","MediaEmbed","PageBreak","RemoveFormat","RestrictedEditingModeEditing","ShowBlocks","SourceEditing","SpecialCharacters","Strikethrough","Subscript","Superscript","Table","TextPartLanguage","Underline","WordCount","PasteAsTextPlugin","PastePlugin","PLUGINS_MAP","bold","italic","underline","strikethrough","list","lists","advlist","link","table","image","imagetools","alignment","fontsize","fontcolor","fontbackgroundcolor","indent","autolink","anchor","autosave","charmap","code","codesample","directionality","emoticons","fullscreen","hr","media","noneditable","pagebreak","searchreplace","textpattern","visualblocks","wordcount","blockquote","subscript","superscript","heading","headings","highlight","removeformat","source","sourceedit","autoformat","nonbreaking","paste","pastetext","pasteastext","autoresize","spellchecker","tabfocus","UNSUPPORTED_PLUGINS","TOOLBAR_MAP","toc","getPluginsFromStringArray","pluginNames","arguments","length","undefined","unsupportedPlugins","filter","name","includes","toLowerCase","pluginsList","join","Error","concat","plugins","map","plugin","index","array","indexOf","getToolbarItemsFromStringArray","Boolean","addPluginsFromStringArray","config","additionalPlugins","additionalToolbarItems","currentPlugins","enhancedPlugins","Array","from","Set","_toConsumableArray","currentToolbar","isArray","toolbar","enhancedToolbar","toolbarWithoutUndo","item","combinedItems","seenButtons","itemKey","JSON","stringify","has","add","_objectSpread"],"sources":["../../../src/TextEditor/utils/plugins.ts"],"sourcesContent":["import type { EditorConfig, Plugin } from 'ckeditor5'\nimport {\n Alignment,\n Autoformat,\n AutoLink,\n Autosave,\n BlockQuote,\n Bold,\n Bookmark,\n Code,\n CodeBlock,\n Emoji,\n FindAndReplace,\n FontBackgroundColor,\n FontColor,\n FontSize,\n Fullscreen,\n Heading,\n Highlight,\n HorizontalLine,\n Image,\n Indent,\n Italic,\n Link,\n List,\n MediaEmbed,\n PageBreak,\n RemoveFormat,\n RestrictedEditingModeEditing,\n ShowBlocks,\n SourceEditing,\n SpecialCharacters,\n Strikethrough,\n Subscript,\n Superscript,\n Table,\n TextPartLanguage,\n Underline,\n WordCount,\n} from 'ckeditor5'\n\nimport { PasteAsTextPlugin } from '../plugins/PasteAsTextPlugin'\nimport { PastePlugin } from '../plugins/PastePlugin'\n\n/** Maps TinyMCE string plugin names to CKEditor plugin objects */\nconst PLUGINS_MAP: Record<string, typeof Plugin | null> = {\n bold: Bold,\n italic: Italic,\n underline: Underline,\n strikethrough: Strikethrough,\n list: List,\n lists: List,\n advlist: List,\n link: Link,\n table: Table,\n image: Image,\n imagetools: Image,\n alignment: Alignment,\n fontsize: FontSize,\n fontcolor: FontColor,\n fontbackgroundcolor: FontBackgroundColor,\n indent: Indent,\n autolink: AutoLink,\n anchor: Bookmark,\n autosave: Autosave,\n charmap: SpecialCharacters,\n code: Code,\n codesample: CodeBlock,\n directionality: TextPartLanguage,\n emoticons: Emoji,\n fullscreen: Fullscreen,\n hr: HorizontalLine,\n media: MediaEmbed,\n noneditable: RestrictedEditingModeEditing,\n pagebreak: PageBreak,\n searchreplace: FindAndReplace,\n textpattern: Autoformat,\n visualblocks: ShowBlocks,\n wordcount: WordCount,\n blockquote: BlockQuote,\n subscript: Subscript,\n superscript: Superscript,\n heading: Heading,\n headings: Heading,\n highlight: Highlight,\n removeformat: RemoveFormat,\n source: SourceEditing,\n sourceedit: SourceEditing,\n autoformat: Autoformat,\n nonbreaking: SpecialCharacters,\n paste: PastePlugin,\n pastetext: PasteAsTextPlugin,\n pasteastext: PasteAsTextPlugin,\n\n // Part of CKEditor core\n autoresize: null,\n spellchecker: null,\n tabfocus: null,\n}\n\nconst UNSUPPORTED_PLUGINS = [\n // Would need custom implementation\n 'help',\n 'visualchars',\n 'insertdatetime',\n 'save',\n 'template',\n\n // Not directly supported\n 'importcss', // CKEditor uses explicit style definitions instead of scanning styles for classes\n 'print', // Could be substituted with ExportPdf, but needs cloud services\n 'preview', // Could be substituted with ExportPdf, but needs cloud services\n 'toc', // Would need TableOfContents premium plugin\n\n // Has been removed in TinyMCE 6\n 'bbcode',\n 'colorpicker',\n 'contextmenu',\n 'fullpage',\n 'legacyoutput',\n]\n\n/** Maps TinyMCE toolbar button names to CKEditor command names */\nconst TOOLBAR_MAP: Record<string, string> = {\n link: 'link',\n table: 'insertTable',\n image: 'insertImageViaUrl',\n blockquote: 'blockQuote',\n code: 'code',\n codesample: 'codeBlock',\n hr: 'horizontalLine',\n media: 'mediaEmbed',\n pagebreak: 'pageBreak',\n subscript: 'subscript',\n superscript: 'superscript',\n removeformat: 'removeFormat',\n heading: 'heading',\n headings: 'heading',\n highlight: 'highlight',\n charmap: 'specialCharacters',\n searchreplace: 'findAndReplace',\n source: 'sourceEditing',\n sourceedit: 'sourceEditing',\n visualblocks: 'showBlocks',\n wordcount: 'wordCount',\n emoticons: 'emoji',\n fullscreen: 'fullscreen',\n anchor: 'bookmark',\n toc: 'tableOfContents',\n}\n\n/** Gets CKEditor plugin objects from TinyMCE string plugin names */\nexport const getPluginsFromStringArray = (pluginNames: string[] = []) => {\n const unsupportedPlugins = pluginNames.filter((name) =>\n UNSUPPORTED_PLUGINS.includes(name.toLowerCase())\n )\n if (unsupportedPlugins.length) {\n const pluginsList = unsupportedPlugins.join(', ')\n throw new Error(\n `The following editor plugins are not supported: ${pluginsList}.`\n )\n }\n\n const plugins = pluginNames\n .map((name) => PLUGINS_MAP[name.toLowerCase()])\n .filter(\n (plugin, index, array) =>\n plugin !== null &&\n // Remove duplicates\n array.indexOf(plugin) === index\n )\n return plugins as (typeof Plugin)[]\n}\n\n/** Gets toolbar items that should be added for the given string plugin names. */\nexport const getToolbarItemsFromStringArray = (pluginNames: string[] = []) => {\n return pluginNames\n .map((name) => TOOLBAR_MAP[name.toLowerCase()])\n .filter(Boolean)\n}\n\n/** Enhances an editor config by adding plugins and toolbar items from TinyMCE string array */\nexport const addPluginsFromStringArray = (\n config: EditorConfig,\n pluginNames: string[] = []\n): EditorConfig => {\n if (!pluginNames.length) {\n return config\n }\n const additionalPlugins = getPluginsFromStringArray(pluginNames)\n const additionalToolbarItems = getToolbarItemsFromStringArray(pluginNames)\n\n const currentPlugins = config.plugins || []\n const enhancedPlugins = Array.from(\n new Set([...currentPlugins, ...additionalPlugins])\n )\n\n const currentToolbar = Array.isArray(config.toolbar) ? config.toolbar : []\n\n let enhancedToolbar = currentToolbar\n if (additionalToolbarItems.length > 0) {\n // Remove undo/redo buttons temporarily\n const toolbarWithoutUndo = currentToolbar.filter(\n (item) => item !== 'undo' && item !== 'redo'\n )\n\n // Combine toolbar items\n const combinedItems = [\n ...toolbarWithoutUndo,\n ...additionalToolbarItems,\n '|',\n 'undo',\n 'redo',\n ]\n\n // Deduplicate items while preserving separators\n const seenButtons = new Set<string>()\n enhancedToolbar = combinedItems.filter((item) => {\n if (item === '|') {\n return true\n }\n const itemKey = typeof item === 'string' ? item : JSON.stringify(item)\n if (seenButtons.has(itemKey)) {\n return false\n }\n seenButtons.add(itemKey)\n return true\n })\n }\n return {\n ...config,\n plugins: enhancedPlugins,\n toolbar: enhancedToolbar,\n }\n}\n"],"mappings":";;;;;;;;;;;;AACA,SACEA,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,IAAI,EACJC,QAAQ,EACRC,IAAI,EACJC,SAAS,EACTC,KAAK,EACLC,cAAc,EACdC,mBAAmB,EACnBC,SAAS,EACTC,QAAQ,EACRC,UAAU,EACVC,OAAO,EACPC,SAAS,EACTC,cAAc,EACdC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,IAAI,EACJC,UAAU,EACVC,SAAS,EACTC,YAAY,EACZC,4BAA4B,EAC5BC,UAAU,EACVC,aAAa,EACbC,iBAAiB,EACjBC,aAAa,EACbC,SAAS,EACTC,WAAW,EACXC,KAAK,EACLC,gBAAgB,EAChBC,SAAS,EACTC,SAAS,QACJ,WAAW;AAElB,SAASC,iBAAiB,QAAQ,8BAA8B;AAChE,SAASC,WAAW,QAAQ,wBAAwB;;AAEpD;AACA,IAAMC,WAAiD,GAAG;EACxDC,IAAI,EAAEnC,IAAI;EAC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O,CAAC,EAAE;QAC5B,OAAO,KAAK;MACd;MACAD,WAAW,CAACK,GAAG,CAACJ,OAAO,CAAC;MACxB,OAAO,IAAI;IACb,CAAC,CAAC;EACJ;EACA,OAAAK,aAAA,CAAAA,aAAA,KACKtB,MAAM;IACTT,OAAO,EAAEa,eAAe;IACxBO,OAAO,EAAEC;EAAe;AAE5B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var _excluded = ["value"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { StyledEditor } from './TextEditorOutput.styles';
|
|
7
|
+
import { sanitizeTextEditorHtml } from './TextEditorOutput.utils';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Render formatted text from `TextEditor`
|
|
11
|
+
*
|
|
12
|
+
* @since 10.24.0
|
|
13
|
+
*/
|
|
14
|
+
export var TextEditorOutput = /*#__PURE__*/React.forwardRef(function TextEditorOutput(_ref, ref) {
|
|
15
|
+
var value = _ref.value,
|
|
16
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
17
|
+
var sanitizedHtml = sanitizeTextEditorHtml(value || '');
|
|
18
|
+
return /*#__PURE__*/React.createElement(StyledEditor, _extends({}, props, {
|
|
19
|
+
ref: ref
|
|
20
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
21
|
+
className: "ck-content",
|
|
22
|
+
dangerouslySetInnerHTML: {
|
|
23
|
+
__html: sanitizedHtml
|
|
24
|
+
},
|
|
25
|
+
contentEditable: false
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
TextEditorOutput.displayName = 'TextEditorOutput';
|
|
29
|
+
//# sourceMappingURL=TextEditorOutput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextEditorOutput.js","names":["React","StyledEditor","sanitizeTextEditorHtml","TextEditorOutput","forwardRef","_ref","ref","value","props","_objectWithoutProperties","_excluded","sanitizedHtml","createElement","_extends","className","dangerouslySetInnerHTML","__html","contentEditable","displayName"],"sources":["../../src/TextEditorOutput/TextEditorOutput.tsx"],"sourcesContent":["import React from 'react'\n\nimport { StyledEditor } from './TextEditorOutput.styles'\nimport type { TextEditorOutputProps } from './TextEditorOutput.types'\nimport { sanitizeTextEditorHtml } from './TextEditorOutput.utils'\n\n/**\n * Render formatted text from `TextEditor`\n *\n * @since 10.24.0\n */\nexport const TextEditorOutput = React.forwardRef<\n HTMLDivElement,\n TextEditorOutputProps & React.HTMLAttributes<HTMLDivElement>\n>(function TextEditorOutput({ value, ...props }, ref) {\n const sanitizedHtml = sanitizeTextEditorHtml(value || '')\n\n return (\n <StyledEditor {...props} ref={ref}>\n <div\n className=\"ck-content\"\n dangerouslySetInnerHTML={{ __html: sanitizedHtml }}\n contentEditable={false}\n />\n </StyledEditor>\n )\n})\n\nTextEditorOutput.displayName = 'TextEditorOutput'\n"],"mappings":";;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,YAAY,QAAQ,2BAA2B;AAExD,SAASC,sBAAsB,QAAQ,0BAA0B;;AAEjE;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMC,gBAAgB,gBAAGH,KAAK,CAACI,UAAU,CAG9C,SAASD,gBAAgBA,CAAAE,IAAA,EAAsBC,GAAG,EAAE;EAAA,IAAxBC,KAAK,GAAAF,IAAA,CAALE,KAAK;IAAKC,KAAK,GAAAC,wBAAA,CAAAJ,IAAA,EAAAK,SAAA;EAC3C,IAAMC,aAAa,GAAGT,sBAAsB,CAACK,KAAK,IAAI,EAAE,CAAC;EAEzD,oBACEP,KAAA,CAAAY,aAAA,CAACX,YAAY,EAAAY,QAAA,KAAKL,KAAK;IAAEF,GAAG,EAAEA;EAAI,iBAChCN,KAAA,CAAAY,aAAA;IACEE,SAAS,EAAC,YAAY;IACtBC,uBAAuB,EAAE;MAAEC,MAAM,EAAEL;IAAc,CAAE;IACnDM,eAAe,EAAE;EAAM,CACxB,CACW,CAAC;AAEnB,CAAC,CAAC;AAEFd,gBAAgB,CAACe,WAAW,GAAG,kBAAkB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
export var StyledEditor = /*#__PURE__*/styled.div.withConfig({
|
|
3
|
+
displayName: "StyledEditor",
|
|
4
|
+
componentId: "text-editor-0_0_1__sc-1oujb2g-0"
|
|
5
|
+
})([".ck-editor__top{height:0 !important;}.ck-content{border:none !important;padding:0 !important;p{margin:0;}table,img{margin-left:auto;margin-right:auto;}img{display:block;}table{border:1px double #b3b3b3;border-collapse:collapse;border-spacing:0;th{text-align:left;}& > thead,& > tbody{& > tr > td,& > tr > th{border:1px solid #bfbfbf;min-width:2em;padding:0.4em;}& > tr > th{background:rgba(0,0,0,0.05);font-weight:700;}}}}"]);
|
|
6
|
+
//# sourceMappingURL=TextEditorOutput.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextEditorOutput.styles.js","names":["styled","StyledEditor","div","withConfig","displayName","componentId"],"sources":["../../src/TextEditorOutput/TextEditorOutput.styles.ts"],"sourcesContent":["import styled from 'styled-components'\n\nexport const StyledEditor = styled.div`\n .ck-editor__top {\n height: 0 !important;\n }\n\n .ck-content {\n border: none !important;\n padding: 0 !important;\n\n p {\n margin: 0;\n }\n\n table,\n img {\n margin-left: auto;\n margin-right: auto;\n }\n\n img {\n display: block;\n }\n\n table {\n border: 1px double #b3b3b3;\n border-collapse: collapse;\n border-spacing: 0;\n\n th {\n text-align: left;\n }\n\n & > thead,\n & > tbody {\n & > tr > td,\n & > tr > th {\n border: 1px solid #bfbfbf;\n min-width: 2em;\n padding: 0.4em;\n }\n\n & > tr > th {\n background: rgba(0, 0, 0, 0.05);\n font-weight: 700;\n }\n }\n }\n }\n`\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AAEtC,OAAO,IAAMC,YAAY,gBAAGD,MAAM,CAACE,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,8aAgDrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextEditorOutput.types.js","names":[],"sources":["../../src/TextEditorOutput/TextEditorOutput.types.ts"],"sourcesContent":["export interface TextEditorOutputProps {\n /**\n * Formatted text from `TextEditor`\n *\n * @since 10.24.0\n */\n value?: string\n\n /**\n * Additional classNames\n *\n * @since 10.24.0\n */\n className?: string\n\n /**\n * Additional CSS styles\n *\n * @since 10.24.0\n */\n style?: React.CSSProperties\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import sanitizeHtml from 'sanitize-html';
|
|
2
|
+
|
|
3
|
+
/** Sanitize HTML content while preserving custom styling */
|
|
4
|
+
export var sanitizeTextEditorHtml = function sanitizeTextEditorHtml(html) {
|
|
5
|
+
if (!html) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
return sanitizeHtml(html, {
|
|
9
|
+
allowedTags: ['p', 'br', 'strong', 'b', 'em', 'i', 'u', 's', 'span', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'a', 'table', 'thead', 'tbody', 'tr', 'td', 'th', 'blockquote', 'pre', 'code', 'hr', 'img', 'sub', 'sup'],
|
|
10
|
+
allowedAttributes: {
|
|
11
|
+
'*': ['style', 'class', 'data-*'],
|
|
12
|
+
a: ['href', 'title', 'target', 'rel'],
|
|
13
|
+
img: ['src', 'alt', 'title', 'width', 'height'],
|
|
14
|
+
table: ['border', 'cellpadding', 'cellspacing'],
|
|
15
|
+
td: ['colspan', 'rowspan'],
|
|
16
|
+
th: ['colspan', 'rowspan', 'scope']
|
|
17
|
+
},
|
|
18
|
+
allowedStyles: {
|
|
19
|
+
'*': {
|
|
20
|
+
color: [/^#[0-9a-fA-F]{3,6}$/, /^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/, /^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*[\d.]+\s*\)$/],
|
|
21
|
+
'background-color': [/^#[0-9a-fA-F]{3,6}$/, /^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/, /^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*[\d.]+\s*\)$/],
|
|
22
|
+
'font-size': [/^\d+(?:px|pt|em|rem|%)$/],
|
|
23
|
+
'font-weight': [/^(?:normal|bold|bolder|lighter|\d{1,3})$/],
|
|
24
|
+
'font-style': [/^(?:normal|italic|oblique)$/],
|
|
25
|
+
'font-family': [/.*/],
|
|
26
|
+
'text-decoration': [/^(?:none|underline|line-through|overline)$/],
|
|
27
|
+
'text-align': [/^(?:left|right|center|justify)$/],
|
|
28
|
+
'line-height': [/^\d+(?:\.\d+)?(?:px|pt|em|rem|%)?$/],
|
|
29
|
+
margin: [/^\d+(?:px|pt|em|rem|%)?(?:\s+\d+(?:px|pt|em|rem|%)?)*$/],
|
|
30
|
+
'margin-top': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
31
|
+
'margin-bottom': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
32
|
+
'margin-left': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
33
|
+
'margin-right': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
34
|
+
padding: [/^\d+(?:px|pt|em|rem|%)?(?:\s+\d+(?:px|pt|em|rem|%)?)*$/],
|
|
35
|
+
'padding-top': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
36
|
+
'padding-bottom': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
37
|
+
'padding-left': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
38
|
+
'padding-right': [/^\d+(?:px|pt|em|rem|%)?$/],
|
|
39
|
+
border: [/.*/],
|
|
40
|
+
'border-top': [/.*/],
|
|
41
|
+
'border-bottom': [/.*/],
|
|
42
|
+
'border-left': [/.*/],
|
|
43
|
+
'border-right': [/.*/],
|
|
44
|
+
'border-color': [/^#[0-9a-fA-F]{3,6}$/, /^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/, /^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*[\d.]+\s*\)$/],
|
|
45
|
+
'border-width': [/^\d+(?:px|pt|em|rem)?$/],
|
|
46
|
+
'border-style': [/^(?:none|solid|dashed|dotted|double)$/],
|
|
47
|
+
'list-style-type': [/.*/],
|
|
48
|
+
'vertical-align': [/.*/],
|
|
49
|
+
'white-space': [/.*/]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
allowedSchemes: ['http', 'https', 'mailto', 'tel'],
|
|
53
|
+
allowedSchemesByTag: {
|
|
54
|
+
img: ['data', 'http', 'https']
|
|
55
|
+
},
|
|
56
|
+
allowedIframeHostnames: []
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=TextEditorOutput.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextEditorOutput.utils.js","names":["sanitizeHtml","sanitizeTextEditorHtml","html","allowedTags","allowedAttributes","a","img","table","td","th","allowedStyles","color","margin","padding","border","allowedSchemes","allowedSchemesByTag","allowedIframeHostnames"],"sources":["../../src/TextEditorOutput/TextEditorOutput.utils.ts"],"sourcesContent":["import sanitizeHtml from 'sanitize-html'\n\n/** Sanitize HTML content while preserving custom styling */\nexport const sanitizeTextEditorHtml = (html: string) => {\n if (!html) {\n return ''\n }\n\n return sanitizeHtml(html, {\n allowedTags: [\n 'p',\n 'br',\n 'strong',\n 'b',\n 'em',\n 'i',\n 'u',\n 's',\n 'span',\n 'div',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'ul',\n 'ol',\n 'li',\n 'a',\n 'table',\n 'thead',\n 'tbody',\n 'tr',\n 'td',\n 'th',\n 'blockquote',\n 'pre',\n 'code',\n 'hr',\n 'img',\n 'sub',\n 'sup',\n ],\n allowedAttributes: {\n '*': ['style', 'class', 'data-*'],\n a: ['href', 'title', 'target', 'rel'],\n img: ['src', 'alt', 'title', 'width', 'height'],\n table: ['border', 'cellpadding', 'cellspacing'],\n td: ['colspan', 'rowspan'],\n th: ['colspan', 'rowspan', 'scope'],\n },\n allowedStyles: {\n '*': {\n color: [\n /^#[0-9a-fA-F]{3,6}$/,\n /^rgb\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*\\)$/,\n /^rgba\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*[\\d.]+\\s*\\)$/,\n ],\n 'background-color': [\n /^#[0-9a-fA-F]{3,6}$/,\n /^rgb\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*\\)$/,\n /^rgba\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*[\\d.]+\\s*\\)$/,\n ],\n 'font-size': [/^\\d+(?:px|pt|em|rem|%)$/],\n 'font-weight': [/^(?:normal|bold|bolder|lighter|\\d{1,3})$/],\n 'font-style': [/^(?:normal|italic|oblique)$/],\n 'font-family': [/.*/],\n 'text-decoration': [/^(?:none|underline|line-through|overline)$/],\n 'text-align': [/^(?:left|right|center|justify)$/],\n 'line-height': [/^\\d+(?:\\.\\d+)?(?:px|pt|em|rem|%)?$/],\n margin: [/^\\d+(?:px|pt|em|rem|%)?(?:\\s+\\d+(?:px|pt|em|rem|%)?)*$/],\n 'margin-top': [/^\\d+(?:px|pt|em|rem|%)?$/],\n 'margin-bottom': [/^\\d+(?:px|pt|em|rem|%)?$/],\n 'margin-left': [/^\\d+(?:px|pt|em|rem|%)?$/],\n 'margin-right': [/^\\d+(?:px|pt|em|rem|%)?$/],\n padding: [/^\\d+(?:px|pt|em|rem|%)?(?:\\s+\\d+(?:px|pt|em|rem|%)?)*$/],\n 'padding-top': [/^\\d+(?:px|pt|em|rem|%)?$/],\n 'padding-bottom': [/^\\d+(?:px|pt|em|rem|%)?$/],\n 'padding-left': [/^\\d+(?:px|pt|em|rem|%)?$/],\n 'padding-right': [/^\\d+(?:px|pt|em|rem|%)?$/],\n border: [/.*/],\n 'border-top': [/.*/],\n 'border-bottom': [/.*/],\n 'border-left': [/.*/],\n 'border-right': [/.*/],\n 'border-color': [\n /^#[0-9a-fA-F]{3,6}$/,\n /^rgb\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*\\)$/,\n /^rgba\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*[\\d.]+\\s*\\)$/,\n ],\n 'border-width': [/^\\d+(?:px|pt|em|rem)?$/],\n 'border-style': [/^(?:none|solid|dashed|dotted|double)$/],\n 'list-style-type': [/.*/],\n 'vertical-align': [/.*/],\n 'white-space': [/.*/],\n },\n },\n allowedSchemes: ['http', 'https', 'mailto', 'tel'],\n allowedSchemesByTag: {\n img: ['data', 'http', 'https'],\n },\n allowedIframeHostnames: [],\n })\n}\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,eAAe;;AAExC;AACA,OAAO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAIC,IAAY,EAAK;EACtD,IAAI,CAACA,IAAI,EAAE;IACT,OAAO,EAAE;EACX;EAEA,OAAOF,Y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export { TextEditorOutput } from './TextEditorOutput'\nexport type { TextEditorOutputProps } from './TextEditorOutput.types'\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,oBAAoB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export var exampleText = {
|
|
2
|
+
"default": 'Click me!',
|
|
3
|
+
none: '',
|
|
4
|
+
short_ipsum: 'Lorum',
|
|
5
|
+
short_sentence: 'Did you think you have mastery over fire? Incredible!',
|
|
6
|
+
long_ipsum: "Lorem ip sum dolor sit amet, consectetur adipiscing elit,\n ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n Scelerisque eleifend donec pretium vulputate sapien nec sagittis.\n Ultricies tristique nulla aliquet enim tortor at auctor urna nunc.\n Vitae turpis massa sed elementum tempus egestas.\n Nunc consequat interdum varius sit amet",
|
|
7
|
+
longest_ipsum: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\n tempor incididunt ut labore et dolore magna aliqua. Ac tortor dignissim\n convallis aenean et. Facilisis volutpat est velit egestas dui id. In\n nulla posuere sollicitudin aliquam ultrices. Lorem mollis aliquam ut\n porttitor. Convallis aenean et tortor at risus viverra adipiscing at.\n Euismod nisi porta lorem mollis aliquam ut porttitor. Hac habitasse\n platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper.\n Viverra tellus in hac habitasse platea dictumst. Scelerisque viverra lawn\n gnome in aliquam sem fringilla ut morbi tincidunt. Ullamcorper morbi tincidunt\n ornare massa eget. Gravida cum sociis natoque penatibus. Leo vel fringilla est\n ullamcorper eget nulla. Vitae proin sagittis nisl rhoncus mattis rhoncus urna.\n Mauris commodo quis imperdiet massa tincidunt nunc pulvinar sapien et. Id aliquet\n lectus proin nibh troll condimentum id venenatis.",
|
|
8
|
+
long_ipsum_one_line: "Lorem ip sum dolor sit amet, consectetur adipiscing elit, ed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Scelerisque eleifend donec pretium vulputate sapien nec sagittis. Ultricies tristique nulla aliquet enim tortor at auctor urna nunc. Vitae turpis massa sed elementum tempus egestas. Nunc consequat interdum varius sit amet"
|
|
9
|
+
};
|
|
10
|
+
export function Ipsum(lengthOrOptions) {
|
|
11
|
+
if (typeof lengthOrOptions === 'number') {
|
|
12
|
+
return _recursiveGrow(lengthOrOptions);
|
|
13
|
+
}
|
|
14
|
+
var length = lengthOrOptions.length,
|
|
15
|
+
lettercase = lengthOrOptions.lettercase,
|
|
16
|
+
trailingPeriod = lengthOrOptions.trailingPeriod;
|
|
17
|
+
var longString = _recursiveGrow(length);
|
|
18
|
+
var lastChar = longString[longString.length - 1];
|
|
19
|
+
if (!trailingPeriod && ['.', ','].includes(lastChar)) {
|
|
20
|
+
longString = longString.slice(0, -1);
|
|
21
|
+
}
|
|
22
|
+
if (lettercase === 'title') {
|
|
23
|
+
longString = longString.replace(/\b\w/g, function (s) {
|
|
24
|
+
return s.toUpperCase();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return longString;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a sentence case sentence.
|
|
32
|
+
* @returns string
|
|
33
|
+
*/
|
|
34
|
+
var _recursiveGrow = function recursiveGrow() {
|
|
35
|
+
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
36
|
+
var out = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : exampleText.longest_ipsum;
|
|
37
|
+
if (!length) {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
if (out.length < length) {
|
|
41
|
+
return _recursiveGrow(length, out + exampleText.longest_ipsum);
|
|
42
|
+
}
|
|
43
|
+
if (out.length >= length) {
|
|
44
|
+
return out.slice(0, length - 1) + '.';
|
|
45
|
+
}
|
|
46
|
+
return 'Lorem ipsum grow failed.';
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":["exampleText","none","short_ipsum","short_sentence","long_ipsum","longest_ipsum","long_ipsum_one_line","Ipsum","lengthOrOptions","recursiveGrow","length","lettercase","trailingPeriod","longString","lastChar","includes","slice","replace","s","toUpperCase","arguments","undefined","out"],"sources":["../../src/_storyHelpers/constants.ts"],"sourcesContent":["export const exampleText = {\n default: 'Click me!',\n none: '',\n short_ipsum: 'Lorum',\n short_sentence: 'Did you think you have mastery over fire? Incredible!',\n long_ipsum: `Lorem ip sum dolor sit amet, consectetur adipiscing elit,\n ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n Scelerisque eleifend donec pretium vulputate sapien nec sagittis.\n Ultricies tristique nulla aliquet enim tortor at auctor urna nunc.\n Vitae turpis massa sed elementum tempus egestas.\n Nunc consequat interdum varius sit amet`,\n longest_ipsum: `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\n tempor incididunt ut labore et dolore magna aliqua. Ac tortor dignissim\n convallis aenean et. Facilisis volutpat est velit egestas dui id. In\n nulla posuere sollicitudin aliquam ultrices. Lorem mollis aliquam ut\n porttitor. Convallis aenean et tortor at risus viverra adipiscing at.\n Euismod nisi porta lorem mollis aliquam ut porttitor. Hac habitasse\n platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper.\n Viverra tellus in hac habitasse platea dictumst. Scelerisque viverra lawn\n gnome in aliquam sem fringilla ut morbi tincidunt. Ullamcorper morbi tincidunt\n ornare massa eget. Gravida cum sociis natoque penatibus. Leo vel fringilla est\n ullamcorper eget nulla. Vitae proin sagittis nisl rhoncus mattis rhoncus urna.\n Mauris commodo quis imperdiet massa tincidunt nunc pulvinar sapien et. Id aliquet\n lectus proin nibh troll condimentum id venenatis.`,\n long_ipsum_one_line: `Lorem ip sum dolor sit amet, consectetur adipiscing elit, ed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Scelerisque eleifend donec pretium vulputate sapien nec sagittis. Ultricies tristique nulla aliquet enim tortor at auctor urna nunc. Vitae turpis massa sed elementum tempus egestas. Nunc consequat interdum varius sit amet`,\n}\n\nexport function Ipsum(\n lengthOrOptions:\n | number\n | {\n length: number\n lettercase?: 'sentence' | 'title'\n trailingPeriod?: boolean\n }\n) {\n if (typeof lengthOrOptions === 'number') {\n return recursiveGrow(lengthOrOptions)\n }\n const { length, lettercase, trailingPeriod } = lengthOrOptions\n let longString = recursiveGrow(length)\n const lastChar = longString[longString.length - 1]\n if (!trailingPeriod && ['.', ','].includes(lastChar)) {\n longString = longString.slice(0, -1)\n }\n if (lettercase === 'title') {\n longString = longString.replace(/\\b\\w/g, (s) => s.toUpperCase())\n }\n return longString\n}\n\n/**\n * Creates a sentence case sentence.\n * @returns string\n */\nconst recursiveGrow = (length = 1, out = exampleText.longest_ipsum): string => {\n if (!length) {\n return ''\n }\n if (out.length < length) {\n return recursiveGrow(length, out + exampleText.longest_ipsum)\n }\n if (out.length >= length) {\n return out.slice(0, length - 1) + '.'\n }\n return 'Lorem ipsum grow failed.'\n}\n"],"mappings":"AAAA,OAAO,IAAMA,WAAW,GAAG;EACzB,WAAS,WAAW;EACpBC,IAAI,EAAE,EAAE;EACRC,WAAW,EAAE,OAAO;EACpBC,cAAc,EAAE,uDAAuD;EACvEC,UAAU,sXAKgC;EAC1CC,aAAa,o+BAYuC;EACpDC,mBAAmB;AACrB,CAAC;AAED,OAAO,SAASC,KAAKA,CACnBC,eAMK,EACL;EACA,IAAI,OAAOA,eAAe,KAAK,QAAQ,EAAE;IACvC,OAAOC,cAAa,CAACD,eAAe,CAAC;EACvC;EACA,IAAQE,MAAM,GAAiCF,eAAe,CAAtDE,MAAM;IAAEC,UAAU,GAAqBH,eAAe,CAA9CG,UAAU;IAAEC,cAAc,GAAKJ,eAAe,CAAlCI,cAAc;EAC1C,IAAIC,UAAU,GAAGJ,cAAa,CAACC,MAAM,CAAC;EACtC,IAAMI,QAAQ,GAAGD,UAAU,CAACA,UAAU,CAACH,MAAM,GAAG,CAAC,CAAC;EAClD,IAAI,CAACE,cAAc,IAAI,CAAC,GAAG,EAAE,GAAG,C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