@contentful/field-editor-rich-text 3.1.11 → 3.2.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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.1.12...@contentful/field-editor-rich-text@3.2.0) (2022-11-16)
7
+
8
+ ### Features
9
+
10
+ - superscipt and subscript support to rich text editor [TOL-30] ([#1280](https://github.com/contentful/field-editors/issues/1280)) ([3c50f07](https://github.com/contentful/field-editors/commit/3c50f0770f95e7c11c12411e3c33c9d3593b19a7))
11
+
12
+ ## [3.1.12](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.1.11...@contentful/field-editor-rich-text@3.1.12) (2022-11-07)
13
+
14
+ **Note:** Version bump only for package @contentful/field-editor-rich-text
15
+
6
16
  ## [3.1.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.1.10...@contentful/field-editor-rich-text@3.1.11) (2022-11-07)
7
17
 
8
18
  **Note:** Version bump only for package @contentful/field-editor-rich-text
@@ -5096,6 +5096,30 @@ function ToolbarListButton(props) {
5096
5096
  }, /*#__PURE__*/React.createElement(f36Icons.ListNumberedIcon, null)));
5097
5097
  }
5098
5098
 
5099
+ var toggleMarkAndDeactivateConflictingMarks = function toggleMarkAndDeactivateConflictingMarks(editor, mark) {
5100
+ var subs = [Contentful.MARKS.SUPERSCRIPT, Contentful.MARKS.SUBSCRIPT];
5101
+ var clear = subs.includes(mark) ? subs : [];
5102
+ plateCore.toggleMark(editor, {
5103
+ key: mark,
5104
+ clear: clear
5105
+ });
5106
+ };
5107
+ var buildMarkEventHandler = function buildMarkEventHandler(type) {
5108
+ return function (editor, _ref) {
5109
+ var hotkey = _ref.options.hotkey;
5110
+ return function (event) {
5111
+ if (editor.selection && hotkey && isHotkey(hotkey, event)) {
5112
+ event.preventDefault();
5113
+ var isActive = plateCore.isMarkActive(editor, type);
5114
+ editor.tracking.onShortcutAction(isActive ? 'unmark' : 'mark', {
5115
+ markType: type
5116
+ });
5117
+ toggleMarkAndDeactivateConflictingMarks(editor, type);
5118
+ }
5119
+ };
5120
+ };
5121
+ };
5122
+
5099
5123
  var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
5100
5124
  var mark = _ref.mark,
5101
5125
  title = _ref.title,
@@ -5110,9 +5134,7 @@ var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
5110
5134
  editor.tracking.onToolbarAction(isActive ? 'unmark' : 'mark', {
5111
5135
  markType: mark
5112
5136
  });
5113
- plateCore.toggleMark(editor, {
5114
- key: mark
5115
- });
5137
+ toggleMarkAndDeactivateConflictingMarks(editor, mark);
5116
5138
  focus(editor);
5117
5139
  }, [editor]);
5118
5140
  if (!editor) return null;
@@ -5129,24 +5151,6 @@ var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
5129
5151
  return Mark;
5130
5152
  };
5131
5153
 
5132
- var buildMarkEventHandler = function buildMarkEventHandler(type) {
5133
- return function (editor, _ref) {
5134
- var hotkey = _ref.options.hotkey;
5135
- return function (event) {
5136
- if (editor.selection && hotkey && isHotkey(hotkey, event)) {
5137
- event.preventDefault();
5138
- var isActive = plateCore.isMarkActive(editor, type);
5139
- editor.tracking.onShortcutAction(isActive ? 'unmark' : 'mark', {
5140
- markType: type
5141
- });
5142
- plateCore.toggleMark(editor, {
5143
- key: type
5144
- });
5145
- }
5146
- };
5147
- };
5148
- };
5149
-
5150
5154
  var ToolbarBoldButton = /*#__PURE__*/createMarkToolbarButton({
5151
5155
  title: 'Bold',
5152
5156
  mark: Contentful.MARKS.BOLD,
@@ -5309,10 +5313,58 @@ var createUnderlinePlugin = function createUnderlinePlugin() {
5309
5313
  });
5310
5314
  };
5311
5315
 
5316
+ var ToolbarSuperscriptButton = /*#__PURE__*/createMarkToolbarButton({
5317
+ title: 'Superscript',
5318
+ mark: Contentful.MARKS.SUPERSCRIPT,
5319
+ icon: /*#__PURE__*/React.createElement(f36Icons.SuperscriptIcon, null)
5320
+ });
5321
+ function Superscript(props) {
5322
+ return /*#__PURE__*/React.createElement("sup", _extends({}, props.attributes), props.children);
5323
+ }
5324
+ var createSuperscriptPlugin = function createSuperscriptPlugin() {
5325
+ return plateBasicMarks.createSuperscriptPlugin({
5326
+ type: Contentful.MARKS.SUPERSCRIPT,
5327
+ component: Superscript,
5328
+ handlers: {
5329
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.SUPERSCRIPT)
5330
+ },
5331
+ deserializeHtml: {
5332
+ rules: [{
5333
+ validNodeName: ['SUP']
5334
+ }]
5335
+ }
5336
+ });
5337
+ };
5338
+
5339
+ var ToolbarSubscriptButton = /*#__PURE__*/createMarkToolbarButton({
5340
+ title: 'Subscript',
5341
+ mark: Contentful.MARKS.SUBSCRIPT,
5342
+ icon: /*#__PURE__*/React.createElement(f36Icons.SubscriptIcon, {
5343
+ viewBox: "0 0 23 18"
5344
+ })
5345
+ });
5346
+ function Subscript(props) {
5347
+ return /*#__PURE__*/React.createElement("sub", _extends({}, props.attributes), props.children);
5348
+ }
5349
+ var createSubscriptPlugin = function createSubscriptPlugin() {
5350
+ return plateBasicMarks.createSubscriptPlugin({
5351
+ type: Contentful.MARKS.SUBSCRIPT,
5352
+ component: Subscript,
5353
+ handlers: {
5354
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.SUBSCRIPT)
5355
+ },
5356
+ deserializeHtml: {
5357
+ rules: [{
5358
+ validNodeName: ['SUB']
5359
+ }]
5360
+ }
5361
+ });
5362
+ };
5363
+
5312
5364
  var createMarksPlugin = function createMarksPlugin() {
5313
5365
  return {
5314
5366
  key: 'Marks',
5315
- plugins: [createBoldPlugin(), createCodePlugin(), createItalicPlugin(), createUnderlinePlugin()]
5367
+ plugins: [createBoldPlugin(), createCodePlugin(), createItalicPlugin(), createUnderlinePlugin(), createSuperscriptPlugin(), createSubscriptPlugin()]
5316
5368
  };
5317
5369
  };
5318
5370
 
@@ -7358,6 +7410,10 @@ var Toolbar = function Toolbar(_ref) {
7358
7410
  isDisabled: isDisabled
7359
7411
  }), isMarkEnabled(sdk.field, Contentful.MARKS.ITALIC) && /*#__PURE__*/React__default.createElement(ToolbarItalicButton, {
7360
7412
  isDisabled: isDisabled
7413
+ }), isMarkEnabled(sdk.field, Contentful.MARKS.SUPERSCRIPT) && /*#__PURE__*/React__default.createElement(ToolbarSuperscriptButton, {
7414
+ isDisabled: isDisabled
7415
+ }), isMarkEnabled(sdk.field, Contentful.MARKS.SUBSCRIPT) && /*#__PURE__*/React__default.createElement(ToolbarSubscriptButton, {
7416
+ isDisabled: isDisabled
7361
7417
  }), isMarkEnabled(sdk.field, Contentful.MARKS.UNDERLINE) && /*#__PURE__*/React__default.createElement(ToolbarUnderlineButton, {
7362
7418
  isDisabled: isDisabled
7363
7419
  }), isMarkEnabled(sdk.field, Contentful.MARKS.CODE) && /*#__PURE__*/React__default.createElement(ToolbarCodeButton, {