@lobehub/editor 4.15.0 → 4.15.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/es/headless.d.ts CHANGED
@@ -488,6 +488,25 @@ declare const LITEXML_MODIFY_COMMAND: _$lexical.LexicalCommand<({
488
488
  litexml: string | string[];
489
489
  })[]>;
490
490
  //#endregion
491
+ //#region src/headless/extract-media-from-editor-state.d.ts
492
+ interface ImageListItem {
493
+ alt: string;
494
+ id: string;
495
+ url: string;
496
+ }
497
+ interface FileListItem {
498
+ fileType: string;
499
+ id: string;
500
+ name: string;
501
+ size: number;
502
+ url: string;
503
+ }
504
+ interface MediaLists {
505
+ fileList: FileListItem[];
506
+ imageList: ImageListItem[];
507
+ }
508
+ declare const extractMediaFromEditorState: (state: SerializedEditorState | null | undefined) => MediaLists;
509
+ //#endregion
491
510
  //#region src/headless/index.d.ts
492
511
  type HeadlessDocumentType = 'json' | 'litexml' | 'markdown' | (string & object);
493
512
  interface HeadlessEditorHydrationInput {
@@ -551,4 +570,4 @@ declare class HeadlessEditor {
551
570
  }
552
571
  declare function createHeadlessEditor(options?: HeadlessEditorOptions): HeadlessEditor;
553
572
  //#endregion
554
- export { DEFAULT_HEADLESS_EDITOR_PLUGINS, HeadlessDocumentType, HeadlessEditor, HeadlessEditorExport, HeadlessEditorExportOptions, HeadlessEditorHydrationInput, HeadlessEditorOptions, HeadlessLiteXMLBatchOperation, HeadlessLiteXMLInsertOperation, HeadlessLiteXMLOperation, HeadlessLiteXMLRemoveOperation, HeadlessLiteXMLReplaceOperation, createHeadlessEditor };
573
+ export { DEFAULT_HEADLESS_EDITOR_PLUGINS, type FileListItem, HeadlessDocumentType, HeadlessEditor, HeadlessEditorExport, HeadlessEditorExportOptions, HeadlessEditorHydrationInput, HeadlessEditorOptions, HeadlessLiteXMLBatchOperation, HeadlessLiteXMLInsertOperation, HeadlessLiteXMLOperation, HeadlessLiteXMLRemoveOperation, HeadlessLiteXMLReplaceOperation, type ImageListItem, type MediaLists, createHeadlessEditor, extractMediaFromEditorState };
package/es/headless.js CHANGED
@@ -26840,6 +26840,54 @@ const HeadlessCodeblockPlugin = class extends KernelPlugin {
26840
26840
  }
26841
26841
  };
26842
26842
  //#endregion
26843
+ //#region src/headless/extract-media-from-editor-state.ts
26844
+ const IMAGE_TYPES = new Set(["image", "block-image"]);
26845
+ const FILE_TYPE = "file";
26846
+ const generateId = () => {
26847
+ if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
26848
+ return `id-${Math.random().toString(36).slice(2)}-${Date.now().toString(36)}`;
26849
+ };
26850
+ const inferFileType = (name) => {
26851
+ const dotIndex = name.lastIndexOf(".");
26852
+ if (dotIndex < 0 || dotIndex === name.length - 1) return "unknown";
26853
+ return name.slice(dotIndex + 1).toLowerCase() || "unknown";
26854
+ };
26855
+ const extractMediaFromEditorState = (state) => {
26856
+ const imageList = [];
26857
+ const fileList = [];
26858
+ const visit = (node) => {
26859
+ const type = node.type;
26860
+ if (IMAGE_TYPES.has(type)) {
26861
+ if (node.status === "uploaded" && typeof node.src === "string" && node.src) imageList.push({
26862
+ alt: typeof node.altText === "string" ? node.altText : "",
26863
+ id: generateId(),
26864
+ url: node.src
26865
+ });
26866
+ return;
26867
+ }
26868
+ if (type === FILE_TYPE) {
26869
+ if (node.status === "uploaded" && typeof node.fileUrl === "string" && node.fileUrl) {
26870
+ const name = typeof node.name === "string" ? node.name : "unknown";
26871
+ fileList.push({
26872
+ fileType: inferFileType(name),
26873
+ id: generateId(),
26874
+ name,
26875
+ size: typeof node.size === "number" ? node.size : 0,
26876
+ url: node.fileUrl
26877
+ });
26878
+ }
26879
+ return;
26880
+ }
26881
+ if (Array.isArray(node.children)) for (const child of node.children) visit(child);
26882
+ };
26883
+ const root = state?.root;
26884
+ if (root && Array.isArray(root.children)) for (const child of root.children) visit(child);
26885
+ return {
26886
+ fileList,
26887
+ imageList
26888
+ };
26889
+ };
26890
+ //#endregion
26843
26891
  //#region src/headless/index.ts
26844
26892
  const getNumericId = (id) => {
26845
26893
  if (typeof id !== "number" && typeof id !== "string") return null;
@@ -27015,4 +27063,4 @@ function createHeadlessEditor(options) {
27015
27063
  return new HeadlessEditor(options);
27016
27064
  }
27017
27065
  //#endregion
27018
- export { DEFAULT_HEADLESS_EDITOR_PLUGINS, HeadlessEditor, createHeadlessEditor };
27066
+ export { DEFAULT_HEADLESS_EDITOR_PLUGINS, HeadlessEditor, createHeadlessEditor, extractMediaFromEditorState };
package/es/index.d.ts CHANGED
@@ -277,6 +277,25 @@ declare const LITEXML_INSERT_COMMAND: _$lexical.LexicalCommand<{
277
277
  litexml: string;
278
278
  }>;
279
279
  //#endregion
280
+ //#region src/headless/extract-media-from-editor-state.d.ts
281
+ interface ImageListItem {
282
+ alt: string;
283
+ id: string;
284
+ url: string;
285
+ }
286
+ interface FileListItem {
287
+ fileType: string;
288
+ id: string;
289
+ name: string;
290
+ size: number;
291
+ url: string;
292
+ }
293
+ interface MediaLists {
294
+ fileList: FileListItem[];
295
+ imageList: ImageListItem[];
296
+ }
297
+ declare const extractMediaFromEditorState: (state: SerializedEditorState | null | undefined) => MediaLists;
298
+ //#endregion
280
299
  //#region src/headless/index.d.ts
281
300
  type HeadlessDocumentType = 'json' | 'litexml' | 'markdown' | (string & object);
282
301
  interface HeadlessEditorHydrationInput {
@@ -1749,25 +1768,6 @@ interface IMarkdownShortCutService {
1749
1768
  }
1750
1769
  declare const IMarkdownShortCutService: IServiceID<IMarkdownShortCutService>;
1751
1770
  //#endregion
1752
- //#region src/utils/extract-media-from-editor-state.d.ts
1753
- interface ImageListItem {
1754
- alt: string;
1755
- id: string;
1756
- url: string;
1757
- }
1758
- interface FileListItem {
1759
- fileType: string;
1760
- id: string;
1761
- name: string;
1762
- size: number;
1763
- url: string;
1764
- }
1765
- interface MediaLists {
1766
- fileList: FileListItem[];
1767
- imageList: ImageListItem[];
1768
- }
1769
- declare const extractMediaFromEditorState: (state: SerializedEditorState | null | undefined) => MediaLists;
1770
- //#endregion
1771
1771
  //#region src/plugins/content-blocks/types.d.ts
1772
1772
  interface TextContentBlock {
1773
1773
  text: string;
package/es/index.js CHANGED
@@ -2097,6 +2097,54 @@ const HeadlessCodeblockPlugin = class extends KernelPlugin {
2097
2097
  }
2098
2098
  };
2099
2099
  //#endregion
2100
+ //#region src/headless/extract-media-from-editor-state.ts
2101
+ const IMAGE_TYPES = new Set(["image", "block-image"]);
2102
+ const FILE_TYPE = "file";
2103
+ const generateId$1 = () => {
2104
+ if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
2105
+ return `id-${Math.random().toString(36).slice(2)}-${Date.now().toString(36)}`;
2106
+ };
2107
+ const inferFileType$1 = (name) => {
2108
+ const dotIndex = name.lastIndexOf(".");
2109
+ if (dotIndex < 0 || dotIndex === name.length - 1) return "unknown";
2110
+ return name.slice(dotIndex + 1).toLowerCase() || "unknown";
2111
+ };
2112
+ const extractMediaFromEditorState = (state) => {
2113
+ const imageList = [];
2114
+ const fileList = [];
2115
+ const visit = (node) => {
2116
+ const type = node.type;
2117
+ if (IMAGE_TYPES.has(type)) {
2118
+ if (node.status === "uploaded" && typeof node.src === "string" && node.src) imageList.push({
2119
+ alt: typeof node.altText === "string" ? node.altText : "",
2120
+ id: generateId$1(),
2121
+ url: node.src
2122
+ });
2123
+ return;
2124
+ }
2125
+ if (type === FILE_TYPE) {
2126
+ if (node.status === "uploaded" && typeof node.fileUrl === "string" && node.fileUrl) {
2127
+ const name = typeof node.name === "string" ? node.name : "unknown";
2128
+ fileList.push({
2129
+ fileType: inferFileType$1(name),
2130
+ id: generateId$1(),
2131
+ name,
2132
+ size: typeof node.size === "number" ? node.size : 0,
2133
+ url: node.fileUrl
2134
+ });
2135
+ }
2136
+ return;
2137
+ }
2138
+ if (Array.isArray(node.children)) for (const child of node.children) visit(child);
2139
+ };
2140
+ const root = state?.root;
2141
+ if (root && Array.isArray(root.children)) for (const child of root.children) visit(child);
2142
+ return {
2143
+ fileList,
2144
+ imageList
2145
+ };
2146
+ };
2147
+ //#endregion
2100
2148
  //#region src/headless/index.ts
2101
2149
  const getNumericId = (id) => {
2102
2150
  if (typeof id !== "number" && typeof id !== "string") return null;
@@ -4534,11 +4582,11 @@ const ContentBlocksPlugin = class extends KernelPlugin {
4534
4582
  };
4535
4583
  //#endregion
4536
4584
  //#region src/plugins/content-blocks/utils/extract-media-lists.ts
4537
- const generateId$1 = () => {
4585
+ const generateId = () => {
4538
4586
  if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
4539
4587
  return `id-${Math.random().toString(36).slice(2)}-${Date.now().toString(36)}`;
4540
4588
  };
4541
- const inferFileType$1 = (name) => {
4589
+ const inferFileType = (name) => {
4542
4590
  const dotIndex = name.lastIndexOf(".");
4543
4591
  if (dotIndex < 0 || dotIndex === name.length - 1) return "unknown";
4544
4592
  return name.slice(dotIndex + 1).toLowerCase() || "unknown";
@@ -4548,12 +4596,12 @@ const extractMediaLists = (blocks) => {
4548
4596
  const fileList = [];
4549
4597
  for (const block of blocks) if (block.type === "image") imageList.push({
4550
4598
  alt: block.alt,
4551
- id: generateId$1(),
4599
+ id: generateId(),
4552
4600
  url: block.url
4553
4601
  });
4554
4602
  else if (block.type === "file") fileList.push({
4555
- fileType: inferFileType$1(block.name),
4556
- id: generateId$1(),
4603
+ fileType: inferFileType(block.name),
4604
+ id: generateId(),
4557
4605
  name: block.name,
4558
4606
  size: typeof block.size === "number" ? block.size : 0,
4559
4607
  url: block.url
@@ -8406,54 +8454,6 @@ const ReactVirtualBlockPlugin = () => {
8406
8454
  };
8407
8455
  ReactVirtualBlockPlugin.displayName = "ReactVirtualBlockPlugin";
8408
8456
  //#endregion
8409
- //#region src/utils/extract-media-from-editor-state.ts
8410
- const IMAGE_TYPES = new Set(["image", "block-image"]);
8411
- const FILE_TYPE = "file";
8412
- const generateId = () => {
8413
- if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
8414
- return `id-${Math.random().toString(36).slice(2)}-${Date.now().toString(36)}`;
8415
- };
8416
- const inferFileType = (name) => {
8417
- const dotIndex = name.lastIndexOf(".");
8418
- if (dotIndex < 0 || dotIndex === name.length - 1) return "unknown";
8419
- return name.slice(dotIndex + 1).toLowerCase() || "unknown";
8420
- };
8421
- const extractMediaFromEditorState = (state) => {
8422
- const imageList = [];
8423
- const fileList = [];
8424
- const visit = (node) => {
8425
- const type = node.type;
8426
- if (IMAGE_TYPES.has(type)) {
8427
- if (node.status === "uploaded" && typeof node.src === "string" && node.src) imageList.push({
8428
- alt: typeof node.altText === "string" ? node.altText : "",
8429
- id: generateId(),
8430
- url: node.src
8431
- });
8432
- return;
8433
- }
8434
- if (type === FILE_TYPE) {
8435
- if (node.status === "uploaded" && typeof node.fileUrl === "string" && node.fileUrl) {
8436
- const name = typeof node.name === "string" ? node.name : "unknown";
8437
- fileList.push({
8438
- fileType: inferFileType(name),
8439
- id: generateId(),
8440
- name,
8441
- size: typeof node.size === "number" ? node.size : 0,
8442
- url: node.fileUrl
8443
- });
8444
- }
8445
- return;
8446
- }
8447
- if (Array.isArray(node.children)) for (const child of node.children) visit(child);
8448
- };
8449
- const root = state?.root;
8450
- if (root && Array.isArray(root.children)) for (const child of root.children) visit(child);
8451
- return {
8452
- fileList,
8453
- imageList
8454
- };
8455
- };
8456
- //#endregion
8457
8457
  //#region src/utils/scrollIntoView.ts
8458
8458
  init_kernel();
8459
8459
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "4.15.0",
3
+ "version": "4.15.1",
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",