@lobehub/editor 4.9.0 → 4.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "4.9.0",
3
+ "version": "4.9.2",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -10,19 +10,15 @@ const SUPPORTED_VERSION = '0.42.0';
10
10
 
11
11
  const FILE_HASHES = {
12
12
  'Lexical.dev.js': {
13
- original: 'a7627f790028c3d6cd13b28bb0efdd8e5b48f85a1f0d62df5696e52c8b5f790d',
14
13
  patched: '7c81a9785b397dc09ce0ecc9f3126d3e4903cdfd12d5c51318965ed74b0e3ccb',
15
14
  },
16
15
  'Lexical.dev.mjs': {
17
- original: '0dd55914d1f967694a77f4fa842ecbbdc9376f7832b8cca380a213e30c4153b3',
18
16
  patched: '880f22f2ec2d873e1699766de39edce5123b4730009bb88bb33d7e4da98a4ad9',
19
17
  },
20
18
  'Lexical.prod.js': {
21
- original: 'dea32eb95962fa45df8251a42144f63821f7745f7dcfcc24d63f33d9cfb79a76',
22
19
  patched: '9f97867340b84853cf82bbd2d60ef9f944ee61ef058daa37007b820c2780a103',
23
20
  },
24
21
  'Lexical.prod.mjs': {
25
- original: 'b4c3af0707687a7d14519233cf9d373cb62261a281be6239649a4a1b36000e4b',
26
22
  patched: 'f7b2993582b2cc0573ca468373831b17971e0bb7383f5ca8785d4b93ab967c0b',
27
23
  },
28
24
  };
@@ -31,8 +27,35 @@ function sha256(content) {
31
27
  return crypto.createHash('sha256').update(content).digest('hex');
32
28
  }
33
29
 
30
+ function normalizeLineEndings(text) {
31
+ return text.replaceAll(/\r\n?/g, '\n');
32
+ }
33
+
34
+ function detectLineEnding(text) {
35
+ const crlfCount = (text.match(/\r\n/g) || []).length;
36
+ const lfCount = (text.match(/\n/g) || []).length - crlfCount;
37
+
38
+ return crlfCount > lfCount ? '\r\n' : '\n';
39
+ }
40
+
41
+ function restoreLineEndings(text, lineEnding) {
42
+ return lineEnding === '\r\n' ? text.replaceAll('\n', '\r\n') : text;
43
+ }
44
+
45
+ function getContentHashState(content, hashes) {
46
+ const currentHash = sha256(content);
47
+ const normalizedContent = normalizeLineEndings(content);
48
+ const normalizedHash = normalizedContent === content ? currentHash : sha256(normalizedContent);
49
+
50
+ if (normalizedHash === hashes.patched) {
51
+ return { currentHash, normalizedContent, normalizedHash, status: 'patched' };
52
+ }
53
+
54
+ return { currentHash, normalizedContent, normalizedHash, status: 'needs-patch' };
55
+ }
56
+
34
57
  function splitLines(text) {
35
- return text.split('\n');
58
+ return normalizeLineEndings(text).split('\n');
36
59
  }
37
60
 
38
61
  function parsePatch(patchText) {
@@ -177,9 +200,9 @@ function patchLexical() {
177
200
  }
178
201
 
179
202
  const currentContent = fs.readFileSync(targetPath, 'utf8');
180
- const currentHash = sha256(currentContent);
203
+ const currentState = getContentHashState(currentContent, hashes);
181
204
 
182
- if (currentHash === hashes.patched) {
205
+ if (currentState.status === 'patched') {
183
206
  continue;
184
207
  }
185
208
 
@@ -189,13 +212,7 @@ function patchLexical() {
189
212
  throw new Error(`[lobe-editor] Missing patch entry for ${filename}`);
190
213
  }
191
214
 
192
- if (currentHash !== hashes.original) {
193
- throw new Error(
194
- `[lobe-editor] Refuse to patch ${filename}: unknown content hash ${currentHash}.`,
195
- );
196
- }
197
-
198
- const patchedContent = applyPatchToContent(currentContent, filePatch);
215
+ const patchedContent = applyPatchToContent(currentState.normalizedContent, filePatch);
199
216
  const patchedHash = sha256(patchedContent);
200
217
 
201
218
  if (patchedHash !== hashes.patched) {
@@ -204,7 +221,10 @@ function patchLexical() {
204
221
  );
205
222
  }
206
223
 
207
- fs.writeFileSync(targetPath, patchedContent);
224
+ fs.writeFileSync(
225
+ targetPath,
226
+ restoreLineEndings(patchedContent, detectLineEnding(currentContent)),
227
+ );
208
228
  patchedFiles.push(filename);
209
229
  }
210
230