@commercetools-uikit/rich-text-utils 15.0.0 → 15.0.2

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.
@@ -165,13 +165,12 @@ var serializeNode = function serializeNode(node) {
165
165
  }
166
166
  };
167
167
 
168
- var wrapWithParaghraph = function wrapWithParaghraph() {
169
- var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
170
- return "<p>".concat(content, "</p>");
168
+ var isEmptyParagraph = function isEmptyParagraph(value) {
169
+ return slate.Element.isElement(value) && value.type === 'paragraph' && value.children.length === 1 && value.children[0].text === '';
171
170
  };
172
171
 
173
172
  var serializeSingle = function serializeSingle(value) {
174
- if (value === null) return wrapWithParaghraph();
173
+ if (value === null || isEmptyParagraph(value)) return '';
175
174
  return serializeNode(value);
176
175
  };
177
176
 
@@ -186,7 +185,7 @@ var serialize = function serialize(value) {
186
185
  }).join('');
187
186
  }
188
187
 
189
- return outputHtml.length > 0 ? outputHtml : wrapWithParaghraph(outputHtml);
188
+ return outputHtml;
190
189
  };
191
190
 
192
191
  var ELEMENT_TAGS = {
@@ -3245,7 +3244,7 @@ RichTextEditorBody.defaultProps = defaultProps;
3245
3244
  var RichTextEditorBody$1 = RichTextEditorBody;
3246
3245
 
3247
3246
  // NOTE: This string will be replaced on build time with the package version.
3248
- var version = "15.0.0";
3247
+ var version = "15.0.2";
3249
3248
 
3250
3249
  exports.Element = Element;
3251
3250
  exports.HiddenInput = HiddenInput$1;
@@ -164,13 +164,12 @@ var serializeNode = function serializeNode(node) {
164
164
  }
165
165
  };
166
166
 
167
- var wrapWithParaghraph = function wrapWithParaghraph() {
168
- var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
169
- return "<p>".concat(content, "</p>");
167
+ var isEmptyParagraph = function isEmptyParagraph(value) {
168
+ return slate.Element.isElement(value) && value.type === 'paragraph' && value.children.length === 1 && value.children[0].text === '';
170
169
  };
171
170
 
172
171
  var serializeSingle = function serializeSingle(value) {
173
- if (value === null) return wrapWithParaghraph();
172
+ if (value === null || isEmptyParagraph(value)) return '';
174
173
  return serializeNode(value);
175
174
  };
176
175
 
@@ -185,7 +184,7 @@ var serialize = function serialize(value) {
185
184
  }).join('');
186
185
  }
187
186
 
188
- return outputHtml.length > 0 ? outputHtml : wrapWithParaghraph(outputHtml);
187
+ return outputHtml;
189
188
  };
190
189
 
191
190
  var ELEMENT_TAGS = {
@@ -3120,7 +3119,7 @@ RichTextEditorBody.defaultProps = defaultProps;
3120
3119
  var RichTextEditorBody$1 = RichTextEditorBody;
3121
3120
 
3122
3121
  // NOTE: This string will be replaced on build time with the package version.
3123
- var version = "15.0.0";
3122
+ var version = "15.0.2";
3124
3123
 
3125
3124
  exports.Element = Element;
3126
3125
  exports.HiddenInput = HiddenInput$1;
@@ -9,7 +9,7 @@ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
9
9
  import { warning } from '@commercetools-uikit/utils';
10
10
  import uniq from 'lodash/uniq';
11
11
  import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
12
- import { Text, Element as Element$1, Editor, Transforms } from 'slate';
12
+ import { Element as Element$1, Text, Editor, Transforms } from 'slate';
13
13
  import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
14
14
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
15
15
  import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
@@ -128,13 +128,12 @@ var serializeNode = function serializeNode(node) {
128
128
  }
129
129
  };
130
130
 
131
- var wrapWithParaghraph = function wrapWithParaghraph() {
132
- var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
133
- return "<p>".concat(content, "</p>");
131
+ var isEmptyParagraph = function isEmptyParagraph(value) {
132
+ return Element$1.isElement(value) && value.type === 'paragraph' && value.children.length === 1 && value.children[0].text === '';
134
133
  };
135
134
 
136
135
  var serializeSingle = function serializeSingle(value) {
137
- if (value === null) return wrapWithParaghraph();
136
+ if (value === null || isEmptyParagraph(value)) return '';
138
137
  return serializeNode(value);
139
138
  };
140
139
 
@@ -149,7 +148,7 @@ var serialize = function serialize(value) {
149
148
  }).join('');
150
149
  }
151
150
 
152
- return outputHtml.length > 0 ? outputHtml : wrapWithParaghraph(outputHtml);
151
+ return outputHtml;
153
152
  };
154
153
 
155
154
  var ELEMENT_TAGS = {
@@ -3208,6 +3207,6 @@ RichTextEditorBody.defaultProps = defaultProps;
3208
3207
  var RichTextEditorBody$1 = RichTextEditorBody;
3209
3208
 
3210
3209
  // NOTE: This string will be replaced on build time with the package version.
3211
- var version = "15.0.0";
3210
+ var version = "15.0.2";
3212
3211
 
3213
3212
  export { Element, HiddenInput$1 as HiddenInput, Leaf, RichTextEditorBody$1 as RichTextBody, focusEditor, html$1 as html, isBlockActive, isRichTextEmpty as isEmpty, isMarkActive, index as localized, resetEditor, toggleBlock, toggleMark, validSlateStateAdapter, version };
@@ -1,5 +1,30 @@
1
- import { type Descendant } from 'slate';
1
+ import { type Descendant, type BaseEditor, type BaseText } from 'slate';
2
+ import { type ReactEditor as TReactEditor } from 'slate-react';
3
+ import type { HistoryEditor } from 'slate-history';
4
+ import { BLOCK_TAGS, MARK_TAGS } from '../tags';
2
5
  declare type Html = string;
6
+ export declare type CustomElement = {
7
+ type: Format;
8
+ children: CustomText[];
9
+ align?: string;
10
+ };
11
+ declare type CustomText = BaseText & {
12
+ bold?: boolean;
13
+ code?: string;
14
+ italic?: string;
15
+ underline?: string;
16
+ superscript?: string;
17
+ subscript?: string;
18
+ strikethrough?: string;
19
+ };
20
+ export declare type Format = typeof BLOCK_TAGS[keyof typeof BLOCK_TAGS] & typeof MARK_TAGS[keyof typeof MARK_TAGS];
21
+ declare module 'slate' {
22
+ interface CustomTypes {
23
+ Editor: BaseEditor & TReactEditor & HistoryEditor;
24
+ Element: CustomElement;
25
+ Text: CustomText;
26
+ }
27
+ }
3
28
  export declare type Deserialized = Descendant | null;
4
29
  export declare const defaultSlateState: Descendant[];
5
30
  declare const html: {
@@ -1 +1 @@
1
- export { default, defaultSlateState, type Deserialized } from './html';
1
+ export { default, defaultSlateState, type Deserialized, type Format, type CustomElement, } from './html';
@@ -1,30 +1,6 @@
1
- import { Editor, type BaseEditor, type BaseText, type Editor as TEditor, type Descendant } from 'slate';
2
- import { type ReactEditor as TReactEditor, type RenderElementProps, type RenderLeafProps } from 'slate-react';
3
- import type { HistoryEditor } from 'slate-history';
4
- import { BLOCK_TAGS, MARK_TAGS } from './tags';
5
- import { type Deserialized } from './html';
6
- declare type CustomElement = {
7
- type: Format;
8
- children: CustomText[];
9
- align?: string;
10
- };
11
- declare type CustomText = BaseText & {
12
- bold?: boolean;
13
- code?: string;
14
- italic?: string;
15
- underline?: string;
16
- superscript?: string;
17
- subscript?: string;
18
- strikethrough?: string;
19
- };
20
- declare type Format = typeof BLOCK_TAGS[keyof typeof BLOCK_TAGS] & typeof MARK_TAGS[keyof typeof MARK_TAGS];
21
- declare module 'slate' {
22
- interface CustomTypes {
23
- Editor: BaseEditor & TReactEditor & HistoryEditor;
24
- Element: CustomElement;
25
- Text: CustomText;
26
- }
27
- }
1
+ import { Editor, type Editor as TEditor, type Descendant } from 'slate';
2
+ import { type RenderElementProps, type RenderLeafProps } from 'slate-react';
3
+ import { type Deserialized, type Format } from './html';
28
4
  declare const Element: ({ attributes, children, element }: RenderElementProps) => import("@emotion/react/jsx-runtime").JSX.Element;
29
5
  declare const Leaf: ({ attributes, children, leaf }: RenderLeafProps) => import("@emotion/react/jsx-runtime").JSX.Element;
30
6
  declare const isMarkActive: (editor: TEditor, format: Format) => boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/rich-text-utils",
3
3
  "description": "Utilities for working with rich-text components.",
4
- "version": "15.0.0",
4
+ "version": "15.0.2",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",