@simpleview/cms-foundation 0.0.5 → 0.0.7
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/components/Preview/PreviewCivWrapper.js +29 -0
- package/dist/components/Preview/PreviewCivWrapper.js.map +7 -0
- package/dist/components/Preview/PreviewContent.js +14 -0
- package/dist/components/Preview/PreviewContent.js.map +7 -0
- package/dist/components/Preview/PreviewPageWrapper.js +91 -0
- package/dist/components/Preview/PreviewPageWrapper.js.map +7 -0
- package/dist/components/Preview/index.js +8 -0
- package/dist/components/Preview/index.js.map +7 -0
- package/dist/components/Section/Section.js +2 -22
- package/dist/components/Section/Section.js.map +2 -2
- package/dist/components/Section/SectionItem.js +15 -0
- package/dist/components/Section/SectionItem.js.map +7 -0
- package/dist/components/Section/SectionItemCiv.js +23 -0
- package/dist/components/Section/SectionItemCiv.js.map +7 -0
- package/dist/components/Section/index.js +2 -0
- package/dist/components/Section/index.js.map +2 -2
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +2 -2
- package/dist/contexts/ComponentMapContext.js +1 -1
- package/dist/contexts/ComponentMapContext.js.map +2 -2
- package/dist/types/components/Preview/PreviewCivWrapper.d.ts +7 -0
- package/dist/types/components/Preview/PreviewContent.d.ts +1 -0
- package/dist/types/components/Preview/PreviewPageWrapper.d.ts +12 -0
- package/dist/types/components/Preview/index.d.ts +4 -0
- package/dist/types/components/Section/SectionItem.d.ts +2 -0
- package/dist/types/components/Section/SectionItemCiv.d.ts +2 -0
- package/dist/types/components/Section/index.d.ts +2 -0
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/types/cms.d.ts +1 -1
- package/dist/utils/getPageContent.js +21 -9
- package/dist/utils/getPageContent.js.map +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
function PreviewCivWrapper({
|
|
3
|
+
children,
|
|
4
|
+
civid,
|
|
5
|
+
onCivEnter,
|
|
6
|
+
highlighted,
|
|
7
|
+
register
|
|
8
|
+
}) {
|
|
9
|
+
const onMouseEnter = (e) => {
|
|
10
|
+
e.stopPropagation();
|
|
11
|
+
onCivEnter(civid);
|
|
12
|
+
};
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
"div",
|
|
15
|
+
{
|
|
16
|
+
style: highlighted === civid ? {
|
|
17
|
+
outlineOffset: 5,
|
|
18
|
+
outline: "rgb(217, 83, 30) solid 7px"
|
|
19
|
+
} : void 0,
|
|
20
|
+
onMouseEnter,
|
|
21
|
+
ref: register(civid),
|
|
22
|
+
children
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
PreviewCivWrapper
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=PreviewCivWrapper.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Preview/PreviewCivWrapper.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { PropsWithChildren, MouseEventHandler } from \"react\";\r\nimport type { PreviewContextState } from \"./PreviewPageWrapper\";\r\n\r\ntype PreviewCivWrapper = PropsWithChildren<{\r\n\tcivid: string;\r\n}> &\r\n\tPreviewContextState;\r\n\r\nexport function PreviewCivWrapper({\r\n\tchildren,\r\n\tcivid,\r\n\tonCivEnter,\r\n\thighlighted,\r\n\tregister,\r\n}: PreviewCivWrapper) {\r\n\tconst onMouseEnter: MouseEventHandler = (e) => {\r\n\t\te.stopPropagation();\r\n\t\tonCivEnter(civid);\r\n\t};\r\n\r\n\treturn (\r\n\t\t<div\r\n\t\t\tstyle={\r\n\t\t\t\thighlighted === civid\r\n\t\t\t\t\t? {\r\n\t\t\t\t\t\t\toutlineOffset: 5,\r\n\t\t\t\t\t\t\toutline: \"rgb(217, 83, 30) solid 7px\",\r\n\t\t\t\t\t }\r\n\t\t\t\t\t: undefined\r\n\t\t\t}\r\n\t\t\tonMouseEnter={onMouseEnter}\r\n\t\t\tref={register(civid)}\r\n\t\t>\r\n\t\t\t{children}\r\n\t\t</div>\r\n\t);\r\n}\r\n"],
|
|
5
|
+
"mappings": "AAqBE;AAbK,SAAS,kBAAkB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAsB;AACrB,QAAM,eAAkC,CAAC,MAAM;AAC9C,MAAE,gBAAgB;AAClB,eAAW,KAAK;AAAA,EACjB;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OACC,gBAAgB,QACb;AAAA,QACA,eAAe;AAAA,QACf,SAAS;AAAA,MACT,IACA;AAAA,MAEJ;AAAA,MACA,KAAK,SAAS,KAAK;AAAA,MAElB;AAAA;AAAA,EACF;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Section } from "@simpleview/cms-foundation/components";
|
|
3
|
+
import { usePreview } from "./PreviewPageWrapper";
|
|
4
|
+
function PreviewContent() {
|
|
5
|
+
const preview = usePreview();
|
|
6
|
+
if (!preview || !preview.pageData) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return /* @__PURE__ */ jsx(Section, { section: [preview.pageData.body] });
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
PreviewContent
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=PreviewContent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Preview/PreviewContent.tsx"],
|
|
4
|
+
"sourcesContent": ["import { Section } from \"@simpleview/cms-foundation/components\";\r\nimport { usePreview } from \"./PreviewPageWrapper\";\r\n\r\nexport function PreviewContent() {\r\n\tconst preview = usePreview();\r\n\r\n\tif (!preview || !preview.pageData) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\treturn <Section section={[preview.pageData.body]} />;\r\n}\r\n"],
|
|
5
|
+
"mappings": "AAUQ;AAVR,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAEpB,SAAS,iBAAiB;AAChC,QAAM,UAAU,WAAW;AAE3B,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AAClC,WAAO;AAAA,EACR;AAEA,SAAO,oBAAC,WAAQ,SAAS,CAAC,QAAQ,SAAS,IAAI,GAAG;AACnD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useMemo,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
useRef
|
|
9
|
+
} from "react";
|
|
10
|
+
const PreviewContext = createContext(
|
|
11
|
+
void 0
|
|
12
|
+
);
|
|
13
|
+
const usePreview = () => useContext(PreviewContext);
|
|
14
|
+
const post = (message) => {
|
|
15
|
+
const parent = window.opener || window.parent;
|
|
16
|
+
const fullMessage = typeof message === "string" ? message : {
|
|
17
|
+
...message,
|
|
18
|
+
namespace: "sv_preview"
|
|
19
|
+
};
|
|
20
|
+
parent.postMessage(fullMessage, "*");
|
|
21
|
+
};
|
|
22
|
+
function PreviewPageWrapper({
|
|
23
|
+
children,
|
|
24
|
+
pageContent
|
|
25
|
+
}) {
|
|
26
|
+
const refs = useRef({});
|
|
27
|
+
const [highlighted, setHighlighted] = useState(
|
|
28
|
+
void 0
|
|
29
|
+
);
|
|
30
|
+
const [pageData, setPageData] = useState(
|
|
31
|
+
pageContent
|
|
32
|
+
);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setPageData(pageContent);
|
|
35
|
+
}, [pageContent]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
post("init");
|
|
38
|
+
const handleMessage = ({ data }) => {
|
|
39
|
+
if (!data || !("namespace" in data) || data.namespace !== "sv_preview" || !("event" in data) || !("args" in data)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const { event, args } = data;
|
|
43
|
+
if (event === "highlight") {
|
|
44
|
+
setHighlighted(args.civid);
|
|
45
|
+
}
|
|
46
|
+
if (event === "scrollTo") {
|
|
47
|
+
if (!refs.current[args.civid]) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
refs.current[args.civid].scrollIntoView({
|
|
51
|
+
behavior: "smooth",
|
|
52
|
+
block: "nearest"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (event === "update") {
|
|
56
|
+
setPageData((prevPageData) => {
|
|
57
|
+
if (!prevPageData) return null;
|
|
58
|
+
return { ...prevPageData, body: args.body };
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
window.addEventListener("message", handleMessage);
|
|
63
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
64
|
+
}, [setPageData]);
|
|
65
|
+
const previewContextState = useMemo(
|
|
66
|
+
() => ({
|
|
67
|
+
register: (civid) => {
|
|
68
|
+
return (ref) => refs.current[civid] = ref;
|
|
69
|
+
},
|
|
70
|
+
onCivEnter: (civid) => {
|
|
71
|
+
post({
|
|
72
|
+
event: "pbScrollTo",
|
|
73
|
+
args: { civid }
|
|
74
|
+
});
|
|
75
|
+
post({
|
|
76
|
+
event: "pbHighlight",
|
|
77
|
+
args: { civid }
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
highlighted,
|
|
81
|
+
pageData
|
|
82
|
+
}),
|
|
83
|
+
[highlighted, pageData]
|
|
84
|
+
);
|
|
85
|
+
return /* @__PURE__ */ jsx(PreviewContext.Provider, { value: previewContextState, children });
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
PreviewPageWrapper,
|
|
89
|
+
usePreview
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=PreviewPageWrapper.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Preview/PreviewPageWrapper.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { PropsWithChildren } from \"react\";\r\nimport {\r\n\tcreateContext,\r\n\tuseContext,\r\n\tuseMemo,\r\n\tuseEffect,\r\n\tuseState,\r\n\tuseRef,\r\n} from \"react\";\r\nimport type { CivProps, PageData } from \"../../types\";\r\n\r\nexport interface PreviewContextState {\r\n\tonCivEnter: (civid: string) => void;\r\n\thighlighted?: string;\r\n\tregister: (civid: string) => (ref: HTMLDivElement) => void;\r\n\tpageData: PageData<CivProps> | null;\r\n}\r\n\r\nconst PreviewContext = createContext<PreviewContextState | undefined>(\r\n\tundefined\r\n);\r\n\r\nexport const usePreview = (): PreviewContextState | undefined =>\r\n\tuseContext(PreviewContext);\r\n\r\ntype PostMessage =\r\n\t| \"init\"\r\n\t| { event: \"pbScrollTo\"; args: { civid: string } }\r\n\t| { event: \"pbHighlight\"; args: { civid: string } }\r\n\t| { event: \"pbUpdate\"; args: { body: CivProps } };\r\n\r\nconst post = (message: PostMessage) => {\r\n\tconst parent = window.opener || window.parent;\r\n\tconst fullMessage =\r\n\t\ttypeof message === \"string\"\r\n\t\t\t? message\r\n\t\t\t: {\r\n\t\t\t\t\t...message,\r\n\t\t\t\t\tnamespace: \"sv_preview\",\r\n\t\t\t };\r\n\r\n\tparent.postMessage(fullMessage, \"*\");\r\n};\r\n\r\nexport function PreviewPageWrapper({\r\n\tchildren,\r\n\tpageContent,\r\n}: PropsWithChildren<{ pageContent: PageData<CivProps> }>) {\r\n\tconst refs = useRef<Record<string, HTMLDivElement>>({});\r\n\tconst [highlighted, setHighlighted] = useState<string | undefined>(\r\n\t\tundefined\r\n\t);\r\n\tconst [pageData, setPageData] = useState<PageData<CivProps> | null>(\r\n\t\tpageContent\r\n\t);\r\n\r\n\tuseEffect(() => {\r\n\t\tsetPageData(pageContent);\r\n\t}, [pageContent]);\r\n\r\n\tuseEffect(() => {\r\n\t\tpost(\"init\");\r\n\r\n\t\tconst handleMessage = ({ data }: WindowEventMap[\"message\"]) => {\r\n\t\t\tif (\r\n\t\t\t\t!data ||\r\n\t\t\t\t!(\"namespace\" in data) ||\r\n\t\t\t\tdata.namespace !== \"sv_preview\" ||\r\n\t\t\t\t!(\"event\" in data) ||\r\n\t\t\t\t!(\"args\" in data)\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst { event, args } = data;\r\n\r\n\t\t\tif (event === \"highlight\") {\r\n\t\t\t\tsetHighlighted(args.civid);\r\n\t\t\t}\r\n\r\n\t\t\tif (event === \"scrollTo\") {\r\n\t\t\t\tif (!refs.current[args.civid]) {\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\trefs.current[args.civid].scrollIntoView({\r\n\t\t\t\t\tbehavior: \"smooth\",\r\n\t\t\t\t\tblock: \"nearest\",\r\n\t\t\t\t});\r\n\t\t\t}\r\n\r\n\t\t\tif (event === \"update\") {\r\n\t\t\t\tsetPageData((prevPageData) => {\r\n\t\t\t\t\tif (!prevPageData) return null;\r\n\t\t\t\t\treturn { ...prevPageData, body: args.body };\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\twindow.addEventListener(\"message\", handleMessage);\r\n\t\treturn () => window.removeEventListener(\"message\", handleMessage);\r\n\t}, [setPageData]);\r\n\r\n\tconst previewContextState = useMemo<PreviewContextState>(\r\n\t\t() => ({\r\n\t\t\tregister: (civid) => {\r\n\t\t\t\treturn (ref) => (refs.current[civid] = ref);\r\n\t\t\t},\r\n\t\t\tonCivEnter: (civid) => {\r\n\t\t\t\tpost({\r\n\t\t\t\t\tevent: \"pbScrollTo\",\r\n\t\t\t\t\targs: { civid },\r\n\t\t\t\t});\r\n\t\t\t\tpost({\r\n\t\t\t\t\tevent: \"pbHighlight\",\r\n\t\t\t\t\targs: { civid },\r\n\t\t\t\t});\r\n\t\t\t},\r\n\t\t\thighlighted,\r\n\t\t\tpageData,\r\n\t\t}),\r\n\t\t[highlighted, pageData]\r\n\t);\r\n\r\n\treturn (\r\n\t\t<PreviewContext.Provider value={previewContextState}>\r\n\t\t\t{children}\r\n\t\t</PreviewContext.Provider>\r\n\t);\r\n}\r\n"],
|
|
5
|
+
"mappings": "AA6HE;AA5HF;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAUP,MAAM,iBAAiB;AAAA,EACtB;AACD;AAEO,MAAM,aAAa,MACzB,WAAW,cAAc;AAQ1B,MAAM,OAAO,CAAC,YAAyB;AACtC,QAAM,SAAS,OAAO,UAAU,OAAO;AACvC,QAAM,cACL,OAAO,YAAY,WAChB,UACA;AAAA,IACA,GAAG;AAAA,IACH,WAAW;AAAA,EACX;AAEJ,SAAO,YAAY,aAAa,GAAG;AACpC;AAEO,SAAS,mBAAmB;AAAA,EAClC;AAAA,EACA;AACD,GAA2D;AAC1D,QAAM,OAAO,OAAuC,CAAC,CAAC;AACtD,QAAM,CAAC,aAAa,cAAc,IAAI;AAAA,IACrC;AAAA,EACD;AACA,QAAM,CAAC,UAAU,WAAW,IAAI;AAAA,IAC/B;AAAA,EACD;AAEA,YAAU,MAAM;AACf,gBAAY,WAAW;AAAA,EACxB,GAAG,CAAC,WAAW,CAAC;AAEhB,YAAU,MAAM;AACf,SAAK,MAAM;AAEX,UAAM,gBAAgB,CAAC,EAAE,KAAK,MAAiC;AAC9D,UACC,CAAC,QACD,EAAE,eAAe,SACjB,KAAK,cAAc,gBACnB,EAAE,WAAW,SACb,EAAE,UAAU,OACX;AACD;AAAA,MACD;AAEA,YAAM,EAAE,OAAO,KAAK,IAAI;AAExB,UAAI,UAAU,aAAa;AAC1B,uBAAe,KAAK,KAAK;AAAA,MAC1B;AAEA,UAAI,UAAU,YAAY;AACzB,YAAI,CAAC,KAAK,QAAQ,KAAK,KAAK,GAAG;AAC9B;AAAA,QACD;AAEA,aAAK,QAAQ,KAAK,KAAK,EAAE,eAAe;AAAA,UACvC,UAAU;AAAA,UACV,OAAO;AAAA,QACR,CAAC;AAAA,MACF;AAEA,UAAI,UAAU,UAAU;AACvB,oBAAY,CAAC,iBAAiB;AAC7B,cAAI,CAAC,aAAc,QAAO;AAC1B,iBAAO,EAAE,GAAG,cAAc,MAAM,KAAK,KAAK;AAAA,QAC3C,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO,iBAAiB,WAAW,aAAa;AAChD,WAAO,MAAM,OAAO,oBAAoB,WAAW,aAAa;AAAA,EACjE,GAAG,CAAC,WAAW,CAAC;AAEhB,QAAM,sBAAsB;AAAA,IAC3B,OAAO;AAAA,MACN,UAAU,CAAC,UAAU;AACpB,eAAO,CAAC,QAAS,KAAK,QAAQ,KAAK,IAAI;AAAA,MACxC;AAAA,MACA,YAAY,CAAC,UAAU;AACtB,aAAK;AAAA,UACJ,OAAO;AAAA,UACP,MAAM,EAAE,MAAM;AAAA,QACf,CAAC;AACD,aAAK;AAAA,UACJ,OAAO;AAAA,UACP,MAAM,EAAE,MAAM;AAAA,QACf,CAAC;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA,CAAC,aAAa,QAAQ;AAAA,EACvB;AAEA,SACC,oBAAC,eAAe,UAAf,EAAwB,OAAO,qBAC9B,UACF;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Preview/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { default } from \"./PreviewPageWrapper\";\r\nexport * from \"./PreviewCivWrapper\";\r\nexport * from \"./PreviewPageWrapper\";\r\nexport * from \"./PreviewContent\";\r\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAAA,gBAAe;AACxB,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { SectionItem } from "./SectionItem";
|
|
3
3
|
function Section({ section }) {
|
|
4
|
-
const map = useComponentMap();
|
|
5
4
|
if (!Array.isArray(section) || !section.length) {
|
|
6
5
|
return null;
|
|
7
6
|
}
|
|
8
|
-
return /* @__PURE__ */ jsx(Fragment, { children: section.map((civ) => {
|
|
9
|
-
if (civ === void 0) {
|
|
10
|
-
return /* @__PURE__ */ jsx(
|
|
11
|
-
map.Error,
|
|
12
|
-
{
|
|
13
|
-
status: 500,
|
|
14
|
-
message: "Is the CMS API running? I bet it isn't \u{1F609}"
|
|
15
|
-
},
|
|
16
|
-
"error"
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
const Component = map.civs[civ.component];
|
|
20
|
-
if (Component === void 0) {
|
|
21
|
-
return /* @__PURE__ */ jsx(map.Unknown, { ...civ }, civ.civid);
|
|
22
|
-
}
|
|
23
|
-
return (
|
|
24
|
-
// <DC.PreviewSectionWrapper key={civ.civid}>
|
|
25
|
-
/* @__PURE__ */ jsx(Component, { ...civ }, civ.civid)
|
|
26
|
-
);
|
|
27
|
-
}) });
|
|
7
|
+
return /* @__PURE__ */ jsx(Fragment, { children: section.map((civ) => /* @__PURE__ */ jsx(SectionItem, { ...civ }, civ.civid)) });
|
|
28
8
|
}
|
|
29
9
|
export {
|
|
30
10
|
Section
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/Section/Section.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { SectionProps } from \"./Section.types\";\r\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { SectionProps } from \"./Section.types\";\r\nimport { SectionItem } from \"./SectionItem\";\r\n\r\nexport function Section({ section }: SectionProps) {\r\n\tif (!Array.isArray(section) || !section.length) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\treturn (\r\n\t\t<>\r\n\t\t\t{section.map((civ) => (\r\n\t\t\t\t<SectionItem key={civ.civid} {...civ} />\r\n\t\t\t))}\r\n\t\t</>\r\n\t);\r\n}\r\n"],
|
|
5
|
+
"mappings": "AASE,mBAEE,WAFF;AARF,SAAS,mBAAmB;AAErB,SAAS,QAAQ,EAAE,QAAQ,GAAiB;AAClD,MAAI,CAAC,MAAM,QAAQ,OAAO,KAAK,CAAC,QAAQ,QAAQ;AAC/C,WAAO;AAAA,EACR;AAEA,SACC,gCACE,kBAAQ,IAAI,CAAC,QACb,oBAAC,eAA6B,GAAG,OAAf,IAAI,KAAgB,CACtC,GACF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PreviewCivWrapper } from "../Preview";
|
|
3
|
+
import { usePreview } from "../Preview/PreviewPageWrapper";
|
|
4
|
+
import { SectionItemCiv } from "./SectionItemCiv";
|
|
5
|
+
function SectionItem(civ) {
|
|
6
|
+
const preview = usePreview();
|
|
7
|
+
if (!preview) {
|
|
8
|
+
return /* @__PURE__ */ jsx(SectionItemCiv, { ...civ });
|
|
9
|
+
}
|
|
10
|
+
return /* @__PURE__ */ jsx(PreviewCivWrapper, { civid: civ.civid, ...preview, children: /* @__PURE__ */ jsx(SectionItemCiv, { ...civ }) });
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
SectionItem
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=SectionItem.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Section/SectionItem.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { CivProps } from \"../../types\";\r\nimport { PreviewCivWrapper } from \"../Preview\";\r\nimport { usePreview } from \"../Preview/PreviewPageWrapper\";\r\nimport { SectionItemCiv } from \"./SectionItemCiv\";\r\n\r\nexport function SectionItem(civ: CivProps) {\r\n\tconst preview = usePreview();\r\n\r\n\tif (!preview) {\r\n\t\treturn <SectionItemCiv {...civ} />;\r\n\t}\r\n\r\n\treturn (\r\n\t\t<PreviewCivWrapper civid={civ.civid} {...preview}>\r\n\t\t\t<SectionItemCiv {...civ} />\r\n\t\t</PreviewCivWrapper>\r\n\t);\r\n}\r\n"],
|
|
5
|
+
"mappings": "AASS;AART,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAExB,SAAS,YAAY,KAAe;AAC1C,QAAM,UAAU,WAAW;AAE3B,MAAI,CAAC,SAAS;AACb,WAAO,oBAAC,kBAAgB,GAAG,KAAK;AAAA,EACjC;AAEA,SACC,oBAAC,qBAAkB,OAAO,IAAI,OAAQ,GAAG,SACxC,8BAAC,kBAAgB,GAAG,KAAK,GAC1B;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useComponentMap } from "../../contexts";
|
|
3
|
+
function SectionItemCiv(civ) {
|
|
4
|
+
const map = useComponentMap();
|
|
5
|
+
if (civ === void 0) {
|
|
6
|
+
return /* @__PURE__ */ jsx(
|
|
7
|
+
map.Error,
|
|
8
|
+
{
|
|
9
|
+
status: 500,
|
|
10
|
+
message: "Is the CMS API running? I bet it isn't \u{1F609}"
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const Component = map.civs[civ.component];
|
|
15
|
+
if (Component === void 0) {
|
|
16
|
+
return /* @__PURE__ */ jsx(map.Unknown, { ...civ });
|
|
17
|
+
}
|
|
18
|
+
return /* @__PURE__ */ jsx(Component, { ...civ });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
SectionItemCiv
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=SectionItemCiv.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Section/SectionItemCiv.tsx"],
|
|
4
|
+
"sourcesContent": ["import { useComponentMap } from \"../../contexts\";\r\nimport type { CivProps } from \"../../types\";\r\n\r\nexport function SectionItemCiv(civ: CivProps) {\r\n\tconst map = useComponentMap();\r\n\r\n\tif (civ === undefined) {\r\n\t\treturn (\r\n\t\t\t<map.Error\r\n\t\t\t\tstatus={500}\r\n\t\t\t\tmessage=\"Is the CMS API running? I bet it isn't \uD83D\uDE09\"\r\n\t\t\t/>\r\n\t\t);\r\n\t}\r\n\r\n\tconst Component = map.civs[civ.component];\r\n\r\n\tif (Component === undefined) {\r\n\t\treturn <map.Unknown {...civ} />;\r\n\t}\r\n\r\n\treturn <Component {...civ} />;\r\n}\r\n"],
|
|
5
|
+
"mappings": "AAQG;AARH,SAAS,uBAAuB;AAGzB,SAAS,eAAe,KAAe;AAC7C,QAAM,MAAM,gBAAgB;AAE5B,MAAI,QAAQ,QAAW;AACtB,WACC;AAAA,MAAC,IAAI;AAAA,MAAJ;AAAA,QACA,QAAQ;AAAA,QACR,SAAQ;AAAA;AAAA,IACT;AAAA,EAEF;AAEA,QAAM,YAAY,IAAI,KAAK,IAAI,SAAS;AAExC,MAAI,cAAc,QAAW;AAC5B,WAAO,oBAAC,IAAI,SAAJ,EAAa,GAAG,KAAK;AAAA,EAC9B;AAEA,SAAO,oBAAC,aAAW,GAAG,KAAK;AAC5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/Section/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from \"./Section\";\r\nexport * from \"./Section.types\";\r\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from \"./Section\";\r\nexport * from \"./SectionItem\";\r\nexport * from \"./SectionItemCiv\";\r\nexport * from \"./Section.types\";\r\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/components/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from \"./App\";\r\nexport * from \"./Error\";\r\nexport * from \"./Layout\";\r\nexport * from \"./Section\";\r\nexport * from \"./Unknown\";\r\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from \"./App\";\r\nexport * from \"./Error\";\r\nexport * from \"./Layout\";\r\nexport * from \"./Preview\";\r\nexport * from \"./Section\";\r\nexport * from \"./Unknown\";\r\nexport * from \"./Preview\";\r\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import { createContext, useContext } from "react";
|
|
|
3
3
|
const ComponentMapContext = createContext({
|
|
4
4
|
civs: {},
|
|
5
5
|
Error,
|
|
6
|
-
Unknown
|
|
6
|
+
Unknown: () => null
|
|
7
7
|
});
|
|
8
8
|
const ComponentMapProvider = ComponentMapContext.Provider;
|
|
9
9
|
const useComponentMap = () => useContext(ComponentMapContext);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/contexts/ComponentMapContext.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Unknown, Error, type ErrorProps } from \"../components\";\r\nimport type { CivProps, ComponentMap } from \"../types\";\r\nimport { createContext, useContext, type FC } from \"react\";\r\n\r\nconst ComponentMapContext = createContext<{\r\n\tcivs: ComponentMap;\r\n\tError: FC<ErrorProps>;\r\n\tUnknown: FC<CivProps>;\r\n}>({\r\n\tcivs: {},\r\n\tError,\r\n\tUnknown,\r\n});\r\n\r\nexport const ComponentMapProvider = ComponentMapContext.Provider;\r\n\r\nexport const useComponentMap = () => useContext(ComponentMapContext);\r\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,aAA8B;AAEhD,SAAS,eAAe,kBAA2B;AAEnD,MAAM,sBAAsB,cAIzB;AAAA,EACF,MAAM,CAAC;AAAA,EACP;AAAA,EACA;
|
|
4
|
+
"sourcesContent": ["import { Unknown, Error, type ErrorProps } from \"../components\";\r\nimport type { CivProps, ComponentMap } from \"../types\";\r\nimport { createContext, useContext, type FC } from \"react\";\r\n\r\nconst ComponentMapContext = createContext<{\r\n\tcivs: ComponentMap;\r\n\tError: FC<ErrorProps>;\r\n\tUnknown: FC<CivProps>;\r\n}>({\r\n\tcivs: {},\r\n\tError,\r\n\tUnknown: () => null,\r\n});\r\n\r\nexport const ComponentMapProvider = ComponentMapContext.Provider;\r\n\r\nexport const useComponentMap = () => useContext(ComponentMapContext);\r\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,aAA8B;AAEhD,SAAS,eAAe,kBAA2B;AAEnD,MAAM,sBAAsB,cAIzB;AAAA,EACF,MAAM,CAAC;AAAA,EACP;AAAA,EACA,SAAS,MAAM;AAChB,CAAC;AAEM,MAAM,uBAAuB,oBAAoB;AAEjD,MAAM,kBAAkB,MAAM,WAAW,mBAAmB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
import type { PreviewContextState } from "./PreviewPageWrapper";
|
|
3
|
+
type PreviewCivWrapper = PropsWithChildren<{
|
|
4
|
+
civid: string;
|
|
5
|
+
}> & PreviewContextState;
|
|
6
|
+
export declare function PreviewCivWrapper({ children, civid, onCivEnter, highlighted, register, }: PreviewCivWrapper): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function PreviewContent(): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
import type { CivProps, PageData } from "../../types";
|
|
3
|
+
export interface PreviewContextState {
|
|
4
|
+
onCivEnter: (civid: string) => void;
|
|
5
|
+
highlighted?: string;
|
|
6
|
+
register: (civid: string) => (ref: HTMLDivElement) => void;
|
|
7
|
+
pageData: PageData<CivProps> | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const usePreview: () => PreviewContextState | undefined;
|
|
10
|
+
export declare function PreviewPageWrapper({ children, pageContent, }: PropsWithChildren<{
|
|
11
|
+
pageContent: PageData<CivProps>;
|
|
12
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { IncomingMessage } from "http";
|
|
2
1
|
import { getCmsUrl } from "./getCmsUrl";
|
|
2
|
+
const previewPath = "/includes/plugins/nav/preview_civs/";
|
|
3
3
|
async function getPageContent(req) {
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
cmsUrl.pathname = parsed_url.pathname + "/content.json";
|
|
4
|
+
const incomingUrl = new URL(req.url, "http://placeholder.com");
|
|
5
|
+
const cmsUrl = getCmsUrl(incomingUrl.host);
|
|
6
|
+
if (/\.[^/]+$/.test(incomingUrl.pathname)) {
|
|
7
|
+
cmsUrl.pathname = incomingUrl.pathname + "/content.json";
|
|
9
8
|
} else {
|
|
10
|
-
cmsUrl.pathname =
|
|
9
|
+
cmsUrl.pathname = incomingUrl.pathname + "content.json";
|
|
11
10
|
}
|
|
12
11
|
const headers = {
|
|
13
12
|
"Accept-Encoding": "gzip",
|
|
@@ -15,10 +14,23 @@ async function getPageContent(req) {
|
|
|
15
14
|
"User-Agent": req.headers.get("user-agent") || ""
|
|
16
15
|
};
|
|
17
16
|
try {
|
|
17
|
+
let body = void 0;
|
|
18
|
+
if (req.method === "POST" && incomingUrl.pathname === previewPath) {
|
|
19
|
+
incomingUrl.searchParams.forEach((val, key) => {
|
|
20
|
+
cmsUrl.searchParams.set(key, val);
|
|
21
|
+
});
|
|
22
|
+
const formData = await req.formData();
|
|
23
|
+
const civs = formData.get("headless_civs");
|
|
24
|
+
const data = JSON.parse(atob(civs));
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
18
27
|
const url = cmsUrl.toString();
|
|
19
28
|
const { method } = req;
|
|
20
|
-
const
|
|
21
|
-
|
|
29
|
+
const fetchParams = {
|
|
30
|
+
method,
|
|
31
|
+
headers,
|
|
32
|
+
body
|
|
33
|
+
};
|
|
22
34
|
console.log("Making page content request:", {
|
|
23
35
|
url,
|
|
24
36
|
...fetchParams
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/getPageContent.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { CivProps, PageData } from \"../types\";\r\nimport { getCmsUrl } from \"./getCmsUrl\";\r\n\r\nexport type { PageData };\r\n\r\nconst previewPath = \"/includes/plugins/nav/preview_civs/\";\r\n\r\nexport async function getPageContent(\r\n\treq: Request\r\n): Promise<PageData<CivProps>> {\r\n\tconst incomingUrl = new URL(req.url, \"http://placeholder.com\");\r\n\tconst cmsUrl = getCmsUrl(incomingUrl.host);\r\n\r\n\tif (/\\.[^/]+$/.test(incomingUrl.pathname)) {\r\n\t\t// If it's a file request, we append /content.json\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"/content.json\";\r\n\t} else {\r\n\t\t// If it's not a file request, we just append content.json since it already ends with a \"/\"\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"content.json\";\r\n\t}\r\n\r\n\tconst headers: Record<string, string> = {\r\n\t\t\"Accept-Encoding\": \"gzip\",\r\n\t\t\"X-Forwarded-For\":\r\n\t\t\treq.headers.get(\"x-real-ip\") ||\r\n\t\t\treq.headers.get(\"x-forwarded-host\") ||\r\n\t\t\t\"\",\r\n\t\t\"User-Agent\": req.headers.get(\"user-agent\") || \"\",\r\n\t};\r\n\r\n\ttry {\r\n\t\tlet body: URLSearchParams | undefined = undefined;\r\n\r\n\t\t/**\r\n\t\t * If this is the live preview page, we need to append the search params from the incoming URL\r\n\t\t * and send the CIVs along with the request.\r\n\t\t */\r\n\t\tif (req.method === \"POST\" && incomingUrl.pathname === previewPath) {\r\n\t\t\tincomingUrl.searchParams.forEach((val, key) => {\r\n\t\t\t\tcmsUrl.searchParams.set(key, val);\r\n\t\t\t});\r\n\r\n\t\t\tconst formData = await req.formData();\r\n\t\t\tconst civs = formData.get(\"headless_civs\");\r\n\t\t\tconst data = JSON.parse(atob(civs));\r\n\r\n\t\t\treturn data;\r\n\t\t}\r\n\r\n\t\tconst url = cmsUrl.toString();\r\n\t\tconst { method } = req;\r\n\t\tconst fetchParams: RequestInit = {\r\n\t\t\tmethod,\r\n\t\t\theaders,\r\n\t\t\tbody,\r\n\t\t};\r\n\r\n\t\tconsole.log(\"Making page content request:\", {\r\n\t\t\turl,\r\n\t\t\t...fetchParams,\r\n\t\t});\r\n\r\n\t\tconst result = await fetch(url, fetchParams).then((res) => res.json());\r\n\t\treturn result;\r\n\t} catch (err: unknown) {\r\n\t\tconst status =\r\n\t\t\t(err as { response?: { status?: number } })?.response?.status ||\r\n\t\t\t500;\r\n\t\tconst message =\r\n\t\t\t(err as { response?: { statusText?: string } })?.response\r\n\t\t\t\t?.statusText || \"Server Error\";\r\n\t\tthrow new Error(`Status ${status}: ${message}`);\r\n\t}\r\n}\r\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,iBAAiB;AAI1B,MAAM,cAAc;AAEpB,eAAsB,eACrB,KAC8B;AAC9B,QAAM,cAAc,IAAI,IAAI,IAAI,KAAK,wBAAwB;AAC7D,QAAM,SAAS,UAAU,YAAY,IAAI;AAEzC,MAAI,WAAW,KAAK,YAAY,QAAQ,GAAG;AAE1C,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C,OAAO;AAEN,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C;AAEA,QAAM,UAAkC;AAAA,IACvC,mBAAmB;AAAA,IACnB,mBACC,IAAI,QAAQ,IAAI,WAAW,KAC3B,IAAI,QAAQ,IAAI,kBAAkB,KAClC;AAAA,IACD,cAAc,IAAI,QAAQ,IAAI,YAAY,KAAK;AAAA,EAChD;AAEA,MAAI;AACH,QAAI,OAAoC;AAMxC,QAAI,IAAI,WAAW,UAAU,YAAY,aAAa,aAAa;AAClE,kBAAY,aAAa,QAAQ,CAAC,KAAK,QAAQ;AAC9C,eAAO,aAAa,IAAI,KAAK,GAAG;AAAA,MACjC,CAAC;AAED,YAAM,WAAW,MAAM,IAAI,SAAS;AACpC,YAAM,OAAO,SAAS,IAAI,eAAe;AACzC,YAAM,OAAO,KAAK,MAAM,KAAK,IAAI,CAAC;AAElC,aAAO;AAAA,IACR;AAEA,UAAM,MAAM,OAAO,SAAS;AAC5B,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,cAA2B;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAEA,YAAQ,IAAI,gCAAgC;AAAA,MAC3C;AAAA,MACA,GAAG;AAAA,IACJ,CAAC;AAED,UAAM,SAAS,MAAM,MAAM,KAAK,WAAW,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC;AACrE,WAAO;AAAA,EACR,SAAS,KAAc;AACtB,UAAM,SACJ,KAA4C,UAAU,UACvD;AACD,UAAM,UACJ,KAAgD,UAC9C,cAAc;AAClB,UAAM,IAAI,MAAM,UAAU,MAAM,KAAK,OAAO,EAAE;AAAA,EAC/C;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simpleview/cms-foundation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Provides helper types and components to assist when working with Granicus CMS Reactor.",
|
|
5
5
|
"packageManager": "yarn@4.6.0+sha224.acd0786f07ffc6c933940eb65fc1d627131ddf5455bddcc295dc90fd",
|
|
6
6
|
"scripts": {
|