Skip to content

Commit

Permalink
chore: add event to get all entries in a page
Browse files Browse the repository at this point in the history
  • Loading branch information
sairajchouhan committed Jan 29, 2024
1 parent 88e2f3e commit 1e48bda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/liveEditor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from "./utils/getCsDataOfElement";
import liveEditorPostMessage from "./utils/liveEditorPostMessage";
import { LiveEditorPostMessageEvents } from "./utils/types/postMessage.types";
import { addCslpOutline } from "../utils/cslpdata";
import { addCslpOutline, extractDetailsFromCslp } from "../utils/cslpdata";
import Config from "../utils/configHandler";
import { ILivePreviewWindowType } from "../types/types";
import { inIframe } from "../utils/inIframe";
Expand Down Expand Up @@ -116,6 +116,30 @@ export class VisualEditor {
window.addEventListener("mouseover", (event) => {
addCslpOutline(event);
});

liveEditorPostMessage?.on(
LiveEditorPostMessageEvents.GET_ENTRY_UID_IN_CURRENT_PAGE,
() => {
const elementsWithCslp = Array.from(
document.querySelectorAll("[data-cslp]")
);
const entryUidsInCurrentPage = elementsWithCslp.map(
(element) => {
return extractDetailsFromCslp(
element.getAttribute("data-cslp") as string
).entry_uid;
}
);
const uniqueEntryUidsInCurrentPage = Array.from(
new Set(entryUidsInCurrentPage)
);

return {
entryUidsInCurrentPage:
uniqueEntryUidsInCurrentPage,
};
}
);
})
.catch(() => {
if (!inIframe()) {
Expand Down
1 change: 1 addition & 0 deletions src/liveEditor/utils/types/postMessage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum LiveEditorPostMessageEvents {
FOCUS_FIELD = "focus-field",
DELETE_INSTANCE = "delete-instance",
MOVE_INSTANCE = "move-instance",
GET_ENTRY_UID_IN_CURRENT_PAGE = "get-entry-uid-in-current-page",
}

0 comments on commit 1e48bda

Please sign in to comment.