@squiz/formatted-text-editor 1.67.0 → 1.67.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.67.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 928cc88: Made children optional for formatted text nodes/tags
8
+ - Updated dependencies [928cc88]
9
+ - @squiz/dx-json-schema-lib@1.65.1
10
+
3
11
  ## 1.67.0
4
12
 
5
13
  ### Minor Changes
@@ -121,7 +121,9 @@ const transformNode = (node) => {
121
121
  * @return {FormattedNode}
122
122
  */
123
123
  const wrapNodeIfNeeded = (node, wrappingNode, copyFont = true) => {
124
+ const wrappingNodeChildren = wrappingNode.children || [];
124
125
  if (node.type === 'tag' && wrappingNode.type === 'tag' && (node.tag === 'span' || node.tag === wrappingNode.tag)) {
126
+ const nodeChildren = node.children || [];
125
127
  // if the node we are wrapping with is a DOM node, and the node being wrapped is
126
128
  // a plain looking DOM node merge the 2 nodes.
127
129
  return {
@@ -141,13 +143,13 @@ const wrapNodeIfNeeded = (node, wrappingNode, copyFont = true) => {
141
143
  ...wrappingNode.font,
142
144
  }
143
145
  : {}),
144
- children: [...node.children, ...wrappingNode.children],
146
+ children: [...nodeChildren, ...wrappingNodeChildren],
145
147
  };
146
148
  }
147
149
  // if the node we are wrapping or the wrapping nodes are not compatible merge them.
148
150
  return {
149
151
  ...wrappingNode,
150
- children: [node, ...wrappingNode.children],
152
+ children: [node, ...wrappingNodeChildren],
151
153
  };
152
154
  };
153
155
  const transformMark = (mark, node) => {
@@ -133,7 +133,7 @@ const unwrapNodeIfNeeded = (node) => {
133
133
  const formatNode = (node) => {
134
134
  const children = [];
135
135
  if ('children' in node) {
136
- node.children.forEach((child) => {
136
+ node.children?.forEach((child) => {
137
137
  children.push(...formatNode(child));
138
138
  });
139
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/formatted-text-editor",
3
- "version": "1.67.0",
3
+ "version": "1.67.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "private": false,
@@ -23,7 +23,7 @@
23
23
  "@headlessui/react": "1.7.11",
24
24
  "@mui/icons-material": "5.11.16",
25
25
  "@remirror/react": "2.0.25",
26
- "@squiz/dx-json-schema-lib": "^1.65.0",
26
+ "@squiz/dx-json-schema-lib": "^1.65.1",
27
27
  "@squiz/resource-browser": "^1.66.3",
28
28
  "clsx": "1.2.1",
29
29
  "react-hook-form": "7.43.2",
@@ -13,7 +13,7 @@ type FontOptions = FormattedTextModels.v1.FormattedNodeFontProperties;
13
13
  type FormattedText = FormattedTextModels.v1.FormattedText;
14
14
  type FormattedNode = FormattedTextModels.v1.FormattedNodes;
15
15
  type FormattedNodeFontProperties = FormattedTextModels.v1.FormattedNodeFontProperties;
16
- type FormattedNodeWithChildren = Extract<FormattedNode, { children: FormattedNode[] }>;
16
+ type FormattedNodeWithChildren = Extract<FormattedNode, { children?: FormattedNode[] }>;
17
17
  type RemirrorTextAlignment = Exclude<Remirror.Attributes['nodeTextAlignment'], undefined>;
18
18
  type FormattedTextAlignment = FormattingOptions['alignment'];
19
19
 
@@ -164,7 +164,11 @@ const wrapNodeIfNeeded = (
164
164
  wrappingNode: FormattedNodeWithChildren,
165
165
  copyFont: boolean = true,
166
166
  ): FormattedNode => {
167
+ const wrappingNodeChildren = wrappingNode.children || [];
168
+
167
169
  if (node.type === 'tag' && wrappingNode.type === 'tag' && (node.tag === 'span' || node.tag === wrappingNode.tag)) {
170
+ const nodeChildren = node.children || [];
171
+
168
172
  // if the node we are wrapping with is a DOM node, and the node being wrapped is
169
173
  // a plain looking DOM node merge the 2 nodes.
170
174
  return {
@@ -186,14 +190,14 @@ const wrapNodeIfNeeded = (
186
190
  }
187
191
  : {},
188
192
  ),
189
- children: [...node.children, ...wrappingNode.children],
193
+ children: [...nodeChildren, ...wrappingNodeChildren],
190
194
  };
191
195
  }
192
196
 
193
197
  // if the node we are wrapping or the wrapping nodes are not compatible merge them.
194
198
  return {
195
199
  ...wrappingNode,
196
- children: [node, ...wrappingNode.children],
200
+ children: [node, ...wrappingNodeChildren],
197
201
  };
198
202
  };
199
203
 
@@ -146,7 +146,7 @@ const formatNode = (node: FormattedNodes): RemirrorJSON[] => {
146
146
  const children: RemirrorJSON[] = [];
147
147
 
148
148
  if ('children' in node) {
149
- node.children.forEach((child: FormattedNodes) => {
149
+ node.children?.forEach((child: FormattedNodes) => {
150
150
  children.push(...formatNode(child));
151
151
  });
152
152
  }