@lobehub/editor 4.24.1 → 4.25.0

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.
Files changed (143) hide show
  1. package/es/codemirror/style.js +42 -0
  2. package/es/editor-kernel/kernel.js +3 -0
  3. package/es/editor-kernel/react/useDecorators.js +2 -4
  4. package/es/headless/collapsible-plugin.js +74 -0
  5. package/es/headless/index.js +2 -0
  6. package/es/headless.d.ts +18 -0
  7. package/es/headless.js +2479 -71
  8. package/es/index.d.ts +26 -3
  9. package/es/index.js +17 -2
  10. package/es/locale/index.d.ts +14 -0
  11. package/es/locale/index.js +14 -0
  12. package/es/plugins/block/command/index.js +24 -0
  13. package/es/plugins/block/plugin/index.js +7 -5
  14. package/es/plugins/block/react/ReactBlockPlugin.js +43 -1
  15. package/es/plugins/block/react/core/menu-position.js +20 -0
  16. package/es/plugins/block/react/drag/drag-session.js +3 -2
  17. package/es/plugins/block/react/drag/drag-utils.js +13 -1
  18. package/es/plugins/codemirror-block/index.d.ts +2 -1
  19. package/es/plugins/codemirror-block/plugin/index.js +2 -0
  20. package/es/plugins/codemirror-block/react/CodemirrorNode.js +95 -5
  21. package/es/plugins/codemirror-block/react/useCodemirrorEditLock.js +33 -0
  22. package/es/plugins/codemirror-block/service/index.d.ts +40 -0
  23. package/es/plugins/codemirror-block/service/index.js +59 -0
  24. package/es/plugins/collapsible/command/index.d.ts +17 -0
  25. package/es/plugins/collapsible/command/index.js +72 -0
  26. package/es/plugins/collapsible/index.d.ts +7 -0
  27. package/es/plugins/collapsible/node/CollapsibleNode.d.ts +30 -0
  28. package/es/plugins/collapsible/node/CollapsibleNode.js +138 -0
  29. package/es/plugins/collapsible/plugin/index.d.ts +11 -0
  30. package/es/plugins/collapsible/plugin/index.js +535 -0
  31. package/es/plugins/collapsible/react/ReactCollapsiblePlugin.d.ts +6 -0
  32. package/es/plugins/collapsible/react/ReactCollapsiblePlugin.js +19 -0
  33. package/es/plugins/collapsible/react/index.d.ts +3 -0
  34. package/es/plugins/collapsible/react/style.js +67 -0
  35. package/es/plugins/collapsible/react/type.d.ts +6 -0
  36. package/es/plugins/common/plugin/index.js +3 -2
  37. package/es/plugins/common/plugin/progressive-select-all.js +81 -0
  38. package/es/plugins/common/plugin/register.js +73 -4
  39. package/es/plugins/link/command/index.js +26 -3
  40. package/es/plugins/link/conversion/index.js +237 -0
  41. package/es/plugins/link/index.d.ts +5 -3
  42. package/es/plugins/link/node/LinkBlockCardNode.d.ts +16 -0
  43. package/es/plugins/link/node/LinkBlockCardNode.js +66 -0
  44. package/es/plugins/link/node/LinkCardNode.d.ts +42 -0
  45. package/es/plugins/link/node/LinkCardNode.js +161 -0
  46. package/es/plugins/link/node/LinkIframeNode.d.ts +33 -0
  47. package/es/plugins/link/node/LinkIframeNode.js +131 -0
  48. package/es/plugins/link/node/LinkNode.d.ts +48 -2
  49. package/es/plugins/link/node/LinkNode.js +14 -6
  50. package/es/plugins/link/node/SchemaNode.d.ts +36 -0
  51. package/es/plugins/link/node/SchemaNode.js +149 -0
  52. package/es/plugins/link/normalization/index.d.ts +7 -0
  53. package/es/plugins/link/normalization/index.js +38 -0
  54. package/es/plugins/link/plugin/index.d.ts +26 -1
  55. package/es/plugins/link/plugin/index.js +124 -4
  56. package/es/plugins/link/react/ReactLinkPlugin.js +165 -7
  57. package/es/plugins/link/react/components/LinkCard.js +235 -0
  58. package/es/plugins/link/react/components/LinkEdit.js +93 -14
  59. package/es/plugins/link/react/components/LinkIframe.js +128 -0
  60. package/es/plugins/link/react/components/LinkToolbar.js +440 -111
  61. package/es/plugins/link/react/components/SchemaLink.js +49 -0
  62. package/es/plugins/link/react/index.d.ts +2 -2
  63. package/es/plugins/link/react/renderer-registry.d.ts +81 -0
  64. package/es/plugins/link/react/renderer-registry.js +80 -0
  65. package/es/plugins/link/react/style.js +63 -1
  66. package/es/plugins/link/react/type.d.ts +24 -1
  67. package/es/plugins/link/service/i-link-service.d.ts +156 -1
  68. package/es/plugins/link/service/i-link-service.js +258 -5
  69. package/es/plugins/list/plugin/index.js +9 -2
  70. package/es/plugins/litexml/command/diffCommand.js +94 -14
  71. package/es/plugins/litexml/command/index.js +187 -6
  72. package/es/plugins/litexml/diff-validation.js +237 -0
  73. package/es/plugins/litexml/node/DiffContentNode.js +67 -0
  74. package/es/plugins/litexml/node/DiffNode.d.ts +1 -1
  75. package/es/plugins/litexml/node/DiffNode.js +5 -2
  76. package/es/plugins/litexml/node/TableCellDiffNode.js +77 -0
  77. package/es/plugins/litexml/node/TableRowDiffNode.js +73 -0
  78. package/es/plugins/litexml/plugin/index.d.ts +2 -0
  79. package/es/plugins/litexml/plugin/index.js +62 -9
  80. package/es/plugins/litexml/react/DiffNodeToolbar/index.js +10 -12
  81. package/es/plugins/litexml/react/TableRowDiffToolbar.js +123 -0
  82. package/es/plugins/litexml/react/hooks/useHasDiffNode.js +5 -2
  83. package/es/plugins/litexml/react/index.js +6 -2
  84. package/es/plugins/litexml/react/style.js +18 -5
  85. package/es/plugins/litexml/table-cell-diff.js +153 -0
  86. package/es/plugins/litexml/table-row-diff.js +82 -0
  87. package/es/plugins/markdown/data-source/markdown/parse.js +25 -1
  88. package/es/plugins/markdown/plugin/index.js +5 -3
  89. package/es/plugins/slash/react/ReactSlashPlugin.js +22 -43
  90. package/es/plugins/slash/react/components/DefaultSlashMenu.js +76 -16
  91. package/es/plugins/slash/react/menu-utils.js +84 -0
  92. package/es/plugins/slash/service/i-slash-service.d.ts +3 -0
  93. package/es/plugins/table/plugin/index.js +4 -1
  94. package/es/plugins/table/plugin/single-cell-paste.js +79 -0
  95. package/es/plugins/table/react/TableController/hooks.js +7 -4
  96. package/es/plugins/table/react/hooks.js +2 -2
  97. package/es/plugins/table/react/index.js +2 -0
  98. package/es/plugins/table/react/style.js +15 -5
  99. package/es/plugins/table/react/useScrollFocusedTableCellIntoView.js +46 -0
  100. package/es/plugins/toc/index.d.ts +10 -0
  101. package/es/plugins/toc/plugin/index.d.ts +8 -0
  102. package/es/plugins/toc/plugin/index.js +56 -0
  103. package/es/plugins/toc/react/ReactTocPlugin.d.ts +6 -0
  104. package/es/plugins/toc/react/ReactTocPlugin.js +36 -0
  105. package/es/plugins/toc/react/getNearestScrollContainer.d.ts +6 -0
  106. package/es/plugins/toc/react/getNearestScrollContainer.js +18 -0
  107. package/es/plugins/toc/react/hooks/useActiveHeading.js +59 -0
  108. package/es/plugins/toc/react/hooks/useTocItems.js +50 -0
  109. package/es/plugins/toc/react/index.d.ts +5 -0
  110. package/es/plugins/toc/react/type.d.ts +30 -0
  111. package/es/plugins/toc/react/useToc.d.ts +5 -0
  112. package/es/plugins/toc/react/useToc.js +41 -0
  113. package/es/plugins/toc/service/i-toc-service.d.ts +39 -0
  114. package/es/plugins/toc/service/i-toc-service.js +125 -0
  115. package/es/plugins/toc/service/index.d.ts +3 -0
  116. package/es/plugins/toc/types.d.ts +23 -0
  117. package/es/plugins/toc/utils/index.d.ts +6 -0
  118. package/es/plugins/toc/utils/index.js +30 -0
  119. package/es/plugins/toolbar/react/index.js +26 -12
  120. package/es/plugins/toolbar/react/style.js +3 -2
  121. package/es/plugins/virtual-block/plugin/register.js +34 -12
  122. package/es/plugins/yjs/index.d.ts +6 -0
  123. package/es/plugins/yjs/plugin/index.d.ts +7 -0
  124. package/es/plugins/yjs/plugin/index.js +191 -0
  125. package/es/plugins/yjs/plugin/types.d.ts +16 -0
  126. package/es/plugins/yjs/plugin/utils/awareness.js +9 -0
  127. package/es/plugins/yjs/plugin/utils/editor-state.js +47 -0
  128. package/es/plugins/yjs/plugin/utils/history.js +31 -0
  129. package/es/plugins/yjs/plugin/utils/node-properties.js +39 -0
  130. package/es/plugins/yjs/plugin/utils/sync.js +24 -0
  131. package/es/plugins/yjs/react/codemirrorEditLockProvider.js +59 -0
  132. package/es/plugins/yjs/react/index.d.ts +23 -0
  133. package/es/plugins/yjs/react/index.js +200 -0
  134. package/es/plugins/yjs/service/index.d.ts +47 -0
  135. package/es/plugins/yjs/service/index.js +84 -0
  136. package/es/plugins/yjs/websocket-provider.d.ts +78 -0
  137. package/es/plugins/yjs/websocket-provider.js +263 -0
  138. package/es/renderer/LexicalRenderer.js +9 -2
  139. package/es/types/kernel.d.ts +4 -0
  140. package/es/utils/updatePosition.js +5 -2
  141. package/package.json +3 -1
  142. package/patches/@lexical__yjs@0.42.0.patch +42 -0
  143. package/scripts/postinstall-lexical-patch.cjs +62 -36
@@ -0,0 +1,81 @@
1
+ import { LinkCardNode } from "../node/LinkCardNode.js";
2
+ import { LinkIframeNode } from "../node/LinkIframeNode.js";
3
+ import { LinkNode } from "../node/LinkNode.js";
4
+ import { SchemaNode } from "../node/SchemaNode.js";
5
+ import { ParsedSchemaUrl, SchemaRule } from "../service/i-link-service.js";
6
+ import { FC, MouseEventHandler, ReactEventHandler, ReactNode } from "react";
7
+ import EventEmitter from "eventemitter3";
8
+ import { LexicalEditor } from "lexical";
9
+ //#region src/plugins/link/react/renderer-registry.d.ts
10
+ interface LinkCardRendererProps {
11
+ description: string;
12
+ editor: LexicalEditor;
13
+ icon: string;
14
+ isLoading: boolean;
15
+ isSelected: boolean;
16
+ layout: 'block' | 'inline';
17
+ node: LinkCardNode;
18
+ onClickCapture: MouseEventHandler<HTMLElement>;
19
+ onMouseDownCapture: MouseEventHandler<HTMLElement>;
20
+ openTarget: null | string;
21
+ title: string;
22
+ url: string;
23
+ }
24
+ interface LinkIframeRendererProps {
25
+ editor: LexicalEditor;
26
+ isEditable: boolean;
27
+ isLoading: boolean;
28
+ isSelected: boolean;
29
+ node: LinkIframeNode;
30
+ onLoad: ReactEventHandler<HTMLIFrameElement>;
31
+ onMouseDownCapture: MouseEventHandler<HTMLElement>;
32
+ src: string;
33
+ title: string;
34
+ url: string;
35
+ }
36
+ interface SchemaRendererProps {
37
+ editor: LexicalEditor;
38
+ node: SchemaNode;
39
+ payload: unknown;
40
+ schema: ParsedSchemaUrl | null;
41
+ schemaType: string;
42
+ title: string;
43
+ url: string;
44
+ }
45
+ type LinkCardRenderer = (props: LinkCardRendererProps) => ReactNode;
46
+ type LinkIframeRenderer = (props: LinkIframeRendererProps) => ReactNode;
47
+ type SchemaRenderer = (props: SchemaRendererProps) => ReactNode;
48
+ interface SchemaLinkRendererProps {
49
+ editor: LexicalEditor;
50
+ node: LinkNode;
51
+ rel: null | string;
52
+ schema: ParsedSchemaUrl | null;
53
+ target: null | string;
54
+ text: string;
55
+ title: null | string;
56
+ url: string;
57
+ }
58
+ type SchemaLinkRenderer = (props: SchemaLinkRendererProps) => ReactNode;
59
+ /** @deprecated Use schemaRules/renderSchema with SchemaNode instead. */
60
+ interface SchemaLinkRendererConfig {
61
+ protocol: string;
62
+ render: SchemaLinkRenderer;
63
+ }
64
+ interface ReactSchemaRule extends SchemaRule {
65
+ render?: SchemaRenderer;
66
+ }
67
+ interface LinkToolbarAction {
68
+ icon?: FC<any>;
69
+ key: string;
70
+ label: string;
71
+ onClick: (context: {
72
+ editor: LexicalEditor;
73
+ node: LinkNode | LinkCardNode | LinkIframeNode | SchemaNode;
74
+ }) => void;
75
+ visible?: (context: {
76
+ editor: LexicalEditor;
77
+ node: LinkNode | LinkCardNode | LinkIframeNode | SchemaNode;
78
+ }) => boolean;
79
+ }
80
+ //#endregion
81
+ export { LinkCardRenderer, LinkCardRendererProps, LinkIframeRenderer, LinkIframeRendererProps, LinkToolbarAction, ReactSchemaRule, SchemaLinkRenderer, SchemaLinkRendererConfig, SchemaLinkRendererProps, SchemaRenderer, SchemaRendererProps };
@@ -0,0 +1,80 @@
1
+ import { normalizeProtocol } from "../service/i-link-service.js";
2
+ import EventEmitter from "eventemitter3";
3
+ //#region src/plugins/link/react/renderer-registry.ts
4
+ var LinkReactRendererRegistry = class extends EventEmitter {
5
+ constructor(..._args) {
6
+ super(..._args);
7
+ this.schemaLinkRenderers = /* @__PURE__ */ new Map();
8
+ this.schemaRenderers = /* @__PURE__ */ new Map();
9
+ }
10
+ update(config) {
11
+ this.renderCard = config?.renderLinkCard;
12
+ this.renderIframe = config?.renderLinkIframe;
13
+ this.renderSchema = config?.renderSchema;
14
+ this.schemaRenderers = config?.schemaRenderers || /* @__PURE__ */ new Map();
15
+ this.schemaLinkRenderers = new Map((config?.schemaLinkRenderers || []).map(({ protocol, render }) => [normalizeProtocol(protocol), render]));
16
+ this.emit("change");
17
+ }
18
+ renderCardNode(props) {
19
+ return this.renderCard?.(props) || null;
20
+ }
21
+ renderIframeNode(props) {
22
+ return this.renderIframe?.(props) || null;
23
+ }
24
+ renderSchemaNode(props) {
25
+ return this.schemaRenderers.get(props.schemaType)?.(props) || this.renderSchema?.(props) || null;
26
+ }
27
+ renderLegacySchemaLink(props) {
28
+ const renderer = this.getSchemaLinkRenderer(props.url);
29
+ if (!renderer) return null;
30
+ const legacy = getLegacyLinkPayload(props.payload);
31
+ return renderer({
32
+ editor: props.editor,
33
+ node: props.node,
34
+ rel: legacy.rel,
35
+ schema: props.schema,
36
+ target: legacy.target,
37
+ text: legacy.text || props.title,
38
+ title: legacy.title || props.title,
39
+ url: props.url
40
+ });
41
+ }
42
+ getSchemaLinkRenderer(url) {
43
+ try {
44
+ const { protocol } = new URL(url);
45
+ return this.schemaLinkRenderers.get(protocol) || null;
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+ };
51
+ function splitReactSchemaRules(rules) {
52
+ if (!rules) return { schemaRenderers: /* @__PURE__ */ new Map() };
53
+ const schemaRenderers = /* @__PURE__ */ new Map();
54
+ return {
55
+ coreRules: rules.map(({ render, ...rule }) => {
56
+ if (render) schemaRenderers.set(rule.id, render);
57
+ return rule;
58
+ }),
59
+ schemaRenderers
60
+ };
61
+ }
62
+ function getLegacyLinkPayload(payload) {
63
+ if (payload && typeof payload === "object" && "__legacyLink" in payload) {
64
+ const legacy = payload.__legacyLink;
65
+ return {
66
+ rel: typeof legacy?.rel === "string" ? legacy.rel : null,
67
+ target: typeof legacy?.target === "string" ? legacy.target : null,
68
+ text: typeof legacy?.text === "string" ? legacy.text : "",
69
+ title: typeof legacy?.title === "string" ? legacy.title : null
70
+ };
71
+ }
72
+ return {
73
+ rel: null,
74
+ target: null,
75
+ text: "",
76
+ title: null
77
+ };
78
+ }
79
+ //#endregion
80
+ export { LinkReactRendererRegistry, splitReactSchemaRules };
@@ -15,6 +15,31 @@ const styles = createStaticStyles(({ css, cssVar }) => {
15
15
  margin-inline: 0;
16
16
  padding: 2px;
17
17
  border: none;
18
+ `,
19
+ linkCard: css`
20
+ user-select: none;
21
+
22
+ display: inline-block;
23
+
24
+ /* Inline decorator wrappers otherwise use the untruncated title as
25
+ their intrinsic width even when the rendered card is capped at 320px. */
26
+ max-width: min(320px, 100%);
27
+ border-radius: 5px;
28
+
29
+ line-height: 1;
30
+ vertical-align: baseline;
31
+
32
+ &[data-link-card-layout='block'] {
33
+ display: block;
34
+ max-width: 100%;
35
+ margin-block: 8px;
36
+ }
37
+
38
+ &.hover,
39
+ &.selected {
40
+ outline: 2px solid ${cssVar.colorPrimaryBorder};
41
+ outline-offset: 1px;
42
+ }
18
43
  `,
19
44
  linkEdit: cx(position, css`
20
45
  min-width: 320px;
@@ -24,10 +49,47 @@ const styles = createStaticStyles(({ css, cssVar }) => {
24
49
  linkEditFooter: css`
25
50
  border-block-start: 1px solid ${cssVar.colorBorderSecondary};
26
51
  background: ${cssVar.colorFillQuaternary};
52
+ `,
53
+ linkIframe: css`
54
+ margin-block: 8px;
27
55
  `,
28
56
  linkToolbar: cx(position, css`
57
+ position: fixed;
58
+
59
+ overflow: hidden;
60
+
61
+ padding-block: 6px;
62
+ padding-inline: 10px;
63
+ border: 1px solid ${cssVar.colorBorder};
64
+ border-radius: 6px;
65
+
29
66
  background: ${cssVar.colorBgElevated};
30
- `)
67
+ box-shadow: ${cssVar.boxShadowSecondary};
68
+ `),
69
+ popoverActionItem: css`
70
+ cursor: pointer;
71
+
72
+ display: flex;
73
+ align-items: center;
74
+ justify-content: center;
75
+
76
+ width: 28px;
77
+ height: 28px;
78
+ padding: 0;
79
+ border: 0;
80
+ border-radius: ${cssVar.borderRadius}px;
81
+
82
+ color: inherit;
83
+
84
+ background: transparent;
85
+
86
+ &:hover {
87
+ background: ${cssVar.colorFillQuaternary};
88
+ }
89
+ `,
90
+ schemaLink: css`
91
+ margin-block: 8px;
92
+ `
31
93
  };
32
94
  });
33
95
  //#endregion
@@ -1,13 +1,36 @@
1
1
  import { LinkAttributes } from "../node/LinkNode.js";
2
+ import { LinkEmbedRule, LinkLabels } from "../service/i-link-service.js";
3
+ import { LinkCardRenderer, LinkIframeRenderer, LinkToolbarAction, ReactSchemaRule, SchemaLinkRendererConfig, SchemaRenderer } from "./renderer-registry.js";
2
4
  //#region src/plugins/link/react/type.d.ts
5
+ type ReactLinkDefaultToolbarItemKey = 'copy' | 'edit' | 'open' | 'unlink';
6
+ type ReactLinkDefaultToolbarItems = boolean | Partial<Record<ReactLinkDefaultToolbarItemKey, boolean>>;
3
7
  interface ReactLinkPluginProps {
8
+ allowedProtocols?: string[];
9
+ /** Registration-time option. Remount ReactLinkPlugin to apply changes. */
4
10
  attributes?: LinkAttributes;
5
11
  className?: string;
12
+ defaultToolbarItems?: ReactLinkDefaultToolbarItems;
13
+ /** Registration-time option. Remount ReactLinkPlugin to apply changes. */
6
14
  enableHotkey?: boolean;
15
+ labels?: Partial<LinkLabels>;
16
+ linkEmbedRules?: LinkEmbedRule[];
17
+ /** Registration-time normalization strategy. Defaults to true for legacy compatibility. */
18
+ normalizeSchemaLinks?: boolean;
19
+ renderLinkCard?: LinkCardRenderer;
20
+ renderLinkIframe?: LinkIframeRenderer;
21
+ renderSchema?: SchemaRenderer;
22
+ schemaLinkRenderers?: SchemaLinkRendererConfig[];
23
+ schemaRules?: ReactSchemaRule[];
24
+ /** Registration-time option. Remount ReactLinkPlugin to apply changes. */
7
25
  theme?: {
8
26
  link?: string;
27
+ linkCard?: string;
28
+ linkIframe?: string;
29
+ schemaLink?: string;
9
30
  };
31
+ toolbarActions?: LinkToolbarAction[];
32
+ /** Registration-time option. Remount ReactLinkPlugin to apply changes. */
10
33
  validateUrl?: (url: string) => boolean;
11
34
  }
12
35
  //#endregion
13
- export { ReactLinkPluginProps };
36
+ export { ReactLinkDefaultToolbarItemKey, ReactLinkDefaultToolbarItems, ReactLinkPluginProps };
@@ -1,10 +1,165 @@
1
1
  import { IServiceID } from "../../../types/kernel.js";
2
2
  import "../../../types/index.js";
3
+ import { LinkCardNode } from "../node/LinkCardNode.js";
4
+ import { LinkIframeNode } from "../node/LinkIframeNode.js";
5
+ import { LinkNode } from "../node/LinkNode.js";
6
+ import { SchemaNode } from "../node/SchemaNode.js";
7
+ import { LinkBlockCardNode } from "../node/LinkBlockCardNode.js";
3
8
  import EventEmitter from "eventemitter3";
9
+ import { LexicalEditor, LexicalNode } from "lexical";
4
10
  //#region src/plugins/link/service/i-link-service.d.ts
11
+ interface ParsedSchemaUrl {
12
+ hash: string;
13
+ host: string;
14
+ params: Record<string, string>;
15
+ pathname: string;
16
+ protocol: string;
17
+ raw: string;
18
+ search: string;
19
+ }
20
+ interface LinkRuleContext {
21
+ editor: LexicalEditor;
22
+ text: string;
23
+ title: string;
24
+ }
25
+ interface LinkCardPayload {
26
+ description?: string;
27
+ icon?: string;
28
+ openTarget?: null | string;
29
+ title?: string;
30
+ url?: string;
31
+ }
32
+ interface LinkIframePayload {
33
+ src?: string;
34
+ title?: string;
35
+ url?: string;
36
+ }
37
+ interface SchemaPayload {
38
+ payload?: unknown;
39
+ schemaType?: string;
40
+ title?: string;
41
+ url?: string;
42
+ }
43
+ interface LinkEmbedRule {
44
+ allowBlockCard?: boolean;
45
+ allowCard?: boolean;
46
+ allowIframe?: boolean;
47
+ getCardPayload?: (url: string, context: LinkRuleContext) => LinkCardPayload | Promise<LinkCardPayload>;
48
+ getIframePayload?: (url: string, context: LinkRuleContext) => LinkIframePayload;
49
+ id: string;
50
+ match: (url: string, context: LinkRuleContext) => boolean;
51
+ }
52
+ interface SchemaRule {
53
+ id: string;
54
+ match: (url: string, context: LinkRuleContext & {
55
+ schema: ParsedSchemaUrl | null;
56
+ }) => boolean;
57
+ parse?: (url: string, schema: ParsedSchemaUrl | null) => SchemaPayload | unknown;
58
+ }
59
+ interface LinkLabels {
60
+ convertToBlockCard: string;
61
+ convertToCard: string;
62
+ convertToIframe: string;
63
+ convertToLink: string;
64
+ convertToSchema: string;
65
+ }
66
+ type LinkToolbarNode = LinkNode | LinkCardNode | LinkBlockCardNode | LinkIframeNode | SchemaNode;
67
+ interface LinkToolbarActionContext {
68
+ editor: LexicalEditor;
69
+ node: LinkToolbarNode;
70
+ }
71
+ interface LinkToolbarAction {
72
+ icon?: unknown;
73
+ key: string;
74
+ label: string;
75
+ onClick: (context: LinkToolbarActionContext) => void;
76
+ visible?: (context: LinkToolbarActionContext) => boolean;
77
+ }
78
+ /** @deprecated Use schemaRules with SchemaNode instead. React rendering lives in the React plugin. */
79
+ interface SchemaLinkRendererConfig {
80
+ protocol: string;
81
+ }
82
+ interface LinkServiceConfig {
83
+ allowedProtocols?: string[];
84
+ labels?: Partial<LinkLabels>;
85
+ linkEmbedRules?: LinkEmbedRule[];
86
+ schemaLinkRenderers?: SchemaLinkRendererConfig[];
87
+ schemaRules?: SchemaRule[];
88
+ toolbarActions?: LinkToolbarAction[];
89
+ }
90
+ type LinkToolbarItemIcon = 'copy' | 'edit' | 'open' | 'unlink';
91
+ interface LinkToolbarRenderContext {
92
+ close: () => void;
93
+ editor: LexicalEditor;
94
+ linkDom: HTMLElement | null;
95
+ linkNode: LinkNode;
96
+ }
97
+ interface LinkToolbarItem {
98
+ icon: LinkToolbarItemIcon;
99
+ key: string;
100
+ label: string | ((context: LinkToolbarRenderContext) => string);
101
+ onClick: (context: LinkToolbarRenderContext) => void | Promise<void>;
102
+ order?: number;
103
+ when?: (context: LinkToolbarRenderContext) => boolean;
104
+ }
5
105
  interface ILinkService {
106
+ readonly enableLinkToolbar: boolean;
107
+ getAllowedProtocols(): Set<string>;
108
+ getEmbedRule(url: string, context: LinkRuleContext): LinkEmbedRule | null;
109
+ getLabels(): LinkLabels;
110
+ getSchemaRule(url: string, context: LinkRuleContext & {
111
+ schema?: ParsedSchemaUrl | null;
112
+ }): SchemaRule | null;
113
+ getToolbarActions(context: LinkToolbarActionContext): LinkToolbarAction[];
114
+ getToolbarItems(context: LinkToolbarRenderContext): LinkToolbarItem[];
115
+ hasSchemaLinkRenderer(url: string): boolean;
116
+ isCardMetadataLoading(nodeKey: string): boolean;
117
+ parseSchemaUrl(url: string): ParsedSchemaUrl | null;
118
+ registerToolbarItem(item: LinkToolbarItem): () => void;
119
+ restoreLinkToolbar(token: symbol): void;
6
120
  setLinkToolbar(enable: boolean): void;
121
+ subscribe(listener: () => void): () => void;
122
+ subscribeCardMetadata(listener: () => void): () => void;
123
+ suppressLinkToolbar(reason?: string): symbol;
124
+ updateConfig(config?: LinkServiceConfig): void;
7
125
  }
8
126
  declare const ILinkService: IServiceID<ILinkService>;
127
+ declare class LinkService extends EventEmitter<'cardMetadataChange' | 'change' | 'linkToolbarChange'> implements ILinkService {
128
+ private cardMetadataLoadingKeys;
129
+ private protocolPolicy;
130
+ private legacySchemaLinkRegistry;
131
+ private ruleRegistry;
132
+ private toolbarController;
133
+ private toolbarItems;
134
+ get enableLinkToolbar(): boolean;
135
+ getAllowedProtocols(): Set<string>;
136
+ getEmbedRule(url: string, context: LinkRuleContext): LinkEmbedRule | null;
137
+ getLabels(): LinkLabels;
138
+ hasSchemaLinkRenderer(url: string): boolean;
139
+ isCardMetadataLoading(nodeKey: string): boolean;
140
+ setCardMetadataLoading(nodeKey: string, loading: boolean): void;
141
+ getSchemaRule(url: string, context: LinkRuleContext & {
142
+ schema?: ParsedSchemaUrl | null;
143
+ }): SchemaRule | null;
144
+ getToolbarActions(context: LinkToolbarActionContext): LinkToolbarAction[];
145
+ parseSchemaUrl(url: string): ParsedSchemaUrl | null;
146
+ updateConfig(config?: LinkServiceConfig): void;
147
+ setAllowedProtocols(protocols: string[]): void;
148
+ setEmbedRules(rules?: LinkEmbedRule[]): void;
149
+ setLabels(labels?: Partial<LinkLabels>): void;
150
+ setSchemaLinkRenderers(renderers?: SchemaLinkRendererConfig[]): void;
151
+ setSchemaRules(rules?: SchemaRule[]): void;
152
+ setToolbarActions(actions?: LinkToolbarAction[]): void;
153
+ getToolbarItems(context: LinkToolbarRenderContext): LinkToolbarItem[];
154
+ registerToolbarItem(item: LinkToolbarItem): () => void;
155
+ setLinkToolbar(enable: boolean): void;
156
+ suppressLinkToolbar(reason?: string): symbol;
157
+ restoreLinkToolbar(token: symbol): void;
158
+ subscribe(listener: () => void): () => void;
159
+ subscribeCardMetadata(listener: () => void): () => void;
160
+ }
161
+ declare function normalizeProtocol(protocol: string): string;
162
+ declare function getNodeUrl(node: LexicalNode): string;
163
+ declare function getNodeTitle(node: LexicalNode): string;
9
164
  //#endregion
10
- export { ILinkService };
165
+ export { ILinkService, LinkCardPayload, LinkEmbedRule, LinkIframePayload, LinkLabels, LinkRuleContext, LinkService, LinkServiceConfig, LinkToolbarAction, LinkToolbarActionContext, LinkToolbarItem, LinkToolbarItemIcon, LinkToolbarNode, LinkToolbarRenderContext, ParsedSchemaUrl, SchemaLinkRendererConfig, SchemaPayload, SchemaRule, getNodeTitle, getNodeUrl, normalizeProtocol };