@flozy/editor 10.7.7 → 10.7.9

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.
@@ -143,11 +143,22 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
143
143
  isUploadInProgress = () => {}
144
144
  } = otherProps || {};
145
145
  const translationFn = translation || translationMock || (() => {});
146
+ const getTitleSaveData = title => {
147
+ const val = debouncedValue.current;
148
+ const data = {
149
+ text: serializeToText(val),
150
+ title: title
151
+ };
152
+ if (customProps.onSaveTitle) {
153
+ const isTitleChanged = true;
154
+ customProps.onSaveTitle(JSON.stringify(val), data, isTitleChanged);
155
+ }
156
+ };
146
157
  const editor = useMemo(() => {
147
158
  if (collaborativeEditor) return collaborativeEditor;
148
159
  const editor = createEditor();
149
160
  editor.needLayout = needLayout;
150
- editor.translation = translationFn;
161
+ editor.getTitleSaveData = getTitleSaveData;
151
162
  return withCommon(editor, {
152
163
  needLayout
153
164
  });
@@ -227,17 +238,6 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
227
238
  title: serializeToText(title?.children) || ""
228
239
  };
229
240
  };
230
- const getTitleSaveData = title => {
231
- const val = debouncedValue.current;
232
- const data = {
233
- text: serializeToText(val),
234
- title: title
235
- };
236
- if (customProps.onSaveTitle) {
237
- const isTitleChanged = true;
238
- customProps.onSaveTitle(JSON.stringify(val), data, isTitleChanged);
239
- }
240
- };
241
241
  const getPreviewImage = async (needBackground = false, options = {}) => {
242
242
  ReactEditor.blur(editor);
243
243
  const dom = needBackground ? editorWrapper?.current : editorWrapper?.current.getElementsByClassName("innert-editor-textbox")[0];
@@ -153,6 +153,52 @@ const getFocusedNode = (editor, nodeType = "") => {
153
153
  }
154
154
  };
155
155
  const voidTypes = ["image", "page-settings"];
156
+
157
+ // 🧠 Split the fragment into first text and rest
158
+ const splitFragment = fragment => {
159
+ let found = false;
160
+ let firstText = "";
161
+ const rest = [];
162
+ for (const node of fragment) {
163
+ if (found) {
164
+ rest.push(node);
165
+ continue;
166
+ }
167
+ const textNodeEntry = [...Node.texts(node)].find(([n]) => n.text.trim().length > 0);
168
+ if (textNodeEntry) {
169
+ const [textNode, path] = textNodeEntry;
170
+ firstText = textNode.text;
171
+
172
+ // Remove the first text node from the node
173
+ const cloned = JSON.parse(JSON.stringify(node));
174
+ let pointer = cloned;
175
+ for (let i = 0; i < path.length - 1; i++) {
176
+ pointer = pointer.children[path[i]];
177
+ }
178
+
179
+ // Remove the first text portion or replace with remaining text
180
+ const index = path[path.length - 1];
181
+ // const original = pointer.children[index];
182
+ // const remainingText = original.text.slice(firstText.length);
183
+
184
+ // if (remainingText) {
185
+ // pointer.children[index] = { ...original, text: remainingText };
186
+ // } else {
187
+ // pointer.children.splice(index, 1);
188
+ // }
189
+
190
+ pointer.children.splice(index, 1);
191
+ if (cloned.children.length > 0) {
192
+ rest.push(cloned);
193
+ }
194
+ found = true;
195
+ } else {
196
+ rest.push(node); // fallback
197
+ }
198
+ }
199
+
200
+ return [firstText, rest];
201
+ };
156
202
  const withHtml = editor => {
157
203
  const {
158
204
  insertData,
@@ -280,9 +326,14 @@ const withHtml = editor => {
280
326
  const firstNodePasted = formattedFragment[0];
281
327
  const isAllowedTextNode = ALLOWED_TEXT_NODES.includes(firstNodePasted?.type || "");
282
328
  if (isAllowedTextNode) {
283
- const [firstNode, ...rest] = formattedFragment;
284
- Transforms.insertFragment(editor, [firstNode]);
285
- insertAtNextNode(editor, rest);
329
+ const [firstText, remainingFragment] = splitFragment(fragment);
330
+ Transforms.insertFragment(editor, [{
331
+ text: firstText
332
+ }]);
333
+ insertAtNextNode(editor, remainingFragment);
334
+ if (editor.getTitleSaveData) {
335
+ editor.getTitleSaveData(firstText);
336
+ }
286
337
  } else {
287
338
  insertAtNextNode(editor, formattedFragment);
288
339
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "10.7.7",
3
+ "version": "10.7.9",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"