admin-lib-cms 1.1.3 → 1.1.5
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.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +35 -5
- package/dist/index.mjs +35 -5
- package/dist/types.d.mts +2 -1
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -34,8 +34,9 @@ interface CmsProviderProps {
|
|
|
34
34
|
iconMap?: Record<string, React.ComponentType<{
|
|
35
35
|
className?: string;
|
|
36
36
|
}>>;
|
|
37
|
+
initialOverrides?: OverridesMap;
|
|
37
38
|
}
|
|
38
|
-
declare function CmsProvider({ config, adapter, children, iconMap }: CmsProviderProps): react.JSX.Element;
|
|
39
|
+
declare function CmsProvider({ config, adapter, children, iconMap, initialOverrides }: CmsProviderProps): react.JSX.Element;
|
|
39
40
|
/** Hook to submit form data to the CMS inbox. */
|
|
40
41
|
declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
|
|
41
42
|
|
|
@@ -63,8 +64,9 @@ interface EditableLinkProps extends BaseProps {
|
|
|
63
64
|
href: string;
|
|
64
65
|
children: string;
|
|
65
66
|
className?: string;
|
|
67
|
+
target?: string;
|
|
66
68
|
}
|
|
67
|
-
declare function EditableLink({ id, label, section, pageId, href, children, className, }: EditableLinkProps): react.JSX.Element;
|
|
69
|
+
declare function EditableLink({ id, label, section, pageId, href, children, className, target, }: EditableLinkProps): react.JSX.Element;
|
|
68
70
|
interface EditableListProps<T = any> extends BaseProps {
|
|
69
71
|
initialItems: T[];
|
|
70
72
|
renderItem?: (item: T, index: number) => React.ReactNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -34,8 +34,9 @@ interface CmsProviderProps {
|
|
|
34
34
|
iconMap?: Record<string, React.ComponentType<{
|
|
35
35
|
className?: string;
|
|
36
36
|
}>>;
|
|
37
|
+
initialOverrides?: OverridesMap;
|
|
37
38
|
}
|
|
38
|
-
declare function CmsProvider({ config, adapter, children, iconMap }: CmsProviderProps): react.JSX.Element;
|
|
39
|
+
declare function CmsProvider({ config, adapter, children, iconMap, initialOverrides }: CmsProviderProps): react.JSX.Element;
|
|
39
40
|
/** Hook to submit form data to the CMS inbox. */
|
|
40
41
|
declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
|
|
41
42
|
|
|
@@ -63,8 +64,9 @@ interface EditableLinkProps extends BaseProps {
|
|
|
63
64
|
href: string;
|
|
64
65
|
children: string;
|
|
65
66
|
className?: string;
|
|
67
|
+
target?: string;
|
|
66
68
|
}
|
|
67
|
-
declare function EditableLink({ id, label, section, pageId, href, children, className, }: EditableLinkProps): react.JSX.Element;
|
|
69
|
+
declare function EditableLink({ id, label, section, pageId, href, children, className, target, }: EditableLinkProps): react.JSX.Element;
|
|
68
70
|
interface EditableListProps<T = any> extends BaseProps {
|
|
69
71
|
initialItems: T[];
|
|
70
72
|
renderItem?: (item: T, index: number) => React.ReactNode;
|
package/dist/index.js
CHANGED
|
@@ -52,9 +52,9 @@ function useCmsContext() {
|
|
|
52
52
|
function useCmsOptional() {
|
|
53
53
|
return (0, import_react.useContext)(CmsContext);
|
|
54
54
|
}
|
|
55
|
-
function CmsProvider({ config, adapter, children, iconMap }) {
|
|
56
|
-
const [overrides, setOverrides] = (0, import_react.useState)({});
|
|
57
|
-
const [savedOverrides, setSavedOverrides] = (0, import_react.useState)({});
|
|
55
|
+
function CmsProvider({ config, adapter, children, iconMap, initialOverrides }) {
|
|
56
|
+
const [overrides, setOverrides] = (0, import_react.useState)(initialOverrides || {});
|
|
57
|
+
const [savedOverrides, setSavedOverrides] = (0, import_react.useState)(initialOverrides || {});
|
|
58
58
|
const [selectedId, setSelectedIdRaw] = (0, import_react.useState)(null);
|
|
59
59
|
const [editMode, setEditMode] = (0, import_react.useState)(false);
|
|
60
60
|
const [collectionChangedAt, setCollectionChangedAt] = (0, import_react.useState)(0);
|
|
@@ -311,7 +311,8 @@ function EditableLink({
|
|
|
311
311
|
pageId,
|
|
312
312
|
href,
|
|
313
313
|
children,
|
|
314
|
-
className
|
|
314
|
+
className,
|
|
315
|
+
target
|
|
315
316
|
}) {
|
|
316
317
|
const ctx = useRegister(id, "link", label, section, pageId, { href, text: children });
|
|
317
318
|
const override = ctx?.overrides[id];
|
|
@@ -325,10 +326,15 @@ function EditableLink({
|
|
|
325
326
|
e.stopPropagation();
|
|
326
327
|
ctx.setSelectedId(id);
|
|
327
328
|
};
|
|
329
|
+
const isExternal = hrefValue.startsWith("http");
|
|
330
|
+
const computedTarget = target || (isExternal ? "_blank" : void 0);
|
|
331
|
+
const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
|
|
328
332
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
329
333
|
"a",
|
|
330
334
|
{
|
|
331
335
|
href: hrefValue,
|
|
336
|
+
target: computedTarget,
|
|
337
|
+
rel: computedRel,
|
|
332
338
|
"data-cms-id": id,
|
|
333
339
|
onClick: active ? onClick : void 0,
|
|
334
340
|
className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
|
|
@@ -1523,7 +1529,31 @@ function CollectionEditor({ collection }) {
|
|
|
1523
1529
|
placeholder: `Search ${f.label.toLowerCase()}...`,
|
|
1524
1530
|
iconMap: ctx.iconMap
|
|
1525
1531
|
}
|
|
1526
|
-
) : f.type === "
|
|
1532
|
+
) : f.type === "slug" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
1533
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1534
|
+
"input",
|
|
1535
|
+
{
|
|
1536
|
+
type: "text",
|
|
1537
|
+
value: String(editing[f.id] ?? ""),
|
|
1538
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
1539
|
+
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
1540
|
+
}
|
|
1541
|
+
),
|
|
1542
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1543
|
+
"button",
|
|
1544
|
+
{
|
|
1545
|
+
type: "button",
|
|
1546
|
+
onClick: () => {
|
|
1547
|
+
const sourceField = f.source || "title";
|
|
1548
|
+
let val = String(editing[sourceField] || editing.id || "");
|
|
1549
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
1550
|
+
setEditing({ ...editing, [f.id]: val });
|
|
1551
|
+
},
|
|
1552
|
+
className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
|
|
1553
|
+
children: "Generate"
|
|
1554
|
+
}
|
|
1555
|
+
)
|
|
1556
|
+
] }) : f.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1527
1557
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1528
1558
|
"input",
|
|
1529
1559
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -24,9 +24,9 @@ function useCmsContext() {
|
|
|
24
24
|
function useCmsOptional() {
|
|
25
25
|
return useContext(CmsContext);
|
|
26
26
|
}
|
|
27
|
-
function CmsProvider({ config, adapter, children, iconMap }) {
|
|
28
|
-
const [overrides, setOverrides] = useState({});
|
|
29
|
-
const [savedOverrides, setSavedOverrides] = useState({});
|
|
27
|
+
function CmsProvider({ config, adapter, children, iconMap, initialOverrides }) {
|
|
28
|
+
const [overrides, setOverrides] = useState(initialOverrides || {});
|
|
29
|
+
const [savedOverrides, setSavedOverrides] = useState(initialOverrides || {});
|
|
30
30
|
const [selectedId, setSelectedIdRaw] = useState(null);
|
|
31
31
|
const [editMode, setEditMode] = useState(false);
|
|
32
32
|
const [collectionChangedAt, setCollectionChangedAt] = useState(0);
|
|
@@ -283,7 +283,8 @@ function EditableLink({
|
|
|
283
283
|
pageId,
|
|
284
284
|
href,
|
|
285
285
|
children,
|
|
286
|
-
className
|
|
286
|
+
className,
|
|
287
|
+
target
|
|
287
288
|
}) {
|
|
288
289
|
const ctx = useRegister(id, "link", label, section, pageId, { href, text: children });
|
|
289
290
|
const override = ctx?.overrides[id];
|
|
@@ -297,10 +298,15 @@ function EditableLink({
|
|
|
297
298
|
e.stopPropagation();
|
|
298
299
|
ctx.setSelectedId(id);
|
|
299
300
|
};
|
|
301
|
+
const isExternal = hrefValue.startsWith("http");
|
|
302
|
+
const computedTarget = target || (isExternal ? "_blank" : void 0);
|
|
303
|
+
const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
|
|
300
304
|
return /* @__PURE__ */ jsx2(
|
|
301
305
|
"a",
|
|
302
306
|
{
|
|
303
307
|
href: hrefValue,
|
|
308
|
+
target: computedTarget,
|
|
309
|
+
rel: computedRel,
|
|
304
310
|
"data-cms-id": id,
|
|
305
311
|
onClick: active ? onClick : void 0,
|
|
306
312
|
className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
|
|
@@ -1521,7 +1527,31 @@ function CollectionEditor({ collection }) {
|
|
|
1521
1527
|
placeholder: `Search ${f.label.toLowerCase()}...`,
|
|
1522
1528
|
iconMap: ctx.iconMap
|
|
1523
1529
|
}
|
|
1524
|
-
) : f.type === "
|
|
1530
|
+
) : f.type === "slug" ? /* @__PURE__ */ jsxs2("div", { className: "flex gap-2", children: [
|
|
1531
|
+
/* @__PURE__ */ jsx5(
|
|
1532
|
+
"input",
|
|
1533
|
+
{
|
|
1534
|
+
type: "text",
|
|
1535
|
+
value: String(editing[f.id] ?? ""),
|
|
1536
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
1537
|
+
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
1538
|
+
}
|
|
1539
|
+
),
|
|
1540
|
+
/* @__PURE__ */ jsx5(
|
|
1541
|
+
"button",
|
|
1542
|
+
{
|
|
1543
|
+
type: "button",
|
|
1544
|
+
onClick: () => {
|
|
1545
|
+
const sourceField = f.source || "title";
|
|
1546
|
+
let val = String(editing[sourceField] || editing.id || "");
|
|
1547
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
1548
|
+
setEditing({ ...editing, [f.id]: val });
|
|
1549
|
+
},
|
|
1550
|
+
className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
|
|
1551
|
+
children: "Generate"
|
|
1552
|
+
}
|
|
1553
|
+
)
|
|
1554
|
+
] }) : f.type === "select" ? /* @__PURE__ */ jsxs2("div", { children: [
|
|
1525
1555
|
/* @__PURE__ */ jsx5(
|
|
1526
1556
|
"input",
|
|
1527
1557
|
{
|
package/dist/types.d.mts
CHANGED
|
@@ -23,11 +23,12 @@ interface PageDef {
|
|
|
23
23
|
interface CollectionField {
|
|
24
24
|
id: string;
|
|
25
25
|
label: string;
|
|
26
|
-
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug";
|
|
27
27
|
options?: string[] | {
|
|
28
28
|
label: string;
|
|
29
29
|
value: string;
|
|
30
30
|
}[];
|
|
31
|
+
source?: string;
|
|
31
32
|
defaultValue?: unknown;
|
|
32
33
|
}
|
|
33
34
|
interface CollectionDef {
|
package/dist/types.d.ts
CHANGED
|
@@ -23,11 +23,12 @@ interface PageDef {
|
|
|
23
23
|
interface CollectionField {
|
|
24
24
|
id: string;
|
|
25
25
|
label: string;
|
|
26
|
-
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug";
|
|
27
27
|
options?: string[] | {
|
|
28
28
|
label: string;
|
|
29
29
|
value: string;
|
|
30
30
|
}[];
|
|
31
|
+
source?: string;
|
|
31
32
|
defaultValue?: unknown;
|
|
32
33
|
}
|
|
33
34
|
interface CollectionDef {
|