@lofcz/platejs-core 53.1.6 → 53.2.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/dist/{index-BooMghRU.d.ts → index-ClAE30YQ.d.ts} +99 -23
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -4
- package/dist/react/index.d.ts +173 -131
- package/dist/react/index.js +1016 -175
- package/dist/static/index.d.ts +1 -1
- package/dist/static/index.js +2 -2
- package/dist/{static-DAs0P1Ms.js → static-C-jR24Fx.js} +3 -3
- package/dist/{withSlate-Ck8dLhUt.js → withSlate-pfxNb3FA.js} +255 -102
- package/package.json +4 -4
package/dist/react/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ut as BaseParagraphPlugin, bt as getSlateClass, cn as getEditorPlugin$1, dt as ChunkingPlugin, ln as createSlatePlugin, m as isEditOnly, n as withSlate, nn as getPluginByType, s as SlateExtensionPlugin, st as DOMPlugin, x as NavigationFeedbackPlugin$1, xt as getPluginNodeProps } from "../withSlate-pfxNb3FA.js";
|
|
2
2
|
import { t as Hotkeys } from "../hotkeys-DI1HPO2Q.js";
|
|
3
|
-
import { A as pipeInjectNodeProps, C as createStaticEditor, k as pipeDecorate, s as PlateStatic } from "../static-
|
|
4
|
-
import { PathApi, createEditor } from "@platejs/slate";
|
|
3
|
+
import { A as pipeInjectNodeProps, C as createStaticEditor, k as pipeDecorate, s as PlateStatic } from "../static-C-jR24Fx.js";
|
|
4
|
+
import { NodeApi, PathApi, createEditor } from "@platejs/slate";
|
|
5
5
|
import { isDefined } from "@udecode/utils";
|
|
6
6
|
import { DefaultPlaceholder, Editable, Slate, useComposing, useFocused, useReadOnly, useSelected, useSlateStatic, withReact } from "slate-react";
|
|
7
7
|
import { c } from "react-compiler-runtime";
|
|
8
8
|
import React, { useEffect, useId, useRef } from "react";
|
|
9
9
|
import { Key, useHotkeys } from "@udecode/react-hotkeys";
|
|
10
|
-
import { createAtomStore, useAtomStoreSet, useAtomStoreState, useAtomStoreValue, useStoreAtomState, useStoreAtomValue, useStoreAtomValue as useStoreAtomValue$1, useStoreSetAtom } from "jotai-x";
|
|
11
10
|
import { atom, atom as atom$1 } from "jotai";
|
|
11
|
+
import { createAtomStore, useAtomStoreSet, useAtomStoreState, useAtomStoreValue, useStoreAtomState, useStoreAtomValue, useStoreAtomValue as useStoreAtomValue$1, useStoreSetAtom } from "jotai-x";
|
|
12
12
|
import { createZustandStore, createZustandStore as createZustandStore$1, useStoreSelect, useStoreSelect as useStoreSelect$1, useStoreState, useStoreValue, useStoreValue as useStoreValue$1, useTracked, useTrackedStore } from "zustand-x";
|
|
13
13
|
import clsx$1, { clsx } from "clsx";
|
|
14
14
|
import omit from "lodash/omit.js";
|
|
15
15
|
import { useDeepCompareMemo } from "use-deep-compare";
|
|
16
|
-
import { useComposedRef,
|
|
16
|
+
import { useComposedRef, useStableFn } from "@udecode/react-utils";
|
|
17
|
+
import { createStore } from "jotai/vanilla";
|
|
17
18
|
import { selectAtom } from "jotai/utils";
|
|
18
19
|
import { focusAtom } from "jotai-optics";
|
|
19
20
|
|
|
@@ -583,16 +584,30 @@ const DOM_HANDLERS = [
|
|
|
583
584
|
* `props.element.attributes` are passed into `props.attributes`. Extend the
|
|
584
585
|
* class name with the node type.
|
|
585
586
|
*/
|
|
586
|
-
const getRenderNodeProps = ({ attributes: nodeAttributes, disableInjectNodeProps, editor, plugin, props, readOnly }) => {
|
|
587
|
+
const getRenderNodeProps = ({ attributes: nodeAttributes, disableInjectNodeProps, editor, plugin, pluginContext, props, readOnly }) => {
|
|
588
|
+
const hasInjectNodeProps = !disableInjectNodeProps && editor.meta.pluginCache.inject.nodeProps.length > 0;
|
|
589
|
+
const canSkipPluginNodeProps = !hasInjectNodeProps && !plugin?.node.props && !plugin?.node.dangerouslyAllowAttributes?.length;
|
|
590
|
+
const resolvedPluginContext = pluginContext ? pluginContext : plugin ? getEditorPlugin(editor, plugin) : {
|
|
591
|
+
api: editor.api,
|
|
592
|
+
editor,
|
|
593
|
+
tf: editor.transforms
|
|
594
|
+
};
|
|
595
|
+
const { className } = props;
|
|
587
596
|
let newProps = {
|
|
588
597
|
...props,
|
|
589
|
-
...
|
|
590
|
-
api: editor.api,
|
|
591
|
-
editor,
|
|
592
|
-
tf: editor.transforms
|
|
593
|
-
}
|
|
598
|
+
...resolvedPluginContext
|
|
594
599
|
};
|
|
595
|
-
|
|
600
|
+
if (canSkipPluginNodeProps) {
|
|
601
|
+
newProps = {
|
|
602
|
+
...newProps,
|
|
603
|
+
attributes: {
|
|
604
|
+
...props.attributes,
|
|
605
|
+
className: clsx(getSlateClass(plugin?.node.type), props.attributes?.className, className) || void 0
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
if (newProps.attributes?.style && Object.keys(newProps.attributes.style).length === 0) newProps.attributes.style = void 0;
|
|
609
|
+
return newProps;
|
|
610
|
+
}
|
|
596
611
|
const pluginProps = getPluginNodeProps({
|
|
597
612
|
attributes: nodeAttributes,
|
|
598
613
|
plugin,
|
|
@@ -605,7 +620,7 @@ const getRenderNodeProps = ({ attributes: nodeAttributes, disableInjectNodeProps
|
|
|
605
620
|
className: clsx(getSlateClass(plugin?.node.type), pluginProps.attributes?.className, className) || void 0
|
|
606
621
|
}
|
|
607
622
|
};
|
|
608
|
-
if (
|
|
623
|
+
if (hasInjectNodeProps) newProps = pipeInjectNodeProps(editor, newProps, (node) => editor.api.findPath(node), readOnly);
|
|
609
624
|
if (newProps.attributes?.style && Object.keys(newProps.attributes.style).length === 0) newProps.attributes.style = void 0;
|
|
610
625
|
return newProps;
|
|
611
626
|
};
|
|
@@ -693,6 +708,21 @@ const pipeOnChange = (editor, value) => {
|
|
|
693
708
|
|
|
694
709
|
//#endregion
|
|
695
710
|
//#region src/react/components/plate-nodes.tsx
|
|
711
|
+
const VOID_HTML_TAGS = new Set([
|
|
712
|
+
"area",
|
|
713
|
+
"base",
|
|
714
|
+
"br",
|
|
715
|
+
"col",
|
|
716
|
+
"embed",
|
|
717
|
+
"hr",
|
|
718
|
+
"img",
|
|
719
|
+
"input",
|
|
720
|
+
"link",
|
|
721
|
+
"meta",
|
|
722
|
+
"source",
|
|
723
|
+
"track",
|
|
724
|
+
"wbr"
|
|
725
|
+
]);
|
|
696
726
|
const useNodeAttributes = (props, ref) => {
|
|
697
727
|
const $ = c(11);
|
|
698
728
|
const t0 = props.attributes;
|
|
@@ -731,81 +761,137 @@ const useNodeAttributes = (props, ref) => {
|
|
|
731
761
|
} else t5 = $[10];
|
|
732
762
|
return t5;
|
|
733
763
|
};
|
|
764
|
+
const isHtmlVoidElementTag = (tag) => VOID_HTML_TAGS.has(tag);
|
|
765
|
+
const useBlockIdAttributeRef = (blockId, ref) => {
|
|
766
|
+
const $ = c(2);
|
|
767
|
+
let t0;
|
|
768
|
+
if ($[0] !== blockId) {
|
|
769
|
+
t0 = (node) => {
|
|
770
|
+
if (!node) return;
|
|
771
|
+
if (blockId) node.setAttribute("data-block-id", String(blockId));
|
|
772
|
+
else node.removeAttribute("data-block-id");
|
|
773
|
+
};
|
|
774
|
+
$[0] = blockId;
|
|
775
|
+
$[1] = t0;
|
|
776
|
+
} else t0 = $[1];
|
|
777
|
+
return useComposedRef(t0, ref);
|
|
778
|
+
};
|
|
734
779
|
const PlateElement = React.forwardRef(function PlateElement$1(t0, ref) {
|
|
735
|
-
const $ = c(
|
|
780
|
+
const $ = c(15);
|
|
781
|
+
let Tag;
|
|
736
782
|
let children;
|
|
737
783
|
let insetProp;
|
|
738
784
|
let props;
|
|
739
785
|
let t1;
|
|
740
786
|
if ($[0] !== t0) {
|
|
741
|
-
|
|
787
|
+
const { as: t2$1, children: t3$1, insetProp: t4, ...t5 } = t0;
|
|
788
|
+
children = t3$1;
|
|
789
|
+
insetProp = t4;
|
|
790
|
+
props = t5;
|
|
791
|
+
Tag = t2$1 === void 0 ? "div" : t2$1;
|
|
792
|
+
t1 = props.element.id && props.editor.api.isBlock(props.element) ? props.element.id : void 0;
|
|
742
793
|
$[0] = t0;
|
|
743
|
-
$[1] =
|
|
744
|
-
$[2] =
|
|
745
|
-
$[3] =
|
|
746
|
-
$[4] =
|
|
794
|
+
$[1] = Tag;
|
|
795
|
+
$[2] = children;
|
|
796
|
+
$[3] = insetProp;
|
|
797
|
+
$[4] = props;
|
|
798
|
+
$[5] = t1;
|
|
747
799
|
} else {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
800
|
+
Tag = $[1];
|
|
801
|
+
children = $[2];
|
|
802
|
+
insetProp = $[3];
|
|
803
|
+
props = $[4];
|
|
804
|
+
t1 = $[5];
|
|
752
805
|
}
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
806
|
+
const blockIdRef = useBlockIdAttributeRef(t1, ref);
|
|
807
|
+
let t2;
|
|
808
|
+
if ($[6] !== props.attributes || $[7] !== props.className || $[8] !== props.style) {
|
|
809
|
+
t2 = {
|
|
810
|
+
attributes: props.attributes,
|
|
811
|
+
className: props.className,
|
|
812
|
+
style: props.style
|
|
813
|
+
};
|
|
814
|
+
$[6] = props.attributes;
|
|
815
|
+
$[7] = props.className;
|
|
816
|
+
$[8] = props.style;
|
|
817
|
+
$[9] = t2;
|
|
818
|
+
} else t2 = $[9];
|
|
819
|
+
const attributes = useNodeAttributes(t2, blockIdRef);
|
|
756
820
|
const inset = insetProp ?? props.plugin?.rules.selection?.affinity === "directional";
|
|
821
|
+
let t3;
|
|
822
|
+
if ($[10] !== Tag || $[11] !== attributes || $[12] !== children || $[13] !== inset) {
|
|
823
|
+
t3 = /* @__PURE__ */ React.createElement(PlateElementBody, {
|
|
824
|
+
attributes,
|
|
825
|
+
inset,
|
|
826
|
+
tag: Tag
|
|
827
|
+
}, children);
|
|
828
|
+
$[10] = Tag;
|
|
829
|
+
$[11] = attributes;
|
|
830
|
+
$[12] = children;
|
|
831
|
+
$[13] = inset;
|
|
832
|
+
$[14] = t3;
|
|
833
|
+
} else t3 = $[14];
|
|
834
|
+
return t3;
|
|
835
|
+
});
|
|
836
|
+
function PlateElementBody(t0) {
|
|
837
|
+
const $ = c(17);
|
|
838
|
+
const { attributes, children, inset, tag: Tag } = t0;
|
|
839
|
+
let t1;
|
|
840
|
+
if ($[0] !== Tag) {
|
|
841
|
+
t1 = isHtmlVoidElementTag(Tag);
|
|
842
|
+
$[0] = Tag;
|
|
843
|
+
$[1] = t1;
|
|
844
|
+
} else t1 = $[1];
|
|
845
|
+
const isVoidTag = t1;
|
|
757
846
|
let t2;
|
|
758
|
-
if ($[
|
|
847
|
+
if ($[2] !== inset) {
|
|
759
848
|
t2 = inset && /* @__PURE__ */ React.createElement(NonBreakingSpace, null);
|
|
760
|
-
$[
|
|
761
|
-
$[
|
|
762
|
-
} else t2 = $[
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
let t6;
|
|
767
|
-
if ($[7] !== t5) {
|
|
768
|
-
t6 = {
|
|
769
|
-
position: "relative",
|
|
770
|
-
...t5
|
|
771
|
-
};
|
|
772
|
-
$[7] = t5;
|
|
773
|
-
$[8] = t6;
|
|
774
|
-
} else t6 = $[8];
|
|
775
|
-
const t7 = t6;
|
|
776
|
-
let t8;
|
|
777
|
-
if ($[9] !== inset) {
|
|
778
|
-
t8 = inset && /* @__PURE__ */ React.createElement(NonBreakingSpace, null);
|
|
779
|
-
$[9] = inset;
|
|
780
|
-
$[10] = t8;
|
|
781
|
-
} else t8 = $[10];
|
|
782
|
-
let t9;
|
|
783
|
-
if ($[11] !== Tag || $[12] !== attributes || $[13] !== children || $[14] !== t3 || $[15] !== t4 || $[16] !== t7 || $[17] !== t8) {
|
|
784
|
-
t9 = /* @__PURE__ */ React.createElement(Tag, {
|
|
849
|
+
$[2] = inset;
|
|
850
|
+
$[3] = t2;
|
|
851
|
+
} else t2 = $[3];
|
|
852
|
+
let t3;
|
|
853
|
+
if ($[4] !== Tag || $[5] !== attributes || $[6] !== children || $[7] !== inset || $[8] !== isVoidTag) {
|
|
854
|
+
t3 = isVoidTag ? /* @__PURE__ */ React.createElement("div", {
|
|
785
855
|
"data-slate-node": "element",
|
|
786
|
-
"data-slate-inline":
|
|
787
|
-
"data-block-id": t4,
|
|
856
|
+
"data-slate-inline": attributes["data-slate-inline"],
|
|
788
857
|
...attributes,
|
|
789
|
-
style:
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
858
|
+
style: {
|
|
859
|
+
position: "relative",
|
|
860
|
+
...attributes?.style
|
|
861
|
+
}
|
|
862
|
+
}, /* @__PURE__ */ React.createElement(Tag, { contentEditable: false }), children) : /* @__PURE__ */ React.createElement(Tag, {
|
|
863
|
+
"data-slate-node": "element",
|
|
864
|
+
"data-slate-inline": attributes["data-slate-inline"],
|
|
865
|
+
...attributes,
|
|
866
|
+
style: {
|
|
867
|
+
position: "relative",
|
|
868
|
+
...attributes?.style
|
|
869
|
+
}
|
|
870
|
+
}, children, inset && /* @__PURE__ */ React.createElement(NonBreakingSpace, null));
|
|
871
|
+
$[4] = Tag;
|
|
872
|
+
$[5] = attributes;
|
|
873
|
+
$[6] = children;
|
|
874
|
+
$[7] = inset;
|
|
875
|
+
$[8] = isVoidTag;
|
|
876
|
+
$[9] = t3;
|
|
877
|
+
} else t3 = $[9];
|
|
878
|
+
let t4;
|
|
879
|
+
if ($[10] !== inset || $[11] !== isVoidTag) {
|
|
880
|
+
t4 = inset && isVoidTag && /* @__PURE__ */ React.createElement(NonBreakingSpace, null);
|
|
881
|
+
$[10] = inset;
|
|
882
|
+
$[11] = isVoidTag;
|
|
883
|
+
$[12] = t4;
|
|
884
|
+
} else t4 = $[12];
|
|
885
|
+
let t5;
|
|
886
|
+
if ($[13] !== t2 || $[14] !== t3 || $[15] !== t4) {
|
|
887
|
+
t5 = /* @__PURE__ */ React.createElement(React.Fragment, null, t2, t3, t4);
|
|
888
|
+
$[13] = t2;
|
|
794
889
|
$[14] = t3;
|
|
795
890
|
$[15] = t4;
|
|
796
|
-
$[16] =
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
let t10;
|
|
801
|
-
if ($[19] !== t2 || $[20] !== t9) {
|
|
802
|
-
t10 = /* @__PURE__ */ React.createElement(React.Fragment, null, t2, t9);
|
|
803
|
-
$[19] = t2;
|
|
804
|
-
$[20] = t9;
|
|
805
|
-
$[21] = t10;
|
|
806
|
-
} else t10 = $[21];
|
|
807
|
-
return t10;
|
|
808
|
-
});
|
|
891
|
+
$[16] = t5;
|
|
892
|
+
} else t5 = $[16];
|
|
893
|
+
return t5;
|
|
894
|
+
}
|
|
809
895
|
const PlateText = React.forwardRef((t0, ref) => {
|
|
810
896
|
const $ = c(8);
|
|
811
897
|
let children;
|
|
@@ -909,18 +995,55 @@ const PlateLeaf = React.forwardRef((t0, ref) => {
|
|
|
909
995
|
|
|
910
996
|
//#endregion
|
|
911
997
|
//#region src/react/utils/pluginRenderLeaf.tsx
|
|
998
|
+
const HARD_AFFINITY_SPACE$1 = String.fromCodePoint(160);
|
|
999
|
+
const HARD_AFFINITY_SPACER_STYLE$1 = {
|
|
1000
|
+
fontSize: 0,
|
|
1001
|
+
lineHeight: 0
|
|
1002
|
+
};
|
|
1003
|
+
const isActiveHardAffinityBoundary$1 = (editor, text) => {
|
|
1004
|
+
if (!editor.api.isCollapsed()) return false;
|
|
1005
|
+
const focus = editor.selection?.focus;
|
|
1006
|
+
if (!focus) return false;
|
|
1007
|
+
if (NodeApi.get(editor, focus.path) !== text) return false;
|
|
1008
|
+
return focus.offset === 0 || focus.offset === text.text.length;
|
|
1009
|
+
};
|
|
1010
|
+
const getSimpleLeafAttributes = (props, className) => {
|
|
1011
|
+
const attributes = props.attributes ?? props.leaf.attributes ?? {};
|
|
1012
|
+
return {
|
|
1013
|
+
...attributes,
|
|
1014
|
+
className: [className, attributes.className].filter(Boolean).join(" ") || void 0
|
|
1015
|
+
};
|
|
1016
|
+
};
|
|
912
1017
|
/**
|
|
913
1018
|
* Get a `Editable.renderLeaf` handler for `plugin.node.type`. If the type is
|
|
914
1019
|
* equals to the slate leaf type, render `plugin.render.node`. Else, return
|
|
915
1020
|
* `children`.
|
|
916
1021
|
*/
|
|
917
1022
|
const pluginRenderLeaf = (editor, plugin) => function render(props) {
|
|
918
|
-
const { render: { leaf: leafComponent, node } } = plugin;
|
|
919
|
-
const { children, leaf } = props;
|
|
920
1023
|
const readOnly = useReadOnly();
|
|
1024
|
+
const { render: { leaf: leafComponent, node } } = plugin;
|
|
1025
|
+
const { children, leaf, text } = props;
|
|
1026
|
+
const Component = leafComponent ?? node;
|
|
921
1027
|
if (isEditOnly(readOnly, plugin, "render")) return children;
|
|
922
1028
|
if (leaf[plugin.node.type]) {
|
|
923
|
-
const
|
|
1029
|
+
const canUseSimpleLeaf = !Component && editor.meta.pluginCache.inject.nodeProps.length === 0 && !plugin.node.props && !plugin.node.dangerouslyAllowAttributes?.length;
|
|
1030
|
+
if (canUseSimpleLeaf && !plugin.rules.selection?.affinity) {
|
|
1031
|
+
const Tag = plugin.render?.as ?? "span";
|
|
1032
|
+
const attributes = getSimpleLeafAttributes(props, getSlateClass(plugin.node.type) || void 0);
|
|
1033
|
+
return /* @__PURE__ */ React.createElement(Tag, attributes, children);
|
|
1034
|
+
}
|
|
1035
|
+
if (canUseSimpleLeaf && plugin.rules.selection?.affinity === "hard") {
|
|
1036
|
+
const Tag = plugin.render?.as ?? "span";
|
|
1037
|
+
const attributes = getSimpleLeafAttributes(props, getSlateClass(plugin.node.type) || void 0);
|
|
1038
|
+
if (!isActiveHardAffinityBoundary$1(editor, text)) return /* @__PURE__ */ React.createElement(Tag, attributes, children);
|
|
1039
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
|
|
1040
|
+
contentEditable: false,
|
|
1041
|
+
style: HARD_AFFINITY_SPACER_STYLE$1
|
|
1042
|
+
}, HARD_AFFINITY_SPACE$1), /* @__PURE__ */ React.createElement(Tag, attributes, children, /* @__PURE__ */ React.createElement("span", {
|
|
1043
|
+
contentEditable: false,
|
|
1044
|
+
style: HARD_AFFINITY_SPACER_STYLE$1
|
|
1045
|
+
}, HARD_AFFINITY_SPACE$1)));
|
|
1046
|
+
}
|
|
924
1047
|
const Leaf = Component ?? PlateLeaf;
|
|
925
1048
|
const ctxProps = getRenderNodeProps({
|
|
926
1049
|
attributes: leaf.attributes,
|
|
@@ -940,24 +1063,95 @@ const pluginRenderLeaf = (editor, plugin) => function render(props) {
|
|
|
940
1063
|
|
|
941
1064
|
//#endregion
|
|
942
1065
|
//#region src/react/utils/pipeRenderLeaf.tsx
|
|
1066
|
+
const HARD_AFFINITY_SPACE = String.fromCodePoint(160);
|
|
1067
|
+
const HARD_AFFINITY_SPACER_STYLE = {
|
|
1068
|
+
fontSize: 0,
|
|
1069
|
+
lineHeight: 0
|
|
1070
|
+
};
|
|
1071
|
+
const isActiveHardAffinityBoundary = (editor, text) => {
|
|
1072
|
+
if (!editor.api.isCollapsed()) return false;
|
|
1073
|
+
const focus = editor.selection?.focus;
|
|
1074
|
+
if (!focus) return false;
|
|
1075
|
+
if (NodeApi.get(editor, focus.path) !== text) return false;
|
|
1076
|
+
return focus.offset === 0 || focus.offset === text.text.length;
|
|
1077
|
+
};
|
|
943
1078
|
/** @see {@link RenderLeaf} */
|
|
944
1079
|
const pipeRenderLeaf = (editor, renderLeafProp) => {
|
|
945
|
-
const
|
|
1080
|
+
const complexRenderLeafEntries = [];
|
|
1081
|
+
const complexRenderLeafEntryByKey = /* @__PURE__ */ new Map();
|
|
1082
|
+
const renderLeafEntries = [];
|
|
1083
|
+
const renderLeafEntryByKey = /* @__PURE__ */ new Map();
|
|
946
1084
|
const leafPropsPlugins = [];
|
|
1085
|
+
const hasInjectNodeProps = editor.meta.pluginCache.inject.nodeProps.length > 0;
|
|
947
1086
|
editor.meta.pluginCache.node.isLeaf.forEach((key) => {
|
|
948
1087
|
const plugin = editor.getPlugin({ key });
|
|
949
|
-
if (plugin)
|
|
1088
|
+
if (plugin) {
|
|
1089
|
+
const leafKey = plugin.node.type ?? key;
|
|
1090
|
+
if (editor.meta.pluginCache.inject.nodeProps.length === 0 && !plugin.render?.leaf && !plugin.render?.node && !plugin.node.props && !plugin.node.dangerouslyAllowAttributes?.length && (!plugin.rules.selection?.affinity || plugin.rules.selection?.affinity === "hard")) {
|
|
1091
|
+
const entry = {
|
|
1092
|
+
className: plugin.node.type ? `slate-${plugin.node.type}` : void 0,
|
|
1093
|
+
editOnly: plugin.editOnly,
|
|
1094
|
+
key: leafKey,
|
|
1095
|
+
selectionAffinity: plugin.rules.selection?.affinity,
|
|
1096
|
+
tag: plugin.render?.as ?? "span"
|
|
1097
|
+
};
|
|
1098
|
+
renderLeafEntries.push(entry);
|
|
1099
|
+
renderLeafEntryByKey.set(leafKey, true);
|
|
1100
|
+
} else {
|
|
1101
|
+
const entry = {
|
|
1102
|
+
key: leafKey,
|
|
1103
|
+
renderLeaf: pluginRenderLeaf(editor, plugin)
|
|
1104
|
+
};
|
|
1105
|
+
complexRenderLeafEntries.push(entry);
|
|
1106
|
+
complexRenderLeafEntryByKey.set(leafKey, entry.renderLeaf);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
950
1109
|
});
|
|
951
1110
|
editor.meta.pluginCache.node.leafProps.forEach((key) => {
|
|
952
1111
|
const plugin = editor.getPlugin({ key });
|
|
953
1112
|
if (plugin) leafPropsPlugins.push(plugin);
|
|
954
1113
|
});
|
|
1114
|
+
if (!hasInjectNodeProps && renderLeafEntries.length === 0 && complexRenderLeafEntries.length === 0 && leafPropsPlugins.length === 0) {
|
|
1115
|
+
if (renderLeafProp) return renderLeafProp;
|
|
1116
|
+
return function render({ attributes, ...props }) {
|
|
1117
|
+
return /* @__PURE__ */ React.createElement("span", attributes, props.children);
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
const canUsePlainOuterLeaf = !hasInjectNodeProps && !renderLeafProp && leafPropsPlugins.length === 0;
|
|
955
1121
|
return function render({ attributes, ...props }) {
|
|
956
1122
|
const readOnly = useReadOnly();
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1123
|
+
const leaf = props.leaf;
|
|
1124
|
+
let hasActiveSimpleRenderLeaf = false;
|
|
1125
|
+
let hasActiveComplexRenderLeaf = false;
|
|
1126
|
+
for (const key in leaf) {
|
|
1127
|
+
if (!Object.hasOwn(leaf, key)) continue;
|
|
1128
|
+
if (!hasActiveSimpleRenderLeaf && renderLeafEntryByKey.has(key)) hasActiveSimpleRenderLeaf = true;
|
|
1129
|
+
if (!hasActiveComplexRenderLeaf && complexRenderLeafEntryByKey.has(key)) hasActiveComplexRenderLeaf = true;
|
|
1130
|
+
if (hasActiveSimpleRenderLeaf && hasActiveComplexRenderLeaf) break;
|
|
1131
|
+
}
|
|
1132
|
+
if (hasActiveSimpleRenderLeaf) for (const { className, editOnly, key, selectionAffinity, tag: Tag } of renderLeafEntries) {
|
|
1133
|
+
if (!leaf[key]) continue;
|
|
1134
|
+
if (editOnly && isEditOnly(readOnly, { editOnly }, "render")) continue;
|
|
1135
|
+
if (selectionAffinity === "hard") {
|
|
1136
|
+
if (!isActiveHardAffinityBoundary(editor, props.text)) {
|
|
1137
|
+
props.children = /* @__PURE__ */ React.createElement(Tag, { className }, props.children);
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
props.children = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
|
|
1141
|
+
contentEditable: false,
|
|
1142
|
+
style: HARD_AFFINITY_SPACER_STYLE
|
|
1143
|
+
}, HARD_AFFINITY_SPACE), /* @__PURE__ */ React.createElement(Tag, { className }, props.children, /* @__PURE__ */ React.createElement("span", {
|
|
1144
|
+
contentEditable: false,
|
|
1145
|
+
style: HARD_AFFINITY_SPACER_STYLE
|
|
1146
|
+
}, HARD_AFFINITY_SPACE)));
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
props.children = /* @__PURE__ */ React.createElement(Tag, { className }, props.children);
|
|
1150
|
+
}
|
|
1151
|
+
if (hasActiveComplexRenderLeaf) for (const { key, renderLeaf: RenderLeaf } of complexRenderLeafEntries) {
|
|
1152
|
+
if (!leaf[key]) continue;
|
|
1153
|
+
props.children = /* @__PURE__ */ React.createElement(RenderLeaf, props, props.children);
|
|
1154
|
+
}
|
|
961
1155
|
leafPropsPlugins.forEach((plugin) => {
|
|
962
1156
|
if (props.leaf[plugin.node.type]) {
|
|
963
1157
|
const pluginLeafProps = typeof plugin.node.leafProps === "function" ? plugin.node.leafProps(props) : plugin.node.leafProps ?? {};
|
|
@@ -968,6 +1162,7 @@ const pipeRenderLeaf = (editor, renderLeafProp) => {
|
|
|
968
1162
|
};
|
|
969
1163
|
}
|
|
970
1164
|
});
|
|
1165
|
+
if (canUsePlainOuterLeaf) return /* @__PURE__ */ React.createElement("span", attributes, props.children);
|
|
971
1166
|
if (renderLeafProp) return renderLeafProp({
|
|
972
1167
|
attributes,
|
|
973
1168
|
...props
|
|
@@ -986,17 +1181,30 @@ const pipeRenderLeaf = (editor, renderLeafProp) => {
|
|
|
986
1181
|
|
|
987
1182
|
//#endregion
|
|
988
1183
|
//#region src/react/utils/pluginRenderText.tsx
|
|
1184
|
+
const getSimpleTextAttributes = (props, className) => {
|
|
1185
|
+
const attributes = props.attributes ?? {};
|
|
1186
|
+
return {
|
|
1187
|
+
...attributes,
|
|
1188
|
+
className: [className, attributes.className].filter(Boolean).join(" ") || void 0
|
|
1189
|
+
};
|
|
1190
|
+
};
|
|
989
1191
|
/**
|
|
990
1192
|
* Get a `Editable.renderText` handler for `plugin.node.type`. If the type is
|
|
991
1193
|
* equals to the slate text type and isDecoration is false, render
|
|
992
1194
|
* `plugin.render.node`. Else, return the default text rendering.
|
|
993
1195
|
*/
|
|
994
1196
|
const pluginRenderText = (editor, plugin) => function render(nodeProps) {
|
|
1197
|
+
const readOnly = useReadOnly();
|
|
995
1198
|
const { render: { node } } = plugin;
|
|
996
1199
|
const { children, text } = nodeProps;
|
|
997
|
-
const
|
|
1200
|
+
const textKey = plugin.node.type ?? plugin.key;
|
|
998
1201
|
if (isEditOnly(readOnly, plugin, "render")) return children;
|
|
999
|
-
if (text[
|
|
1202
|
+
if (text[textKey]) {
|
|
1203
|
+
if (!node && editor.meta.pluginCache.inject.nodeProps.length === 0 && !plugin.node.props && !plugin.node.dangerouslyAllowAttributes?.length) {
|
|
1204
|
+
const Tag = plugin.render?.as ?? "span";
|
|
1205
|
+
const attributes = getSimpleTextAttributes(nodeProps, getSlateClass(plugin.node.type) || void 0);
|
|
1206
|
+
return /* @__PURE__ */ React.createElement(Tag, attributes, children);
|
|
1207
|
+
}
|
|
1000
1208
|
const Text = node ?? PlateText;
|
|
1001
1209
|
const ctxProps = getRenderNodeProps({
|
|
1002
1210
|
attributes: nodeProps.attributes,
|
|
@@ -1019,17 +1227,58 @@ const pluginRenderText = (editor, plugin) => function render(nodeProps) {
|
|
|
1019
1227
|
/** @see {@link RenderText} */
|
|
1020
1228
|
const pipeRenderText = (editor, renderTextProp) => {
|
|
1021
1229
|
const renderTexts = [];
|
|
1230
|
+
const renderTextByKey = /* @__PURE__ */ new Map();
|
|
1231
|
+
const simpleRenderTexts = [];
|
|
1232
|
+
const simpleRenderTextByKey = /* @__PURE__ */ new Map();
|
|
1022
1233
|
const textPropsPlugins = [];
|
|
1234
|
+
const hasInjectNodeProps = editor.meta.pluginCache.inject.nodeProps.length > 0;
|
|
1023
1235
|
editor.meta.pluginList.forEach((plugin) => {
|
|
1024
|
-
if (plugin.node.isLeaf && plugin.node.isDecoration === false)
|
|
1236
|
+
if (plugin.node.isLeaf && plugin.node.isDecoration === false) if (!plugin.render.node && !plugin.node.component && !plugin.node.props && !plugin.node.dangerouslyAllowAttributes?.length) {
|
|
1237
|
+
const entry = {
|
|
1238
|
+
className: getSlateClass(plugin.node.type) || void 0,
|
|
1239
|
+
plugin,
|
|
1240
|
+
tag: plugin.render?.as ?? "span",
|
|
1241
|
+
textKey: plugin.node.type ?? plugin.key
|
|
1242
|
+
};
|
|
1243
|
+
simpleRenderTexts.push(entry);
|
|
1244
|
+
simpleRenderTextByKey.set(entry.textKey, true);
|
|
1245
|
+
} else {
|
|
1246
|
+
const entry = {
|
|
1247
|
+
renderText: pluginRenderText(editor, plugin),
|
|
1248
|
+
textKey: plugin.node.type ?? plugin.key
|
|
1249
|
+
};
|
|
1250
|
+
renderTexts.push(entry);
|
|
1251
|
+
renderTextByKey.set(entry.textKey, true);
|
|
1252
|
+
}
|
|
1025
1253
|
if (plugin.node.textProps) textPropsPlugins.push(plugin);
|
|
1026
1254
|
});
|
|
1255
|
+
if (!hasInjectNodeProps && simpleRenderTexts.length === 0 && renderTexts.length === 0 && textPropsPlugins.length === 0) {
|
|
1256
|
+
if (renderTextProp) return renderTextProp;
|
|
1257
|
+
return function render({ attributes, ...props }) {
|
|
1258
|
+
return /* @__PURE__ */ React.createElement("span", attributes, props.children);
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
const canUsePlainOuterText = !hasInjectNodeProps && !renderTextProp && textPropsPlugins.length === 0;
|
|
1027
1262
|
return function render({ attributes, ...props }) {
|
|
1028
1263
|
const readOnly = useReadOnly();
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1264
|
+
const text = props.text;
|
|
1265
|
+
let hasActiveSimpleRenderText = false;
|
|
1266
|
+
let hasActiveRenderText = false;
|
|
1267
|
+
for (const textKey in text) {
|
|
1268
|
+
if (!Object.hasOwn(text, textKey)) continue;
|
|
1269
|
+
if (!hasActiveSimpleRenderText && simpleRenderTextByKey.has(textKey)) hasActiveSimpleRenderText = true;
|
|
1270
|
+
if (!hasActiveRenderText && renderTextByKey.has(textKey)) hasActiveRenderText = true;
|
|
1271
|
+
if (hasActiveSimpleRenderText && hasActiveRenderText) break;
|
|
1272
|
+
}
|
|
1273
|
+
if (hasActiveSimpleRenderText) for (const { className, plugin, tag: Tag, textKey } of simpleRenderTexts) {
|
|
1274
|
+
if (!text[textKey]) continue;
|
|
1275
|
+
if (isEditOnly(readOnly, plugin, "render")) continue;
|
|
1276
|
+
props.children = /* @__PURE__ */ React.createElement(Tag, { className }, props.children);
|
|
1277
|
+
}
|
|
1278
|
+
if (hasActiveRenderText) for (const { renderText: RenderText, textKey } of renderTexts) {
|
|
1279
|
+
if (!text[textKey]) continue;
|
|
1280
|
+
props.children = /* @__PURE__ */ React.createElement(RenderText, props, props.children);
|
|
1281
|
+
}
|
|
1033
1282
|
textPropsPlugins.forEach((plugin) => {
|
|
1034
1283
|
if (props.text[plugin.node.type ?? plugin.key]) {
|
|
1035
1284
|
const pluginTextProps = typeof plugin.node.textProps === "function" ? plugin.node.textProps(props) : plugin.node.textProps ?? {};
|
|
@@ -1040,6 +1289,7 @@ const pipeRenderText = (editor, renderTextProp) => {
|
|
|
1040
1289
|
};
|
|
1041
1290
|
}
|
|
1042
1291
|
});
|
|
1292
|
+
if (canUsePlainOuterText) return /* @__PURE__ */ React.createElement("span", attributes, props.children);
|
|
1043
1293
|
if (renderTextProp) return renderTextProp({
|
|
1044
1294
|
attributes,
|
|
1045
1295
|
...props
|
|
@@ -1147,27 +1397,17 @@ const useEditableProps = ({ disabled, readOnly, ...editableProps } = {}) => {
|
|
|
1147
1397
|
* will not return the new path.
|
|
1148
1398
|
*/
|
|
1149
1399
|
const useNodePath = (node) => {
|
|
1150
|
-
const $ = c(
|
|
1400
|
+
const $ = c(3);
|
|
1151
1401
|
const editor = useEditorRef();
|
|
1152
1402
|
let t0;
|
|
1153
1403
|
if ($[0] !== editor.api || $[1] !== node) {
|
|
1154
|
-
t0 =
|
|
1404
|
+
t0 = editor.api.findPath(node);
|
|
1155
1405
|
$[0] = editor.api;
|
|
1156
1406
|
$[1] = node;
|
|
1157
1407
|
$[2] = t0;
|
|
1158
1408
|
} else t0 = $[2];
|
|
1159
|
-
|
|
1160
|
-
if ($[3] !== editor || $[4] !== node) {
|
|
1161
|
-
t1 = [editor, node];
|
|
1162
|
-
$[3] = editor;
|
|
1163
|
-
$[4] = node;
|
|
1164
|
-
$[5] = t1;
|
|
1165
|
-
} else t1 = $[5];
|
|
1166
|
-
return useMemoizedSelector(t0, t1, _temp);
|
|
1409
|
+
return t0;
|
|
1167
1410
|
};
|
|
1168
|
-
function _temp(a, b) {
|
|
1169
|
-
return !!a && !!b && PathApi.equals(a, b);
|
|
1170
|
-
}
|
|
1171
1411
|
|
|
1172
1412
|
//#endregion
|
|
1173
1413
|
//#region src/react/hooks/useSlateProps.ts
|
|
@@ -1251,44 +1491,193 @@ const useSlateProps = (t0) => {
|
|
|
1251
1491
|
return t6;
|
|
1252
1492
|
};
|
|
1253
1493
|
|
|
1254
|
-
//#endregion
|
|
1255
|
-
//#region src/react/stores/element/usePath.ts
|
|
1256
|
-
/** Get the memoized path of the closest element. */
|
|
1257
|
-
const usePath = (pluginKey) => {
|
|
1258
|
-
const editor = useEditorRef();
|
|
1259
|
-
const value = useAtomStoreValue(useElementStore(pluginKey), "path");
|
|
1260
|
-
if (!value) {
|
|
1261
|
-
editor.api.debug.warn(`usePath(${pluginKey}) hook must be used inside the node component's context`, "USE_ELEMENT_CONTEXT");
|
|
1262
|
-
return;
|
|
1263
|
-
}
|
|
1264
|
-
return value;
|
|
1265
|
-
};
|
|
1266
|
-
|
|
1267
1494
|
//#endregion
|
|
1268
1495
|
//#region src/react/stores/element/useElementStore.tsx
|
|
1269
1496
|
const SCOPE_ELEMENT = "element";
|
|
1270
|
-
const
|
|
1497
|
+
const { elementStore, useElementStore: useElementStoreAtom } = createAtomStore({
|
|
1271
1498
|
element: null,
|
|
1272
1499
|
entry: null,
|
|
1273
1500
|
path: null
|
|
1274
|
-
}
|
|
1275
|
-
const { ElementProvider, elementStore, useElementStore } = createAtomStore(initialState, {
|
|
1276
|
-
effect: Effect,
|
|
1501
|
+
}, {
|
|
1277
1502
|
name: "element",
|
|
1278
1503
|
suppressWarnings: true
|
|
1279
1504
|
});
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1505
|
+
const ElementContext = React.createContext(null);
|
|
1506
|
+
const ElementStoreContext = React.createContext(null);
|
|
1507
|
+
let currentElementContext = null;
|
|
1508
|
+
const syncElementStore = (store, nextState, prevState) => {
|
|
1509
|
+
if (!prevState || !Object.is(prevState.element, nextState.element)) store.set(elementStore.atom.element, nextState.element);
|
|
1510
|
+
if (!prevState || !Object.is(prevState.entry, nextState.entry)) store.set(elementStore.atom.entry, nextState.entry);
|
|
1511
|
+
if (!prevState || !Object.is(prevState.path, nextState.path)) store.set(elementStore.atom.path, nextState.path);
|
|
1512
|
+
};
|
|
1513
|
+
const createElementJotaiStore = (state) => {
|
|
1514
|
+
const store = createStore();
|
|
1515
|
+
syncElementStore(store, state);
|
|
1516
|
+
return store;
|
|
1517
|
+
};
|
|
1518
|
+
const createElementRuntimeStore = (initialState) => {
|
|
1519
|
+
let jotaiStore = null;
|
|
1520
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1521
|
+
let state = initialState;
|
|
1522
|
+
return {
|
|
1523
|
+
getJotaiStore: () => {
|
|
1524
|
+
if (!jotaiStore) jotaiStore = createElementJotaiStore(state);
|
|
1525
|
+
return jotaiStore;
|
|
1526
|
+
},
|
|
1527
|
+
getState: () => state,
|
|
1528
|
+
setState: (nextState) => {
|
|
1529
|
+
if (Object.is(state.element, nextState.element) && Object.is(state.entry, nextState.entry) && Object.is(state.path, nextState.path)) return;
|
|
1530
|
+
const prevState = state;
|
|
1531
|
+
state = nextState;
|
|
1532
|
+
if (jotaiStore) syncElementStore(jotaiStore, nextState, prevState);
|
|
1533
|
+
listeners.forEach((listener) => {
|
|
1534
|
+
listener();
|
|
1535
|
+
});
|
|
1536
|
+
},
|
|
1537
|
+
subscribe: (listener) => {
|
|
1538
|
+
listeners.add(listener);
|
|
1539
|
+
return () => {
|
|
1540
|
+
listeners.delete(listener);
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
};
|
|
1545
|
+
const findElementContext = (context, scope) => {
|
|
1546
|
+
if (!context) return null;
|
|
1547
|
+
if (!scope) return context;
|
|
1548
|
+
let current = context;
|
|
1549
|
+
while (current) {
|
|
1550
|
+
if (current.scope === scope) return current;
|
|
1551
|
+
current = current.parent;
|
|
1552
|
+
}
|
|
1553
|
+
return context;
|
|
1554
|
+
};
|
|
1555
|
+
const findMatchingElementContext = (context, scope) => {
|
|
1556
|
+
if (!context || !scope) return context;
|
|
1557
|
+
let current = context;
|
|
1558
|
+
while (current) {
|
|
1559
|
+
if (current.scope === scope) return current;
|
|
1560
|
+
current = current.parent;
|
|
1290
1561
|
}
|
|
1291
1562
|
return null;
|
|
1563
|
+
};
|
|
1564
|
+
const withElementContext = (context, callback) => {
|
|
1565
|
+
const previousContext = currentElementContext;
|
|
1566
|
+
const nextContext = {};
|
|
1567
|
+
Object.defineProperties(nextContext, Object.getOwnPropertyDescriptors(context));
|
|
1568
|
+
nextContext.parent = previousContext;
|
|
1569
|
+
currentElementContext = nextContext;
|
|
1570
|
+
try {
|
|
1571
|
+
return callback();
|
|
1572
|
+
} finally {
|
|
1573
|
+
currentElementContext = previousContext;
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
const useElementContext = (scope) => {
|
|
1577
|
+
const $ = c(8);
|
|
1578
|
+
const context = React.useContext(ElementContext);
|
|
1579
|
+
let t0;
|
|
1580
|
+
if ($[0] !== scope) {
|
|
1581
|
+
t0 = findMatchingElementContext(currentElementContext, scope);
|
|
1582
|
+
$[0] = scope;
|
|
1583
|
+
$[1] = t0;
|
|
1584
|
+
} else t0 = $[1];
|
|
1585
|
+
const renderContext = t0;
|
|
1586
|
+
if (renderContext) return renderContext;
|
|
1587
|
+
let t1;
|
|
1588
|
+
if ($[2] !== context || $[3] !== scope) {
|
|
1589
|
+
t1 = findMatchingElementContext(context, scope);
|
|
1590
|
+
$[2] = context;
|
|
1591
|
+
$[3] = scope;
|
|
1592
|
+
$[4] = t1;
|
|
1593
|
+
} else t1 = $[4];
|
|
1594
|
+
const providerContext = t1;
|
|
1595
|
+
if (providerContext) return providerContext;
|
|
1596
|
+
if (currentElementContext) return currentElementContext;
|
|
1597
|
+
let t2;
|
|
1598
|
+
if ($[5] !== context || $[6] !== scope) {
|
|
1599
|
+
t2 = findElementContext(context, scope);
|
|
1600
|
+
$[5] = context;
|
|
1601
|
+
$[6] = scope;
|
|
1602
|
+
$[7] = t2;
|
|
1603
|
+
} else t2 = $[7];
|
|
1604
|
+
return t2;
|
|
1605
|
+
};
|
|
1606
|
+
const useElementStoreContext = (scope) => {
|
|
1607
|
+
const context = React.useContext(ElementStoreContext);
|
|
1608
|
+
if (!context) return null;
|
|
1609
|
+
if (!scope) return context;
|
|
1610
|
+
let current = context;
|
|
1611
|
+
while (current) {
|
|
1612
|
+
if (current.scope === scope) return current;
|
|
1613
|
+
current = current.parent;
|
|
1614
|
+
}
|
|
1615
|
+
return context;
|
|
1616
|
+
};
|
|
1617
|
+
const useElementStore = (scope) => {
|
|
1618
|
+
const $ = c(3);
|
|
1619
|
+
const context = useElementStoreContext(scope);
|
|
1620
|
+
let t0;
|
|
1621
|
+
if ($[0] !== context || $[1] !== scope) {
|
|
1622
|
+
t0 = context ? {
|
|
1623
|
+
scope,
|
|
1624
|
+
store: context.store
|
|
1625
|
+
} : scope;
|
|
1626
|
+
$[0] = context;
|
|
1627
|
+
$[1] = scope;
|
|
1628
|
+
$[2] = t0;
|
|
1629
|
+
} else t0 = $[2];
|
|
1630
|
+
return useElementStoreAtom(t0);
|
|
1631
|
+
};
|
|
1632
|
+
function ElementProvider({ children, path, scope, ...props }) {
|
|
1633
|
+
const element = props.element ?? null;
|
|
1634
|
+
const entry = props.entry ?? null;
|
|
1635
|
+
const elementPath = path ?? null;
|
|
1636
|
+
const [runtime] = React.useState(() => createElementRuntimeStore({
|
|
1637
|
+
element,
|
|
1638
|
+
entry,
|
|
1639
|
+
path: elementPath
|
|
1640
|
+
}));
|
|
1641
|
+
const parent = React.useContext(ElementContext);
|
|
1642
|
+
const parentStore = React.useContext(ElementStoreContext);
|
|
1643
|
+
const contextValue = React.useMemo(() => ({
|
|
1644
|
+
element,
|
|
1645
|
+
entry,
|
|
1646
|
+
parent,
|
|
1647
|
+
path: elementPath,
|
|
1648
|
+
scope
|
|
1649
|
+
}), [
|
|
1650
|
+
element,
|
|
1651
|
+
elementPath,
|
|
1652
|
+
entry,
|
|
1653
|
+
parent,
|
|
1654
|
+
scope
|
|
1655
|
+
]);
|
|
1656
|
+
const storeContextValue = React.useMemo(() => ({
|
|
1657
|
+
parent: parentStore,
|
|
1658
|
+
runtime,
|
|
1659
|
+
scope,
|
|
1660
|
+
get store() {
|
|
1661
|
+
return runtime.getJotaiStore();
|
|
1662
|
+
}
|
|
1663
|
+
}), [
|
|
1664
|
+
parentStore,
|
|
1665
|
+
runtime,
|
|
1666
|
+
scope
|
|
1667
|
+
]);
|
|
1668
|
+
React.useLayoutEffect(() => {
|
|
1669
|
+
runtime.setState({
|
|
1670
|
+
element,
|
|
1671
|
+
entry,
|
|
1672
|
+
path: elementPath
|
|
1673
|
+
});
|
|
1674
|
+
}, [
|
|
1675
|
+
element,
|
|
1676
|
+
elementPath,
|
|
1677
|
+
entry,
|
|
1678
|
+
runtime
|
|
1679
|
+
]);
|
|
1680
|
+
return /* @__PURE__ */ React.createElement(ElementStoreContext.Provider, { value: storeContextValue }, /* @__PURE__ */ React.createElement(ElementContext.Provider, { value: contextValue }, path && PathApi.equals(path, [0]) ? /* @__PURE__ */ React.createElement(FirstBlockEffect, null) : null, children));
|
|
1292
1681
|
}
|
|
1293
1682
|
function FirstBlockEffect() {
|
|
1294
1683
|
const editor = useEditorRef();
|
|
@@ -1307,18 +1696,18 @@ function FirstBlockEffect() {
|
|
|
1307
1696
|
//#region src/react/utils/pluginRenderElement.tsx
|
|
1308
1697
|
function ElementContent(t0) {
|
|
1309
1698
|
const $ = c(3);
|
|
1310
|
-
const { editor, plugin, ...t1 } = t0;
|
|
1699
|
+
const { editor, plugin, pluginContext, ...t1 } = t0;
|
|
1311
1700
|
let props = t1;
|
|
1312
|
-
const element = useElement();
|
|
1313
1701
|
const readOnly = useReadOnly();
|
|
1314
1702
|
if (isEditOnly(readOnly, plugin, "render")) return null;
|
|
1315
1703
|
const { children: _children } = props;
|
|
1316
1704
|
const Component = plugin.render?.node;
|
|
1317
1705
|
const Element = Component ?? PlateElement;
|
|
1318
1706
|
props = getRenderNodeProps({
|
|
1319
|
-
attributes: element.attributes,
|
|
1707
|
+
attributes: props.element.attributes,
|
|
1320
1708
|
editor,
|
|
1321
1709
|
plugin,
|
|
1710
|
+
pluginContext,
|
|
1322
1711
|
props,
|
|
1323
1712
|
readOnly
|
|
1324
1713
|
});
|
|
@@ -1364,13 +1753,19 @@ function ElementContent(t0) {
|
|
|
1364
1753
|
});
|
|
1365
1754
|
return component;
|
|
1366
1755
|
}
|
|
1367
|
-
function BelowRootNodes(
|
|
1368
|
-
const $ = c(
|
|
1756
|
+
function BelowRootNodes(t0) {
|
|
1757
|
+
const $ = c(8);
|
|
1758
|
+
let props;
|
|
1759
|
+
if ($[0] !== t0) {
|
|
1760
|
+
({...props} = t0);
|
|
1761
|
+
$[0] = t0;
|
|
1762
|
+
$[1] = props;
|
|
1763
|
+
} else props = $[1];
|
|
1369
1764
|
const editor = useEditorRef();
|
|
1370
1765
|
const readOnly = useReadOnly();
|
|
1371
|
-
let
|
|
1372
|
-
if ($[
|
|
1373
|
-
|
|
1766
|
+
let t1;
|
|
1767
|
+
if ($[2] !== editor || $[3] !== props || $[4] !== readOnly) {
|
|
1768
|
+
t1 = editor.meta.pluginCache.render.belowRootNodes.map((key) => {
|
|
1374
1769
|
const plugin = editor.getPlugin({ key });
|
|
1375
1770
|
if (isEditOnly(readOnly, plugin, "render")) return null;
|
|
1376
1771
|
const Component = plugin.render.belowRootNodes;
|
|
@@ -1379,55 +1774,338 @@ function BelowRootNodes(props) {
|
|
|
1379
1774
|
...props
|
|
1380
1775
|
});
|
|
1381
1776
|
});
|
|
1382
|
-
$[
|
|
1383
|
-
$[
|
|
1384
|
-
$[
|
|
1385
|
-
$[3] = t0;
|
|
1386
|
-
} else t0 = $[3];
|
|
1387
|
-
let t1;
|
|
1388
|
-
if ($[4] !== t0) {
|
|
1389
|
-
t1 = /* @__PURE__ */ React.createElement(React.Fragment, null, t0);
|
|
1390
|
-
$[4] = t0;
|
|
1777
|
+
$[2] = editor;
|
|
1778
|
+
$[3] = props;
|
|
1779
|
+
$[4] = readOnly;
|
|
1391
1780
|
$[5] = t1;
|
|
1392
1781
|
} else t1 = $[5];
|
|
1393
|
-
|
|
1782
|
+
let t2;
|
|
1783
|
+
if ($[6] !== t1) {
|
|
1784
|
+
t2 = /* @__PURE__ */ React.createElement(React.Fragment, null, t1);
|
|
1785
|
+
$[6] = t1;
|
|
1786
|
+
$[7] = t2;
|
|
1787
|
+
} else t2 = $[7];
|
|
1788
|
+
return t2;
|
|
1394
1789
|
}
|
|
1395
1790
|
/**
|
|
1396
1791
|
* Get a `Editable.renderElement` handler for `plugin.node.type`. If the type is
|
|
1397
1792
|
* equals to the slate element type, render `plugin.render.node`. Else, return
|
|
1398
1793
|
* `undefined` so the pipeline can check the next plugin.
|
|
1399
1794
|
*/
|
|
1400
|
-
const pluginRenderElement = (editor, plugin) =>
|
|
1401
|
-
const
|
|
1402
|
-
return
|
|
1403
|
-
element,
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1795
|
+
const pluginRenderElement = (editor, plugin) => {
|
|
1796
|
+
const pluginContext = getEditorPlugin(editor, plugin);
|
|
1797
|
+
return function render(props) {
|
|
1798
|
+
const { element, path } = props;
|
|
1799
|
+
return /* @__PURE__ */ React.createElement(ElementProvider, {
|
|
1800
|
+
element,
|
|
1801
|
+
entry: [element, path],
|
|
1802
|
+
path,
|
|
1803
|
+
scope: plugin.key
|
|
1804
|
+
}, /* @__PURE__ */ React.createElement(ElementContent, {
|
|
1805
|
+
editor,
|
|
1806
|
+
plugin,
|
|
1807
|
+
pluginContext,
|
|
1808
|
+
...props
|
|
1809
|
+
}));
|
|
1810
|
+
};
|
|
1412
1811
|
};
|
|
1413
1812
|
|
|
1414
1813
|
//#endregion
|
|
1415
1814
|
//#region src/react/utils/pipeRenderElement.tsx
|
|
1416
|
-
|
|
1417
|
-
const
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1815
|
+
function FastElementWithPath(t0) {
|
|
1816
|
+
const $ = c(16);
|
|
1817
|
+
const { attributes, children, editor, element, plugin } = t0;
|
|
1818
|
+
const path = useNodePath(element);
|
|
1819
|
+
let t1;
|
|
1820
|
+
if ($[0] !== element || $[1] !== path) {
|
|
1821
|
+
t1 = [element, path];
|
|
1822
|
+
$[0] = element;
|
|
1823
|
+
$[1] = path;
|
|
1824
|
+
$[2] = t1;
|
|
1825
|
+
} else t1 = $[2];
|
|
1826
|
+
let t2;
|
|
1827
|
+
if ($[3] !== attributes || $[4] !== children || $[5] !== editor || $[6] !== element || $[7] !== path || $[8] !== plugin) {
|
|
1828
|
+
t2 = /* @__PURE__ */ React.createElement(FastElementBody, {
|
|
1829
|
+
attributes,
|
|
1830
|
+
editor,
|
|
1831
|
+
element,
|
|
1832
|
+
path,
|
|
1833
|
+
plugin
|
|
1834
|
+
}, children);
|
|
1835
|
+
$[3] = attributes;
|
|
1836
|
+
$[4] = children;
|
|
1837
|
+
$[5] = editor;
|
|
1838
|
+
$[6] = element;
|
|
1839
|
+
$[7] = path;
|
|
1840
|
+
$[8] = plugin;
|
|
1841
|
+
$[9] = t2;
|
|
1842
|
+
} else t2 = $[9];
|
|
1843
|
+
let t3;
|
|
1844
|
+
if ($[10] !== element || $[11] !== path || $[12] !== plugin.key || $[13] !== t1 || $[14] !== t2) {
|
|
1845
|
+
t3 = /* @__PURE__ */ React.createElement(ElementProvider, {
|
|
1846
|
+
element,
|
|
1847
|
+
entry: t1,
|
|
1848
|
+
path,
|
|
1849
|
+
scope: plugin.key
|
|
1850
|
+
}, t2);
|
|
1851
|
+
$[10] = element;
|
|
1852
|
+
$[11] = path;
|
|
1853
|
+
$[12] = plugin.key;
|
|
1854
|
+
$[13] = t1;
|
|
1855
|
+
$[14] = t2;
|
|
1856
|
+
$[15] = t3;
|
|
1857
|
+
} else t3 = $[15];
|
|
1858
|
+
return t3;
|
|
1859
|
+
}
|
|
1860
|
+
function useFastInjectedAttributes({ attributes, editor, element, path, readOnly }) {
|
|
1861
|
+
if (editor.meta.pluginCache.inject.nodeProps.length === 0) return attributes;
|
|
1862
|
+
return pipeInjectNodeProps(editor, {
|
|
1863
|
+
attributes,
|
|
1864
|
+
element
|
|
1865
|
+
}, (node) => node === element ? path : editor.api.findPath(node), readOnly).attributes;
|
|
1866
|
+
}
|
|
1867
|
+
function FastElementBody(t0) {
|
|
1868
|
+
const $ = c(16);
|
|
1869
|
+
const { attributes, children, editor, element, path, plugin } = t0;
|
|
1870
|
+
const readOnly = useReadOnly();
|
|
1871
|
+
let t1;
|
|
1872
|
+
if ($[0] !== attributes || $[1] !== editor || $[2] !== element || $[3] !== path || $[4] !== readOnly) {
|
|
1873
|
+
t1 = {
|
|
1874
|
+
attributes,
|
|
1875
|
+
editor,
|
|
1876
|
+
element,
|
|
1877
|
+
path,
|
|
1878
|
+
readOnly
|
|
1879
|
+
};
|
|
1880
|
+
$[0] = attributes;
|
|
1881
|
+
$[1] = editor;
|
|
1882
|
+
$[2] = element;
|
|
1883
|
+
$[3] = path;
|
|
1884
|
+
$[4] = readOnly;
|
|
1885
|
+
$[5] = t1;
|
|
1886
|
+
} else t1 = $[5];
|
|
1887
|
+
const injectedAttributes = useFastInjectedAttributes(t1);
|
|
1888
|
+
const t2 = plugin.render?.as;
|
|
1889
|
+
let t3;
|
|
1890
|
+
if ($[6] !== children || $[7] !== editor || $[8] !== element || $[9] !== injectedAttributes || $[10] !== path || $[11] !== plugin || $[12] !== t2) {
|
|
1891
|
+
t3 = {
|
|
1892
|
+
as: t2,
|
|
1893
|
+
attributes: injectedAttributes,
|
|
1894
|
+
children,
|
|
1895
|
+
editor,
|
|
1896
|
+
element,
|
|
1897
|
+
path,
|
|
1898
|
+
plugin
|
|
1899
|
+
};
|
|
1900
|
+
$[6] = children;
|
|
1901
|
+
$[7] = editor;
|
|
1902
|
+
$[8] = element;
|
|
1903
|
+
$[9] = injectedAttributes;
|
|
1904
|
+
$[10] = path;
|
|
1905
|
+
$[11] = plugin;
|
|
1906
|
+
$[12] = t2;
|
|
1907
|
+
$[13] = t3;
|
|
1908
|
+
} else t3 = $[13];
|
|
1909
|
+
const t4 = t3;
|
|
1910
|
+
let t5;
|
|
1911
|
+
if ($[14] !== t4) {
|
|
1912
|
+
t5 = /* @__PURE__ */ React.createElement(PlateElement, t4);
|
|
1913
|
+
$[14] = t4;
|
|
1914
|
+
$[15] = t5;
|
|
1915
|
+
} else t5 = $[15];
|
|
1916
|
+
return t5;
|
|
1917
|
+
}
|
|
1918
|
+
function FastIntrinsicElement(t0) {
|
|
1919
|
+
const $ = c(20);
|
|
1920
|
+
const { attributes, blockId, children, editor, element, isVoidTag, plugin, renderBelowNodes, tag: Tag } = t0;
|
|
1921
|
+
const path = useNodePath(element);
|
|
1922
|
+
let t1;
|
|
1923
|
+
if ($[0] !== element || $[1] !== path) {
|
|
1924
|
+
t1 = [element, path];
|
|
1925
|
+
$[0] = element;
|
|
1926
|
+
$[1] = path;
|
|
1927
|
+
$[2] = t1;
|
|
1928
|
+
} else t1 = $[2];
|
|
1929
|
+
let t2;
|
|
1930
|
+
if ($[3] !== Tag || $[4] !== attributes || $[5] !== blockId || $[6] !== children || $[7] !== editor || $[8] !== element || $[9] !== isVoidTag || $[10] !== path || $[11] !== plugin || $[12] !== renderBelowNodes) {
|
|
1931
|
+
t2 = /* @__PURE__ */ React.createElement(FastIntrinsicElementBody, {
|
|
1932
|
+
attributes,
|
|
1933
|
+
blockId,
|
|
1934
|
+
editor,
|
|
1935
|
+
element,
|
|
1936
|
+
isVoidTag,
|
|
1937
|
+
path,
|
|
1938
|
+
plugin,
|
|
1939
|
+
renderBelowNodes,
|
|
1940
|
+
tag: Tag
|
|
1941
|
+
}, children);
|
|
1942
|
+
$[3] = Tag;
|
|
1943
|
+
$[4] = attributes;
|
|
1944
|
+
$[5] = blockId;
|
|
1945
|
+
$[6] = children;
|
|
1946
|
+
$[7] = editor;
|
|
1947
|
+
$[8] = element;
|
|
1948
|
+
$[9] = isVoidTag;
|
|
1949
|
+
$[10] = path;
|
|
1950
|
+
$[11] = plugin;
|
|
1951
|
+
$[12] = renderBelowNodes;
|
|
1952
|
+
$[13] = t2;
|
|
1953
|
+
} else t2 = $[13];
|
|
1954
|
+
let t3;
|
|
1955
|
+
if ($[14] !== element || $[15] !== path || $[16] !== plugin.key || $[17] !== t1 || $[18] !== t2) {
|
|
1956
|
+
t3 = /* @__PURE__ */ React.createElement(ElementProvider, {
|
|
1957
|
+
element,
|
|
1958
|
+
entry: t1,
|
|
1959
|
+
path,
|
|
1960
|
+
scope: plugin.key
|
|
1961
|
+
}, t2);
|
|
1962
|
+
$[14] = element;
|
|
1963
|
+
$[15] = path;
|
|
1964
|
+
$[16] = plugin.key;
|
|
1965
|
+
$[17] = t1;
|
|
1966
|
+
$[18] = t2;
|
|
1967
|
+
$[19] = t3;
|
|
1968
|
+
} else t3 = $[19];
|
|
1969
|
+
return t3;
|
|
1970
|
+
}
|
|
1971
|
+
function FastIntrinsicElementBody(t0) {
|
|
1972
|
+
const $ = c(27);
|
|
1973
|
+
const { attributes, blockId, children, editor, element, isVoidTag, path, plugin, renderBelowNodes, tag: Tag } = t0;
|
|
1974
|
+
const readOnly = useReadOnly();
|
|
1975
|
+
let t1;
|
|
1976
|
+
if ($[0] !== attributes || $[1] !== editor || $[2] !== element || $[3] !== path || $[4] !== readOnly) {
|
|
1977
|
+
t1 = {
|
|
1978
|
+
attributes,
|
|
1979
|
+
editor,
|
|
1980
|
+
element,
|
|
1981
|
+
path,
|
|
1982
|
+
readOnly
|
|
1983
|
+
};
|
|
1984
|
+
$[0] = attributes;
|
|
1985
|
+
$[1] = editor;
|
|
1986
|
+
$[2] = element;
|
|
1987
|
+
$[3] = path;
|
|
1988
|
+
$[4] = readOnly;
|
|
1989
|
+
$[5] = t1;
|
|
1990
|
+
} else t1 = $[5];
|
|
1991
|
+
const injectedAttributes = useFastInjectedAttributes(t1);
|
|
1992
|
+
const ref = useBlockIdAttributeRef(blockId, injectedAttributes.ref);
|
|
1993
|
+
let elementChildren;
|
|
1994
|
+
if ($[6] !== attributes || $[7] !== children || $[8] !== editor || $[9] !== element || $[10] !== path || $[11] !== plugin || $[12] !== readOnly || $[13] !== renderBelowNodes) {
|
|
1995
|
+
elementChildren = children;
|
|
1996
|
+
if (renderBelowNodes) {
|
|
1997
|
+
const nodeProps = {
|
|
1998
|
+
attributes,
|
|
1999
|
+
children,
|
|
2000
|
+
editor,
|
|
2001
|
+
element,
|
|
2002
|
+
path,
|
|
2003
|
+
plugin
|
|
2004
|
+
};
|
|
2005
|
+
editor.meta.pluginCache.render.belowNodes.forEach((key) => {
|
|
2006
|
+
const wrapperPlugin = editor.getPlugin({ key });
|
|
2007
|
+
if (isEditOnly(readOnly, wrapperPlugin, "render")) return;
|
|
2008
|
+
const hoc = wrapperPlugin.render.belowNodes({
|
|
2009
|
+
...nodeProps,
|
|
2010
|
+
key
|
|
2011
|
+
});
|
|
2012
|
+
if (hoc) elementChildren = hoc({
|
|
2013
|
+
...nodeProps,
|
|
2014
|
+
children: elementChildren
|
|
2015
|
+
});
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
$[6] = attributes;
|
|
2019
|
+
$[7] = children;
|
|
2020
|
+
$[8] = editor;
|
|
2021
|
+
$[9] = element;
|
|
2022
|
+
$[10] = path;
|
|
2023
|
+
$[11] = plugin;
|
|
2024
|
+
$[12] = readOnly;
|
|
2025
|
+
$[13] = renderBelowNodes;
|
|
2026
|
+
$[14] = elementChildren;
|
|
2027
|
+
} else elementChildren = $[14];
|
|
2028
|
+
const t2 = injectedAttributes["data-slate-inline"];
|
|
2029
|
+
let t3;
|
|
2030
|
+
if ($[15] !== injectedAttributes.style) {
|
|
2031
|
+
t3 = {
|
|
2032
|
+
position: "relative",
|
|
2033
|
+
...injectedAttributes.style
|
|
2034
|
+
};
|
|
2035
|
+
$[15] = injectedAttributes.style;
|
|
2036
|
+
$[16] = t3;
|
|
2037
|
+
} else t3 = $[16];
|
|
2038
|
+
const t4 = t3;
|
|
2039
|
+
let t5;
|
|
2040
|
+
if ($[17] !== injectedAttributes || $[18] !== ref || $[19] !== t2 || $[20] !== t4) {
|
|
2041
|
+
t5 = {
|
|
2042
|
+
"data-slate-inline": t2,
|
|
2043
|
+
"data-slate-node": "element",
|
|
2044
|
+
...injectedAttributes,
|
|
2045
|
+
ref,
|
|
2046
|
+
style: t4
|
|
2047
|
+
};
|
|
2048
|
+
$[17] = injectedAttributes;
|
|
2049
|
+
$[18] = ref;
|
|
2050
|
+
$[19] = t2;
|
|
2051
|
+
$[20] = t4;
|
|
2052
|
+
$[21] = t5;
|
|
2053
|
+
} else t5 = $[21];
|
|
2054
|
+
const fastElementProps = t5;
|
|
2055
|
+
let t6;
|
|
2056
|
+
if ($[22] !== Tag || $[23] !== elementChildren || $[24] !== fastElementProps || $[25] !== isVoidTag) {
|
|
2057
|
+
t6 = isVoidTag ? /* @__PURE__ */ React.createElement("div", fastElementProps, /* @__PURE__ */ React.createElement(Tag, { contentEditable: false }), elementChildren) : /* @__PURE__ */ React.createElement(Tag, fastElementProps, elementChildren);
|
|
2058
|
+
$[22] = Tag;
|
|
2059
|
+
$[23] = elementChildren;
|
|
2060
|
+
$[24] = fastElementProps;
|
|
2061
|
+
$[25] = isVoidTag;
|
|
2062
|
+
$[26] = t6;
|
|
2063
|
+
} else t6 = $[26];
|
|
2064
|
+
return t6;
|
|
2065
|
+
}
|
|
2066
|
+
function PluginElementWithPath(t0) {
|
|
2067
|
+
const $ = c(5);
|
|
2068
|
+
const { editor, plugin, props } = t0;
|
|
2069
|
+
const path = useNodePath(props.element);
|
|
2070
|
+
let t1;
|
|
2071
|
+
if ($[0] !== editor || $[1] !== path || $[2] !== plugin || $[3] !== props) {
|
|
2072
|
+
t1 = pluginRenderElement(editor, plugin)({
|
|
1423
2073
|
...props,
|
|
1424
2074
|
path
|
|
1425
2075
|
});
|
|
1426
|
-
|
|
2076
|
+
$[0] = editor;
|
|
2077
|
+
$[1] = path;
|
|
2078
|
+
$[2] = plugin;
|
|
2079
|
+
$[3] = props;
|
|
2080
|
+
$[4] = t1;
|
|
2081
|
+
} else t1 = $[4];
|
|
2082
|
+
return t1;
|
|
2083
|
+
}
|
|
2084
|
+
function RenderElementPropWithPath(t0) {
|
|
2085
|
+
const $ = c(4);
|
|
2086
|
+
const { props, renderElementProp } = t0;
|
|
2087
|
+
const path = useNodePath(props.element);
|
|
2088
|
+
let t1;
|
|
2089
|
+
if ($[0] !== path || $[1] !== props || $[2] !== renderElementProp) {
|
|
2090
|
+
t1 = renderElementProp({
|
|
1427
2091
|
...props,
|
|
1428
2092
|
path
|
|
1429
2093
|
});
|
|
1430
|
-
|
|
2094
|
+
$[0] = path;
|
|
2095
|
+
$[1] = props;
|
|
2096
|
+
$[2] = renderElementProp;
|
|
2097
|
+
$[3] = t1;
|
|
2098
|
+
} else t1 = $[3];
|
|
2099
|
+
return t1;
|
|
2100
|
+
}
|
|
2101
|
+
function DefaultElementWithPath(t0) {
|
|
2102
|
+
const $ = c(20);
|
|
2103
|
+
const { editor, props } = t0;
|
|
2104
|
+
const readOnly = useReadOnly();
|
|
2105
|
+
const path = useNodePath(props.element);
|
|
2106
|
+
let t1;
|
|
2107
|
+
if ($[0] !== editor || $[1] !== path || $[2] !== props || $[3] !== readOnly) {
|
|
2108
|
+
t1 = getRenderNodeProps({
|
|
1431
2109
|
disableInjectNodeProps: true,
|
|
1432
2110
|
editor,
|
|
1433
2111
|
props: {
|
|
@@ -1436,12 +2114,121 @@ const pipeRenderElement = (editor, renderElementProp) => {
|
|
|
1436
2114
|
},
|
|
1437
2115
|
readOnly
|
|
1438
2116
|
});
|
|
1439
|
-
|
|
2117
|
+
$[0] = editor;
|
|
2118
|
+
$[1] = path;
|
|
2119
|
+
$[2] = props;
|
|
2120
|
+
$[3] = readOnly;
|
|
2121
|
+
$[4] = t1;
|
|
2122
|
+
} else t1 = $[4];
|
|
2123
|
+
const ctxProps = t1;
|
|
2124
|
+
let t2;
|
|
2125
|
+
if ($[5] !== ctxProps.element || $[6] !== path) {
|
|
2126
|
+
t2 = [ctxProps.element, path];
|
|
2127
|
+
$[5] = ctxProps.element;
|
|
2128
|
+
$[6] = path;
|
|
2129
|
+
$[7] = t2;
|
|
2130
|
+
} else t2 = $[7];
|
|
2131
|
+
const t3 = ctxProps.element.type ?? "default";
|
|
2132
|
+
let t4;
|
|
2133
|
+
if ($[8] !== ctxProps) {
|
|
2134
|
+
t4 = /* @__PURE__ */ React.createElement(BelowRootNodes, ctxProps);
|
|
2135
|
+
$[8] = ctxProps;
|
|
2136
|
+
$[9] = t4;
|
|
2137
|
+
} else t4 = $[9];
|
|
2138
|
+
let t5;
|
|
2139
|
+
if ($[10] !== ctxProps || $[11] !== props.children || $[12] !== t4) {
|
|
2140
|
+
t5 = /* @__PURE__ */ React.createElement(PlateElement, ctxProps, props.children, t4);
|
|
2141
|
+
$[10] = ctxProps;
|
|
2142
|
+
$[11] = props.children;
|
|
2143
|
+
$[12] = t4;
|
|
2144
|
+
$[13] = t5;
|
|
2145
|
+
} else t5 = $[13];
|
|
2146
|
+
let t6;
|
|
2147
|
+
if ($[14] !== ctxProps.element || $[15] !== path || $[16] !== t2 || $[17] !== t3 || $[18] !== t5) {
|
|
2148
|
+
t6 = /* @__PURE__ */ React.createElement(ElementProvider, {
|
|
1440
2149
|
element: ctxProps.element,
|
|
1441
|
-
entry:
|
|
2150
|
+
entry: t2,
|
|
1442
2151
|
path,
|
|
1443
|
-
scope:
|
|
1444
|
-
},
|
|
2152
|
+
scope: t3
|
|
2153
|
+
}, t5);
|
|
2154
|
+
$[14] = ctxProps.element;
|
|
2155
|
+
$[15] = path;
|
|
2156
|
+
$[16] = t2;
|
|
2157
|
+
$[17] = t3;
|
|
2158
|
+
$[18] = t5;
|
|
2159
|
+
$[19] = t6;
|
|
2160
|
+
} else t6 = $[19];
|
|
2161
|
+
return t6;
|
|
2162
|
+
}
|
|
2163
|
+
/** @see {@link RenderElement} */
|
|
2164
|
+
const pipeRenderElement = (editor, renderElementProp) => {
|
|
2165
|
+
const hasAboveNodes = editor.meta.pluginCache.render.aboveNodes.length > 0;
|
|
2166
|
+
const hasBelowRootNodes = editor.meta.pluginCache.render.belowRootNodes.length > 0;
|
|
2167
|
+
return function render(props) {
|
|
2168
|
+
const plugin = getPluginByType(editor, props.element.type);
|
|
2169
|
+
if (plugin?.node.isElement) {
|
|
2170
|
+
if (!hasAboveNodes && !hasBelowRootNodes && !plugin.render.node && !plugin.node.props && !plugin.node.dangerouslyAllowAttributes?.length) {
|
|
2171
|
+
const readOnly = editor.dom.readOnly;
|
|
2172
|
+
if (isEditOnly(readOnly, plugin, "render")) return null;
|
|
2173
|
+
const blockId = props.element.id && editor.api.isBlock(props.element) ? props.element.id : void 0;
|
|
2174
|
+
const inset = plugin.rules.selection?.affinity === "directional";
|
|
2175
|
+
const attributes = {
|
|
2176
|
+
...props.attributes,
|
|
2177
|
+
className: [getSlateClass(plugin.node.type), props.attributes?.className].filter(Boolean).join(" ") || void 0
|
|
2178
|
+
};
|
|
2179
|
+
const renderAs = plugin.render?.as ?? "div";
|
|
2180
|
+
const isIntrinsicTag = typeof renderAs === "string";
|
|
2181
|
+
const Tag = renderAs;
|
|
2182
|
+
const isVoidTag = isIntrinsicTag && isHtmlVoidElementTag(Tag);
|
|
2183
|
+
const hasBelowNodeWrappers = editor.meta.pluginCache.render.belowNodes.some((key) => {
|
|
2184
|
+
return !isEditOnly(readOnly, editor.getPlugin({ key }), "render");
|
|
2185
|
+
});
|
|
2186
|
+
if (!inset && !hasBelowNodeWrappers && isIntrinsicTag) return /* @__PURE__ */ React.createElement(FastIntrinsicElement, {
|
|
2187
|
+
attributes,
|
|
2188
|
+
blockId,
|
|
2189
|
+
editor,
|
|
2190
|
+
element: props.element,
|
|
2191
|
+
isVoidTag,
|
|
2192
|
+
plugin,
|
|
2193
|
+
renderBelowNodes: false,
|
|
2194
|
+
tag: Tag
|
|
2195
|
+
}, props.children);
|
|
2196
|
+
if (!inset && hasBelowNodeWrappers && isIntrinsicTag) return /* @__PURE__ */ React.createElement(FastIntrinsicElement, {
|
|
2197
|
+
attributes,
|
|
2198
|
+
blockId,
|
|
2199
|
+
editor,
|
|
2200
|
+
element: props.element,
|
|
2201
|
+
isVoidTag,
|
|
2202
|
+
plugin,
|
|
2203
|
+
renderBelowNodes: true,
|
|
2204
|
+
tag: Tag
|
|
2205
|
+
}, props.children);
|
|
2206
|
+
if (!hasBelowNodeWrappers && isIntrinsicTag) return /* @__PURE__ */ React.createElement(FastElementWithPath, {
|
|
2207
|
+
attributes,
|
|
2208
|
+
editor,
|
|
2209
|
+
element: props.element,
|
|
2210
|
+
plugin
|
|
2211
|
+
}, props.children);
|
|
2212
|
+
return /* @__PURE__ */ React.createElement(PluginElementWithPath, {
|
|
2213
|
+
editor,
|
|
2214
|
+
plugin,
|
|
2215
|
+
props
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2218
|
+
return /* @__PURE__ */ React.createElement(PluginElementWithPath, {
|
|
2219
|
+
editor,
|
|
2220
|
+
plugin,
|
|
2221
|
+
props
|
|
2222
|
+
});
|
|
2223
|
+
}
|
|
2224
|
+
if (renderElementProp) return /* @__PURE__ */ React.createElement(RenderElementPropWithPath, {
|
|
2225
|
+
props,
|
|
2226
|
+
renderElementProp
|
|
2227
|
+
});
|
|
2228
|
+
return /* @__PURE__ */ React.createElement(DefaultElementWithPath, {
|
|
2229
|
+
editor,
|
|
2230
|
+
props
|
|
2231
|
+
});
|
|
1445
2232
|
};
|
|
1446
2233
|
};
|
|
1447
2234
|
|
|
@@ -1780,7 +2567,7 @@ const useElement = (t0) => {
|
|
|
1780
2567
|
const $ = c(1);
|
|
1781
2568
|
const pluginKey = t0 === void 0 ? SCOPE_ELEMENT : t0;
|
|
1782
2569
|
const editor = useEditorRef();
|
|
1783
|
-
const value =
|
|
2570
|
+
const value = useElementContext(pluginKey)?.element;
|
|
1784
2571
|
if (!value) {
|
|
1785
2572
|
editor.api.debug.warn(`useElement(${pluginKey}) hook must be used inside the node component's context`, "USE_ELEMENT_CONTEXT");
|
|
1786
2573
|
let t1;
|
|
@@ -1796,8 +2583,62 @@ const useElement = (t0) => {
|
|
|
1796
2583
|
//#endregion
|
|
1797
2584
|
//#region src/react/stores/element/useElementSelector.ts
|
|
1798
2585
|
const useElementSelector = (selector, deps, { key, equalityFn = (a, b) => a === b } = {}) => {
|
|
1799
|
-
const
|
|
1800
|
-
|
|
2586
|
+
const context = useElementStoreContext(key);
|
|
2587
|
+
const [memoizedSelector, memoizedEqualityFn] = React.useMemo(() => [selector, equalityFn], deps);
|
|
2588
|
+
const cacheRef = React.useRef({
|
|
2589
|
+
entry: null,
|
|
2590
|
+
hasValue: false,
|
|
2591
|
+
runtime: null,
|
|
2592
|
+
selector: null,
|
|
2593
|
+
value: void 0
|
|
2594
|
+
});
|
|
2595
|
+
const subscribe = React.useCallback((onStoreChange) => context?.runtime.subscribe(onStoreChange) ?? (() => {}), [context]);
|
|
2596
|
+
const getSnapshot = React.useCallback(() => {
|
|
2597
|
+
const runtime = context?.runtime ?? null;
|
|
2598
|
+
const cache = cacheRef.current;
|
|
2599
|
+
if (cache.runtime !== runtime || cache.selector !== memoizedSelector) {
|
|
2600
|
+
cache.entry = null;
|
|
2601
|
+
cache.hasValue = false;
|
|
2602
|
+
cache.runtime = runtime;
|
|
2603
|
+
cache.selector = memoizedSelector;
|
|
2604
|
+
cache.value = void 0;
|
|
2605
|
+
}
|
|
2606
|
+
const entry = runtime?.getState().entry ?? null;
|
|
2607
|
+
if (cache.entry === entry && cache.hasValue) return cache.value;
|
|
2608
|
+
if (!entry) {
|
|
2609
|
+
cache.entry = null;
|
|
2610
|
+
cache.hasValue = false;
|
|
2611
|
+
cache.value = void 0;
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
const nextValue = memoizedSelector(entry, cache.hasValue ? cache.value : void 0);
|
|
2615
|
+
if (cache.hasValue && memoizedEqualityFn(cache.value, nextValue)) {
|
|
2616
|
+
cache.entry = entry;
|
|
2617
|
+
return cache.value;
|
|
2618
|
+
}
|
|
2619
|
+
cache.entry = entry;
|
|
2620
|
+
cache.hasValue = true;
|
|
2621
|
+
cache.value = nextValue;
|
|
2622
|
+
return nextValue;
|
|
2623
|
+
}, [
|
|
2624
|
+
context,
|
|
2625
|
+
memoizedEqualityFn,
|
|
2626
|
+
memoizedSelector
|
|
2627
|
+
]);
|
|
2628
|
+
return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
2629
|
+
};
|
|
2630
|
+
|
|
2631
|
+
//#endregion
|
|
2632
|
+
//#region src/react/stores/element/usePath.ts
|
|
2633
|
+
/** Get the memoized path of the closest element. */
|
|
2634
|
+
const usePath = (pluginKey) => {
|
|
2635
|
+
const editor = useEditorRef();
|
|
2636
|
+
const value = useElementContext(pluginKey)?.path;
|
|
2637
|
+
if (!value) {
|
|
2638
|
+
editor.api.debug.warn(`usePath(${pluginKey}) hook must be used inside the node component's context`, "USE_ELEMENT_CONTEXT");
|
|
2639
|
+
return;
|
|
2640
|
+
}
|
|
2641
|
+
return value;
|
|
1801
2642
|
};
|
|
1802
2643
|
|
|
1803
2644
|
//#endregion
|
|
@@ -2621,4 +3462,4 @@ const withHOC = (HOC, Component, hocProps, hocRef) => React.forwardRef((props, c
|
|
|
2621
3462
|
});
|
|
2622
3463
|
|
|
2623
3464
|
//#endregion
|
|
2624
|
-
export { BLUR_EDITOR_EVENT, BelowRootNodes, ContentVisibilityChunk, DOM_HANDLERS, DefaultPlaceholder, Editable, EditorHotkeysEffect, EditorMethodsEffect, EditorRefEffect, EditorRefPluginEffect, ElementProvider, EventEditorPlugin, EventEditorStore, FOCUS_EDITOR_EVENT, GLOBAL_PLATE_SCOPE, NavigationFeedbackPlugin, PLATE_SCOPE, ParagraphPlugin, Plate, PlateContainer, PlateContent, PlateController, PlateControllerEffect, PlateElement, PlateLeaf, PlateSlate, PlateStoreProvider, PlateTest, PlateText, PlateView, ReactPlugin, SCOPE_ELEMENT, Slate, SlateReactExtensionPlugin, atom, convertDomEventToSyntheticEvent, createAtomStore, createPlateEditor, createPlateFallbackEditor, createPlatePlugin, createPlateStore, createTPlatePlugin, createZustandStore, elementStore, getEditorPlugin, getEventPlateId, getPlateCorePlugins, getPlugin, getRenderNodeProps, isEventHandled, omitPluginContext, pipeHandler, pipeOnChange, pipeRenderElement, pipeRenderLeaf, pipeRenderText, plateControllerStore, plateStore, pluginRenderElement, pluginRenderLeaf, pluginRenderText, toPlatePlugin, toTPlatePlugin, useComposing, useEditableProps, useEditorComposing, useEditorContainerRef, useEditorId, useEditorMounted, useEditorPlugin, useEditorPluginOption, useEditorPluginOptions, useEditorReadOnly, useEditorRef, useEditorScrollRef, useEditorSelection, useEditorSelector, useEditorState, useEditorValue, useEditorVersion, useElement, useElementSelector, useElementStore, useEventEditorValue, useEventPlateId, useFocusEditorEvents, useFocused, useFocusedLast, useIncrementVersion, useNavigationHighlight, useNodeAttributes, useNodePath, usePath, usePlateControllerExists, usePlateControllerLocalStore, usePlateControllerStore, usePlateEditor, usePlateLocalStore, usePlateSet, usePlateState, usePlateStore, usePlateValue, usePlateViewEditor, usePluginOption, usePluginOptions, useReadOnly, useRedecorate, useScrollRef, useSelected, useSelectionVersion, useSlateProps, useSlateStatic, useStoreAtomState, useStoreAtomValue, useStoreSelect, useStoreSetAtom, useStoreState, useStoreValue, useTracked, useTrackedStore, useValueVersion, withHOC, withPlate, withPlateReact, withReact };
|
|
3465
|
+
export { BLUR_EDITOR_EVENT, BelowRootNodes, ContentVisibilityChunk, DOM_HANDLERS, DefaultPlaceholder, Editable, EditorHotkeysEffect, EditorMethodsEffect, EditorRefEffect, EditorRefPluginEffect, ElementProvider, EventEditorPlugin, EventEditorStore, FOCUS_EDITOR_EVENT, FirstBlockEffect, GLOBAL_PLATE_SCOPE, NavigationFeedbackPlugin, PLATE_SCOPE, ParagraphPlugin, Plate, PlateContainer, PlateContent, PlateController, PlateControllerEffect, PlateElement, PlateLeaf, PlateSlate, PlateStoreProvider, PlateTest, PlateText, PlateView, ReactPlugin, SCOPE_ELEMENT, Slate, SlateReactExtensionPlugin, atom, convertDomEventToSyntheticEvent, createAtomStore, createPlateEditor, createPlateFallbackEditor, createPlatePlugin, createPlateStore, createTPlatePlugin, createZustandStore, elementStore, getEditorPlugin, getEventPlateId, getPlateCorePlugins, getPlugin, getRenderNodeProps, isEventHandled, isHtmlVoidElementTag, omitPluginContext, pipeHandler, pipeOnChange, pipeRenderElement, pipeRenderLeaf, pipeRenderText, plateControllerStore, plateStore, pluginRenderElement, pluginRenderLeaf, pluginRenderText, toPlatePlugin, toTPlatePlugin, useBlockIdAttributeRef, useComposing, useEditableProps, useEditorComposing, useEditorContainerRef, useEditorId, useEditorMounted, useEditorPlugin, useEditorPluginOption, useEditorPluginOptions, useEditorReadOnly, useEditorRef, useEditorScrollRef, useEditorSelection, useEditorSelector, useEditorState, useEditorValue, useEditorVersion, useElement, useElementContext, useElementSelector, useElementStore, useElementStoreContext, useEventEditorValue, useEventPlateId, useFocusEditorEvents, useFocused, useFocusedLast, useIncrementVersion, useNavigationHighlight, useNodeAttributes, useNodePath, usePath, usePlateControllerExists, usePlateControllerLocalStore, usePlateControllerStore, usePlateEditor, usePlateLocalStore, usePlateSet, usePlateState, usePlateStore, usePlateValue, usePlateViewEditor, usePluginOption, usePluginOptions, useReadOnly, useRedecorate, useScrollRef, useSelected, useSelectionVersion, useSlateProps, useSlateStatic, useStoreAtomState, useStoreAtomValue, useStoreSelect, useStoreSetAtom, useStoreState, useStoreValue, useTracked, useTrackedStore, useValueVersion, withElementContext, withHOC, withPlate, withPlateReact, withReact };
|