@contentful/field-editor-rich-text 3.22.2 → 3.23.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.
@@ -25,6 +25,7 @@ const _List = require("../plugins/List");
25
25
  const _Bold = require("../plugins/Marks/Bold");
26
26
  const _Code = require("../plugins/Marks/Code");
27
27
  const _Italic = require("../plugins/Marks/Italic");
28
+ const _Strikethrough = require("../plugins/Marks/Strikethrough");
28
29
  const _Subscript = require("../plugins/Marks/Subscript");
29
30
  const _Superscript = require("../plugins/Marks/Superscript");
30
31
  const _Underline = require("../plugins/Marks/Underline");
@@ -124,9 +125,15 @@ const styles = {
124
125
  marginRight: '20px'
125
126
  })
126
127
  };
128
+ const dropdownMarks = [
129
+ _richtexttypes.MARKS.SUPERSCRIPT,
130
+ _richtexttypes.MARKS.SUBSCRIPT,
131
+ _richtexttypes.MARKS.CODE,
132
+ _richtexttypes.MARKS.STRIKETHROUGH
133
+ ];
127
134
  const Dropdown = ({ sdk, isDisabled })=>{
128
135
  const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
129
- const isActive = editor && ((0, _queries.isMarkActive)(editor, _richtexttypes.MARKS.SUPERSCRIPT) || (0, _queries.isMarkActive)(editor, _richtexttypes.MARKS.SUBSCRIPT) || (0, _queries.isMarkActive)(editor, _richtexttypes.MARKS.CODE));
136
+ const isActive = editor && dropdownMarks.some((mark)=>(0, _queries.isMarkActive)(editor, mark));
130
137
  return _react.createElement(_f36components.Menu, null, _react.createElement(_f36components.Menu.Trigger, null, _react.createElement("span", null, _react.createElement(_f36components.IconButton, {
131
138
  size: "small",
132
139
  className: styles.toolbarBtn,
@@ -139,6 +146,8 @@ const Dropdown = ({ sdk, isDisabled })=>{
139
146
  isDisabled: isDisabled
140
147
  }), (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.SUBSCRIPT) && _react.createElement(_Subscript.ToolbarDropdownSubscriptButton, {
141
148
  isDisabled: isDisabled
149
+ }), (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.STRIKETHROUGH) && _react.createElement(_Strikethrough.ToolbarDropdownStrikethroughButton, {
150
+ isDisabled: isDisabled
142
151
  }), (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.CODE) && _react.createElement(_Code.ToolbarDropdownCodeButton, {
143
152
  isDisabled: isDisabled
144
153
  })));
@@ -154,7 +163,7 @@ const Toolbar = ({ isDisabled })=>{
154
163
  const isBlockquoteSelected = (0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.QUOTE);
155
164
  const shouldDisableTables = isDisabled || !canInsertBlocks || isListSelected || isBlockquoteSelected;
156
165
  const boldItalicUnderlineAvailable = (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.BOLD) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.ITALIC) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.UNDERLINE);
157
- const dropdownItemsAvailable = (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.SUPERSCRIPT) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.SUBSCRIPT) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.CODE);
166
+ const dropdownItemsAvailable = dropdownMarks.some((mark)=>(0, _validations.isMarkEnabled)(sdk.field, mark));
158
167
  const shouldShowDropdown = boldItalicUnderlineAvailable && dropdownItemsAvailable;
159
168
  return _react.createElement(_f36components.Flex, {
160
169
  gap: "spacingS",
@@ -181,6 +190,8 @@ const Toolbar = ({ isDisabled })=>{
181
190
  isDisabled: isDisabled
182
191
  }), !boldItalicUnderlineAvailable && (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.SUBSCRIPT) && _react.createElement(_Subscript.ToolbarSubscriptButton, {
183
192
  isDisabled: isDisabled
193
+ }), !boldItalicUnderlineAvailable && (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.STRIKETHROUGH) && _react.createElement(_Strikethrough.ToolbarStrikethroughButton, {
194
+ isDisabled: isDisabled
184
195
  }), !boldItalicUnderlineAvailable && (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.CODE) && _react.createElement(_Code.ToolbarCodeButton, {
185
196
  isDisabled: isDisabled
186
197
  }), shouldShowDropdown && _react.createElement(Dropdown, {
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ Strikethrough: function() {
13
+ return Strikethrough;
14
+ },
15
+ ToolbarDropdownStrikethroughButton: function() {
16
+ return ToolbarDropdownStrikethroughButton;
17
+ },
18
+ ToolbarStrikethroughButton: function() {
19
+ return ToolbarStrikethroughButton;
20
+ },
21
+ createStrikethroughPlugin: function() {
22
+ return createStrikethroughPlugin;
23
+ }
24
+ });
25
+ const _react = _interop_require_wildcard(require("react"));
26
+ const _richtexttypes = require("@contentful/rich-text-types");
27
+ const _platebasicmarks = require("@udecode/plate-basic-marks");
28
+ const _emotion = require("emotion");
29
+ const _MarkToolbarButton = require("./components/MarkToolbarButton");
30
+ const _helpers = require("./helpers");
31
+ function _getRequireWildcardCache(nodeInterop) {
32
+ if (typeof WeakMap !== "function") return null;
33
+ var cacheBabelInterop = new WeakMap();
34
+ var cacheNodeInterop = new WeakMap();
35
+ return (_getRequireWildcardCache = function(nodeInterop) {
36
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
37
+ })(nodeInterop);
38
+ }
39
+ function _interop_require_wildcard(obj, nodeInterop) {
40
+ if (!nodeInterop && obj && obj.__esModule) {
41
+ return obj;
42
+ }
43
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
44
+ return {
45
+ default: obj
46
+ };
47
+ }
48
+ var cache = _getRequireWildcardCache(nodeInterop);
49
+ if (cache && cache.has(obj)) {
50
+ return cache.get(obj);
51
+ }
52
+ var newObj = {
53
+ __proto__: null
54
+ };
55
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
56
+ for(var key in obj){
57
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
58
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
59
+ if (desc && (desc.get || desc.set)) {
60
+ Object.defineProperty(newObj, key, desc);
61
+ } else {
62
+ newObj[key] = obj[key];
63
+ }
64
+ }
65
+ }
66
+ newObj.default = obj;
67
+ if (cache) {
68
+ cache.set(obj, newObj);
69
+ }
70
+ return newObj;
71
+ }
72
+ const styles = {
73
+ strikethrough: (0, _emotion.css)({
74
+ textDecoration: 'line-through'
75
+ })
76
+ };
77
+ const ToolbarDropdownStrikethroughButton = (0, _MarkToolbarButton.createMarkToolbarButton)({
78
+ title: 'Strikethrough',
79
+ mark: _richtexttypes.MARKS.STRIKETHROUGH
80
+ });
81
+ const ToolbarStrikethroughButton = (0, _MarkToolbarButton.createMarkToolbarButton)({
82
+ title: 'Strikethrough',
83
+ mark: _richtexttypes.MARKS.STRIKETHROUGH,
84
+ icon: _react.createElement("svg", {
85
+ xmlns: "http://www.w3.org/2000/svg",
86
+ viewBox: "0 0 256 256",
87
+ width: "18",
88
+ height: "18"
89
+ }, _react.createElement("rect", {
90
+ width: "256",
91
+ height: "256",
92
+ fill: "none"
93
+ }), _react.createElement("line", {
94
+ x1: "40",
95
+ y1: "128",
96
+ x2: "216",
97
+ y2: "128",
98
+ fill: "none",
99
+ stroke: "currentColor",
100
+ strokeLinecap: "round",
101
+ strokeLinejoin: "round",
102
+ strokeWidth: "24"
103
+ }), _react.createElement("path", {
104
+ d: "M72,168c0,22.09,25.07,40,56,40s56-17.91,56-40c0-23.77-21.62-33-45.6-40",
105
+ fill: "none",
106
+ stroke: "currentColor",
107
+ strokeLinecap: "round",
108
+ strokeLinejoin: "round",
109
+ strokeWidth: "24"
110
+ }), _react.createElement("path", {
111
+ d: "M75.11,88c0-22.09,22-40,52.89-40,23,0,40.24,9.87,48,24",
112
+ fill: "none",
113
+ stroke: "currentColor",
114
+ strokeLinecap: "round",
115
+ strokeLinejoin: "round",
116
+ strokeWidth: "24"
117
+ }))
118
+ });
119
+ function Strikethrough(props) {
120
+ return _react.createElement("s", {
121
+ ...props.attributes,
122
+ className: styles.strikethrough
123
+ }, props.children);
124
+ }
125
+ const createStrikethroughPlugin = ()=>(0, _platebasicmarks.createStrikethroughPlugin)({
126
+ type: _richtexttypes.MARKS.STRIKETHROUGH,
127
+ component: Strikethrough,
128
+ handlers: {
129
+ onKeyDown: (0, _helpers.buildMarkEventHandler)(_richtexttypes.MARKS.STRIKETHROUGH)
130
+ },
131
+ deserializeHtml: {
132
+ rules: [
133
+ {
134
+ validNodeName: [
135
+ 'S'
136
+ ]
137
+ }
138
+ ]
139
+ }
140
+ });
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "createMarksPlugin", {
11
11
  const _Bold = require("./Bold");
12
12
  const _Code = require("./Code");
13
13
  const _Italic = require("./Italic");
14
+ const _Strikethrough = require("./Strikethrough");
14
15
  const _Subscript = require("./Subscript");
15
16
  const _Superscript = require("./Superscript");
16
17
  const _Underline = require("./Underline");
@@ -22,6 +23,7 @@ const createMarksPlugin = ()=>({
22
23
  (0, _Italic.createItalicPlugin)(),
23
24
  (0, _Underline.createUnderlinePlugin)(),
24
25
  (0, _Superscript.createSuperscriptPlugin)(),
25
- (0, _Subscript.createSubscriptPlugin)()
26
+ (0, _Subscript.createSubscriptPlugin)(),
27
+ (0, _Strikethrough.createStrikethroughPlugin)()
26
28
  ]
27
29
  });
@@ -15,6 +15,7 @@ import { ToolbarListButton } from '../plugins/List';
15
15
  import { ToolbarBoldButton } from '../plugins/Marks/Bold';
16
16
  import { ToolbarCodeButton, ToolbarDropdownCodeButton } from '../plugins/Marks/Code';
17
17
  import { ToolbarItalicButton } from '../plugins/Marks/Italic';
18
+ import { ToolbarDropdownStrikethroughButton, ToolbarStrikethroughButton } from '../plugins/Marks/Strikethrough';
18
19
  import { ToolbarDropdownSubscriptButton, ToolbarSubscriptButton } from '../plugins/Marks/Subscript';
19
20
  import { ToolbarDropdownSuperscriptButton, ToolbarSuperscriptButton } from '../plugins/Marks/Superscript';
20
21
  import { ToolbarUnderlineButton } from '../plugins/Marks/Underline';
@@ -68,9 +69,15 @@ const styles = {
68
69
  marginRight: '20px'
69
70
  })
70
71
  };
72
+ const dropdownMarks = [
73
+ MARKS.SUPERSCRIPT,
74
+ MARKS.SUBSCRIPT,
75
+ MARKS.CODE,
76
+ MARKS.STRIKETHROUGH
77
+ ];
71
78
  const Dropdown = ({ sdk, isDisabled })=>{
72
79
  const editor = useContentfulEditor();
73
- const isActive = editor && (isMarkActive(editor, MARKS.SUPERSCRIPT) || isMarkActive(editor, MARKS.SUBSCRIPT) || isMarkActive(editor, MARKS.CODE));
80
+ const isActive = editor && dropdownMarks.some((mark)=>isMarkActive(editor, mark));
74
81
  return React.createElement(Menu, null, React.createElement(Menu.Trigger, null, React.createElement("span", null, React.createElement(IconButton, {
75
82
  size: "small",
76
83
  className: styles.toolbarBtn,
@@ -83,6 +90,8 @@ const Dropdown = ({ sdk, isDisabled })=>{
83
90
  isDisabled: isDisabled
84
91
  }), isMarkEnabled(sdk.field, MARKS.SUBSCRIPT) && React.createElement(ToolbarDropdownSubscriptButton, {
85
92
  isDisabled: isDisabled
93
+ }), isMarkEnabled(sdk.field, MARKS.STRIKETHROUGH) && React.createElement(ToolbarDropdownStrikethroughButton, {
94
+ isDisabled: isDisabled
86
95
  }), isMarkEnabled(sdk.field, MARKS.CODE) && React.createElement(ToolbarDropdownCodeButton, {
87
96
  isDisabled: isDisabled
88
97
  })));
@@ -98,7 +107,7 @@ const Toolbar = ({ isDisabled })=>{
98
107
  const isBlockquoteSelected = isNodeTypeSelected(editor, BLOCKS.QUOTE);
99
108
  const shouldDisableTables = isDisabled || !canInsertBlocks || isListSelected || isBlockquoteSelected;
100
109
  const boldItalicUnderlineAvailable = isMarkEnabled(sdk.field, MARKS.BOLD) || isMarkEnabled(sdk.field, MARKS.ITALIC) || isMarkEnabled(sdk.field, MARKS.UNDERLINE);
101
- const dropdownItemsAvailable = isMarkEnabled(sdk.field, MARKS.SUPERSCRIPT) || isMarkEnabled(sdk.field, MARKS.SUBSCRIPT) || isMarkEnabled(sdk.field, MARKS.CODE);
110
+ const dropdownItemsAvailable = dropdownMarks.some((mark)=>isMarkEnabled(sdk.field, mark));
102
111
  const shouldShowDropdown = boldItalicUnderlineAvailable && dropdownItemsAvailable;
103
112
  return React.createElement(Flex, {
104
113
  gap: "spacingS",
@@ -125,6 +134,8 @@ const Toolbar = ({ isDisabled })=>{
125
134
  isDisabled: isDisabled
126
135
  }), !boldItalicUnderlineAvailable && isMarkEnabled(sdk.field, MARKS.SUBSCRIPT) && React.createElement(ToolbarSubscriptButton, {
127
136
  isDisabled: isDisabled
137
+ }), !boldItalicUnderlineAvailable && isMarkEnabled(sdk.field, MARKS.STRIKETHROUGH) && React.createElement(ToolbarStrikethroughButton, {
138
+ isDisabled: isDisabled
128
139
  }), !boldItalicUnderlineAvailable && isMarkEnabled(sdk.field, MARKS.CODE) && React.createElement(ToolbarCodeButton, {
129
140
  isDisabled: isDisabled
130
141
  }), shouldShowDropdown && React.createElement(Dropdown, {
@@ -0,0 +1,75 @@
1
+ import * as React from 'react';
2
+ import { MARKS } from '@contentful/rich-text-types';
3
+ import { createStrikethroughPlugin as createDefaultStrikethroughPlugin } from '@udecode/plate-basic-marks';
4
+ import { css } from 'emotion';
5
+ import { createMarkToolbarButton } from './components/MarkToolbarButton';
6
+ import { buildMarkEventHandler } from './helpers';
7
+ const styles = {
8
+ strikethrough: css({
9
+ textDecoration: 'line-through'
10
+ })
11
+ };
12
+ export const ToolbarDropdownStrikethroughButton = createMarkToolbarButton({
13
+ title: 'Strikethrough',
14
+ mark: MARKS.STRIKETHROUGH
15
+ });
16
+ export const ToolbarStrikethroughButton = createMarkToolbarButton({
17
+ title: 'Strikethrough',
18
+ mark: MARKS.STRIKETHROUGH,
19
+ icon: React.createElement("svg", {
20
+ xmlns: "http://www.w3.org/2000/svg",
21
+ viewBox: "0 0 256 256",
22
+ width: "18",
23
+ height: "18"
24
+ }, React.createElement("rect", {
25
+ width: "256",
26
+ height: "256",
27
+ fill: "none"
28
+ }), React.createElement("line", {
29
+ x1: "40",
30
+ y1: "128",
31
+ x2: "216",
32
+ y2: "128",
33
+ fill: "none",
34
+ stroke: "currentColor",
35
+ strokeLinecap: "round",
36
+ strokeLinejoin: "round",
37
+ strokeWidth: "24"
38
+ }), React.createElement("path", {
39
+ d: "M72,168c0,22.09,25.07,40,56,40s56-17.91,56-40c0-23.77-21.62-33-45.6-40",
40
+ fill: "none",
41
+ stroke: "currentColor",
42
+ strokeLinecap: "round",
43
+ strokeLinejoin: "round",
44
+ strokeWidth: "24"
45
+ }), React.createElement("path", {
46
+ d: "M75.11,88c0-22.09,22-40,52.89-40,23,0,40.24,9.87,48,24",
47
+ fill: "none",
48
+ stroke: "currentColor",
49
+ strokeLinecap: "round",
50
+ strokeLinejoin: "round",
51
+ strokeWidth: "24"
52
+ }))
53
+ });
54
+ export function Strikethrough(props) {
55
+ return React.createElement("s", {
56
+ ...props.attributes,
57
+ className: styles.strikethrough
58
+ }, props.children);
59
+ }
60
+ export const createStrikethroughPlugin = ()=>createDefaultStrikethroughPlugin({
61
+ type: MARKS.STRIKETHROUGH,
62
+ component: Strikethrough,
63
+ handlers: {
64
+ onKeyDown: buildMarkEventHandler(MARKS.STRIKETHROUGH)
65
+ },
66
+ deserializeHtml: {
67
+ rules: [
68
+ {
69
+ validNodeName: [
70
+ 'S'
71
+ ]
72
+ }
73
+ ]
74
+ }
75
+ });
@@ -1,6 +1,7 @@
1
1
  import { createBoldPlugin } from './Bold';
2
2
  import { createCodePlugin } from './Code';
3
3
  import { createItalicPlugin } from './Italic';
4
+ import { createStrikethroughPlugin } from './Strikethrough';
4
5
  import { createSubscriptPlugin } from './Subscript';
5
6
  import { createSuperscriptPlugin } from './Superscript';
6
7
  import { createUnderlinePlugin } from './Underline';
@@ -12,6 +13,7 @@ export const createMarksPlugin = ()=>({
12
13
  createItalicPlugin(),
13
14
  createUnderlinePlugin(),
14
15
  createSuperscriptPlugin(),
15
- createSubscriptPlugin()
16
+ createSubscriptPlugin(),
17
+ createStrikethroughPlugin()
16
18
  ]
17
19
  });
@@ -15,6 +15,7 @@ export interface Text extends p.TText {
15
15
  [MARKS.UNDERLINE]?: boolean;
16
16
  [MARKS.SUPERSCRIPT]?: boolean;
17
17
  [MARKS.SUBSCRIPT]?: boolean;
18
+ [MARKS.STRIKETHROUGH]?: boolean;
18
19
  }
19
20
  export interface Element extends p.TElement {
20
21
  type: string;
@@ -0,0 +1,16 @@
1
+ import { MARKS } from '@contentful/rich-text-types';
2
+ import { PlatePlugin, RenderLeafProps } from '../../internal/types';
3
+ export declare const ToolbarDropdownStrikethroughButton: {
4
+ ({ isDisabled }: {
5
+ isDisabled?: boolean | undefined;
6
+ }): JSX.Element | null;
7
+ displayName: MARKS;
8
+ };
9
+ export declare const ToolbarStrikethroughButton: {
10
+ ({ isDisabled }: {
11
+ isDisabled?: boolean | undefined;
12
+ }): JSX.Element | null;
13
+ displayName: MARKS;
14
+ };
15
+ export declare function Strikethrough(props: RenderLeafProps): JSX.Element;
16
+ export declare const createStrikethroughPlugin: () => PlatePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.22.2",
3
+ "version": "3.23.0",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -44,10 +44,10 @@
44
44
  "@contentful/f36-icons": "^4.1.1",
45
45
  "@contentful/f36-tokens": "^4.0.0",
46
46
  "@contentful/f36-utils": "^4.19.0",
47
- "@contentful/field-editor-reference": "^5.28.1",
48
- "@contentful/field-editor-shared": "^1.5.1",
47
+ "@contentful/field-editor-reference": "^5.28.2",
48
+ "@contentful/field-editor-shared": "^1.5.2",
49
49
  "@contentful/rich-text-plain-text-renderer": "^16.0.4",
50
- "@contentful/rich-text-types": "16.3.0",
50
+ "@contentful/rich-text-types": "16.5.0",
51
51
  "@popperjs/core": "^2.11.5",
52
52
  "@udecode/plate-basic-marks": "30.1.2",
53
53
  "@udecode/plate-break": "30.1.2",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "registry": "https://npm.pkg.github.com/"
88
88
  },
89
- "gitHead": "60fd3c2f5a58f4d42886b5f952ce3cc1aec71833"
89
+ "gitHead": "73b725e42e7d57a13494863bc7b8f784fa6522b9"
90
90
  }