@openeditor/react 0.0.22 → 0.0.23
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.js +33 -26
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -32904,15 +32904,34 @@ var pageSnapshotFromNode = (node) => {
|
|
|
32904
32904
|
href: typeof node.attrs?.href === "string" ? node.attrs.href : null
|
|
32905
32905
|
};
|
|
32906
32906
|
};
|
|
32907
|
+
var useResolvedPageSnapshot = (cached, runtime) => {
|
|
32908
|
+
const [resolved, setResolved] = useState(null);
|
|
32909
|
+
useEffect(() => {
|
|
32910
|
+
let active = true;
|
|
32911
|
+
setResolved(null);
|
|
32912
|
+
if (cached?.pageId && runtime?.resolvePage) {
|
|
32913
|
+
void runtime.resolvePage(cached.pageId).then((page) => {
|
|
32914
|
+
if (active && page) setResolved(page);
|
|
32915
|
+
}).catch(() => {
|
|
32916
|
+
if (active) setResolved(null);
|
|
32917
|
+
});
|
|
32918
|
+
}
|
|
32919
|
+
return () => {
|
|
32920
|
+
active = false;
|
|
32921
|
+
};
|
|
32922
|
+
}, [cached?.pageId, runtime]);
|
|
32923
|
+
return [resolved ?? cached, setResolved];
|
|
32924
|
+
};
|
|
32907
32925
|
var OpenEditorPageNodeView = ({ editor, node, updateAttributes: updateAttributes2 }) => {
|
|
32908
32926
|
const runtime = use(OpenEditorPageRuntimeContext);
|
|
32909
32927
|
const themeStyle = useOpenEditorThemeStyle();
|
|
32910
32928
|
const [creating, setCreating] = useState(false);
|
|
32911
32929
|
const [error, setError] = useState(null);
|
|
32912
|
-
const
|
|
32913
|
-
const
|
|
32930
|
+
const cached = pageSnapshotFromNode(node);
|
|
32931
|
+
const [page, setResolvedPage] = useResolvedPageSnapshot(cached, runtime);
|
|
32932
|
+
const icon = normalizeEmoji(page?.icon, DEFAULT_PAGE_EMOJI);
|
|
32914
32933
|
const openPage = () => {
|
|
32915
|
-
if (
|
|
32934
|
+
if (page) void runtime?.openPage?.(page);
|
|
32916
32935
|
};
|
|
32917
32936
|
const createPage = async () => {
|
|
32918
32937
|
if (!runtime?.createPage || creating) return;
|
|
@@ -32929,10 +32948,11 @@ var OpenEditorPageNodeView = ({ editor, node, updateAttributes: updateAttributes
|
|
|
32929
32948
|
};
|
|
32930
32949
|
const updateIcon = async (nextIcon) => {
|
|
32931
32950
|
updateAttributes2({ icon: nextIcon });
|
|
32932
|
-
if (!
|
|
32951
|
+
if (!page?.pageId || !runtime?.updatePageIcon) return;
|
|
32952
|
+
setResolvedPage({ ...page, icon: nextIcon });
|
|
32933
32953
|
setError(null);
|
|
32934
32954
|
try {
|
|
32935
|
-
await runtime.updatePageIcon(
|
|
32955
|
+
await runtime.updatePageIcon(page.pageId, nextIcon);
|
|
32936
32956
|
} catch (cause) {
|
|
32937
32957
|
setError(cause instanceof Error ? cause.message : "Could not update the page icon.");
|
|
32938
32958
|
}
|
|
@@ -32940,22 +32960,22 @@ var OpenEditorPageNodeView = ({ editor, node, updateAttributes: updateAttributes
|
|
|
32940
32960
|
return /* @__PURE__ */ jsxs(
|
|
32941
32961
|
NodeViewWrapper,
|
|
32942
32962
|
{
|
|
32943
|
-
"aria-label":
|
|
32963
|
+
"aria-label": page ? `Open ${page.title}` : void 0,
|
|
32944
32964
|
className: "oe-page",
|
|
32945
|
-
"data-page-id":
|
|
32965
|
+
"data-page-id": page?.pageId ?? "",
|
|
32946
32966
|
onClick: (event) => {
|
|
32947
32967
|
if (event.target.closest(".oe-emoji-trigger, .oe-emoji-popover")) return;
|
|
32948
32968
|
openPage();
|
|
32949
32969
|
},
|
|
32950
32970
|
onKeyDown: (event) => {
|
|
32951
32971
|
if (event.target.closest(".oe-emoji-trigger, .oe-emoji-popover")) return;
|
|
32952
|
-
if (
|
|
32972
|
+
if (page && (event.key === "Enter" || event.key === " ")) {
|
|
32953
32973
|
event.preventDefault();
|
|
32954
32974
|
openPage();
|
|
32955
32975
|
}
|
|
32956
32976
|
},
|
|
32957
|
-
role:
|
|
32958
|
-
tabIndex:
|
|
32977
|
+
role: page ? "button" : void 0,
|
|
32978
|
+
tabIndex: page ? 0 : void 0,
|
|
32959
32979
|
children: [
|
|
32960
32980
|
/* @__PURE__ */ jsx("span", { contentEditable: false, children: /* @__PURE__ */ jsx(
|
|
32961
32981
|
OpenEditorEmojiPicker,
|
|
@@ -32968,7 +32988,7 @@ var OpenEditorPageNodeView = ({ editor, node, updateAttributes: updateAttributes
|
|
|
32968
32988
|
onEmojiSelect: (nextIcon) => void updateIcon(nextIcon)
|
|
32969
32989
|
}
|
|
32970
32990
|
) }),
|
|
32971
|
-
/* @__PURE__ */ jsx(
|
|
32991
|
+
page && page !== cached ? /* @__PURE__ */ jsx("div", { className: "oe-page-title", contentEditable: false, children: page.title }) : /* @__PURE__ */ jsx(
|
|
32972
32992
|
NodeViewContent,
|
|
32973
32993
|
{
|
|
32974
32994
|
as: "div",
|
|
@@ -32976,7 +32996,7 @@ var OpenEditorPageNodeView = ({ editor, node, updateAttributes: updateAttributes
|
|
|
32976
32996
|
contentEditable: false
|
|
32977
32997
|
}
|
|
32978
32998
|
),
|
|
32979
|
-
!
|
|
32999
|
+
!page && runtime?.createPage && editor.isEditable ? /* @__PURE__ */ jsx(
|
|
32980
33000
|
"button",
|
|
32981
33001
|
{
|
|
32982
33002
|
className: "oe-page-action",
|
|
@@ -33015,20 +33035,7 @@ var Page = Node3.create({
|
|
|
33015
33035
|
var OpenEditorPageViewer = ({ node }) => {
|
|
33016
33036
|
const runtime = use(OpenEditorPageRuntimeContext);
|
|
33017
33037
|
const cached = pageSnapshotFromNode(node);
|
|
33018
|
-
const [
|
|
33019
|
-
useEffect(() => {
|
|
33020
|
-
let active = true;
|
|
33021
|
-
setResolved(null);
|
|
33022
|
-
if (cached?.pageId && runtime?.resolvePage) {
|
|
33023
|
-
void runtime.resolvePage(cached.pageId).then((page2) => {
|
|
33024
|
-
if (active && page2) setResolved(page2);
|
|
33025
|
-
});
|
|
33026
|
-
}
|
|
33027
|
-
return () => {
|
|
33028
|
-
active = false;
|
|
33029
|
-
};
|
|
33030
|
-
}, [cached?.pageId, runtime]);
|
|
33031
|
-
const page = resolved ?? cached;
|
|
33038
|
+
const [page] = useResolvedPageSnapshot(cached, runtime);
|
|
33032
33039
|
const title = page?.title ?? (getNodeText(node) || "Untitled");
|
|
33033
33040
|
const content = /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
33034
33041
|
/* @__PURE__ */ jsx("span", { className: "oe-page-icon", "aria-hidden": "true", children: normalizeEmoji(page?.icon, DEFAULT_PAGE_EMOJI) }),
|