admin-lib-cms 1.1.4 → 1.1.6

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.
File without changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { CmsConfig, StorageAdapter, OverridesMap, EditableMeta } from './types.mjs';
4
+ export { CollectionDef, CollectionEntry, CollectionField, FieldType, GlobalGroup, PageDef, Submission } from './types.mjs';
4
5
  export { generateDefaultTemplate, sendEmailNotification } from './emails/index.mjs';
5
6
 
6
7
  interface CmsContextValue {
@@ -34,8 +35,9 @@ interface CmsProviderProps {
34
35
  iconMap?: Record<string, React.ComponentType<{
35
36
  className?: string;
36
37
  }>>;
38
+ initialOverrides?: OverridesMap;
37
39
  }
38
- declare function CmsProvider({ config, adapter, children, iconMap }: CmsProviderProps): react.JSX.Element;
40
+ declare function CmsProvider({ config, adapter, children, iconMap, initialOverrides }: CmsProviderProps): react.JSX.Element;
39
41
  /** Hook to submit form data to the CMS inbox. */
40
42
  declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
41
43
 
@@ -61,10 +63,12 @@ interface EditableImageProps extends BaseProps {
61
63
  declare function EditableImage({ id, label, section, pageId, src, alt, className, width, height, }: EditableImageProps): react.JSX.Element;
62
64
  interface EditableLinkProps extends BaseProps {
63
65
  href: string;
64
- children: string;
66
+ children?: React.ReactNode;
67
+ text?: string;
65
68
  className?: string;
69
+ target?: string;
66
70
  }
67
- declare function EditableLink({ id, label, section, pageId, href, children, className, }: EditableLinkProps): react.JSX.Element;
71
+ declare function EditableLink({ id, label, section, pageId, href, children, text, className, target, }: EditableLinkProps): react.JSX.Element;
68
72
  interface EditableListProps<T = any> extends BaseProps {
69
73
  initialItems: T[];
70
74
  renderItem?: (item: T, index: number) => React.ReactNode;
@@ -124,4 +128,4 @@ declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
124
128
 
125
129
  declare function SubscriptionPage(): react.JSX.Element;
126
130
 
127
- export { AdminApp, AdminLogin, type AdminLoginProps, CmsProvider, EditableImage, EditableLink, EditableList, EditableText, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
131
+ export { AdminApp, AdminLogin, type AdminLoginProps, CmsConfig, CmsProvider, EditableImage, EditableLink, EditableList, EditableMeta, EditableText, OverridesMap, StorageAdapter, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { CmsConfig, StorageAdapter, OverridesMap, EditableMeta } from './types.js';
4
+ export { CollectionDef, CollectionEntry, CollectionField, FieldType, GlobalGroup, PageDef, Submission } from './types.js';
4
5
  export { generateDefaultTemplate, sendEmailNotification } from './emails/index.js';
5
6
 
6
7
  interface CmsContextValue {
@@ -34,8 +35,9 @@ interface CmsProviderProps {
34
35
  iconMap?: Record<string, React.ComponentType<{
35
36
  className?: string;
36
37
  }>>;
38
+ initialOverrides?: OverridesMap;
37
39
  }
38
- declare function CmsProvider({ config, adapter, children, iconMap }: CmsProviderProps): react.JSX.Element;
40
+ declare function CmsProvider({ config, adapter, children, iconMap, initialOverrides }: CmsProviderProps): react.JSX.Element;
39
41
  /** Hook to submit form data to the CMS inbox. */
40
42
  declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
41
43
 
@@ -61,10 +63,12 @@ interface EditableImageProps extends BaseProps {
61
63
  declare function EditableImage({ id, label, section, pageId, src, alt, className, width, height, }: EditableImageProps): react.JSX.Element;
62
64
  interface EditableLinkProps extends BaseProps {
63
65
  href: string;
64
- children: string;
66
+ children?: React.ReactNode;
67
+ text?: string;
65
68
  className?: string;
69
+ target?: string;
66
70
  }
67
- declare function EditableLink({ id, label, section, pageId, href, children, className, }: EditableLinkProps): react.JSX.Element;
71
+ declare function EditableLink({ id, label, section, pageId, href, children, text, className, target, }: EditableLinkProps): react.JSX.Element;
68
72
  interface EditableListProps<T = any> extends BaseProps {
69
73
  initialItems: T[];
70
74
  renderItem?: (item: T, index: number) => React.ReactNode;
@@ -124,4 +128,4 @@ declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
124
128
 
125
129
  declare function SubscriptionPage(): react.JSX.Element;
126
130
 
127
- export { AdminApp, AdminLogin, type AdminLoginProps, CmsProvider, EditableImage, EditableLink, EditableList, EditableText, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
131
+ export { AdminApp, AdminLogin, type AdminLoginProps, CmsConfig, CmsProvider, EditableImage, EditableLink, EditableList, EditableMeta, EditableText, OverridesMap, StorageAdapter, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
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,12 +311,15 @@ function EditableLink({
311
311
  pageId,
312
312
  href,
313
313
  children,
314
- className
314
+ text,
315
+ className,
316
+ target
315
317
  }) {
316
- const ctx = useRegister(id, "link", label, section, pageId, { href, text: children });
318
+ const defaultText = text ?? (typeof children === "string" ? children : "");
319
+ const ctx = useRegister(id, "link", label, section, pageId, { href, text: defaultText });
317
320
  const override = ctx?.overrides[id];
318
321
  const hrefValue = override?.href ?? href;
319
- const textValue = override?.text ?? children;
322
+ const textValue = override?.text ?? defaultText;
320
323
  const active = !!ctx?.editMode;
321
324
  const selected = ctx?.selectedId === id;
322
325
  const onClick = (e) => {
@@ -325,14 +328,19 @@ function EditableLink({
325
328
  e.stopPropagation();
326
329
  ctx.setSelectedId(id);
327
330
  };
331
+ const isExternal = hrefValue.startsWith("http");
332
+ const computedTarget = target || (isExternal ? "_blank" : void 0);
333
+ const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
328
334
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
329
335
  "a",
330
336
  {
331
337
  href: hrefValue,
338
+ target: computedTarget,
339
+ rel: computedRel,
332
340
  "data-cms-id": id,
333
341
  onClick: active ? onClick : void 0,
334
342
  className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
335
- children: textValue
343
+ children: typeof children !== "undefined" ? children : textValue
336
344
  }
337
345
  );
338
346
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import "./chunk-WBQAMGXK.mjs";
2
3
  import {
3
4
  generateDefaultTemplate,
4
5
  sendEmailNotification
@@ -24,9 +25,9 @@ function useCmsContext() {
24
25
  function useCmsOptional() {
25
26
  return useContext(CmsContext);
26
27
  }
27
- function CmsProvider({ config, adapter, children, iconMap }) {
28
- const [overrides, setOverrides] = useState({});
29
- const [savedOverrides, setSavedOverrides] = useState({});
28
+ function CmsProvider({ config, adapter, children, iconMap, initialOverrides }) {
29
+ const [overrides, setOverrides] = useState(initialOverrides || {});
30
+ const [savedOverrides, setSavedOverrides] = useState(initialOverrides || {});
30
31
  const [selectedId, setSelectedIdRaw] = useState(null);
31
32
  const [editMode, setEditMode] = useState(false);
32
33
  const [collectionChangedAt, setCollectionChangedAt] = useState(0);
@@ -283,12 +284,15 @@ function EditableLink({
283
284
  pageId,
284
285
  href,
285
286
  children,
286
- className
287
+ text,
288
+ className,
289
+ target
287
290
  }) {
288
- const ctx = useRegister(id, "link", label, section, pageId, { href, text: children });
291
+ const defaultText = text ?? (typeof children === "string" ? children : "");
292
+ const ctx = useRegister(id, "link", label, section, pageId, { href, text: defaultText });
289
293
  const override = ctx?.overrides[id];
290
294
  const hrefValue = override?.href ?? href;
291
- const textValue = override?.text ?? children;
295
+ const textValue = override?.text ?? defaultText;
292
296
  const active = !!ctx?.editMode;
293
297
  const selected = ctx?.selectedId === id;
294
298
  const onClick = (e) => {
@@ -297,14 +301,19 @@ function EditableLink({
297
301
  e.stopPropagation();
298
302
  ctx.setSelectedId(id);
299
303
  };
304
+ const isExternal = hrefValue.startsWith("http");
305
+ const computedTarget = target || (isExternal ? "_blank" : void 0);
306
+ const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
300
307
  return /* @__PURE__ */ jsx2(
301
308
  "a",
302
309
  {
303
310
  href: hrefValue,
311
+ target: computedTarget,
312
+ rel: computedRel,
304
313
  "data-cms-id": id,
305
314
  onClick: active ? onClick : void 0,
306
315
  className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
307
- children: textValue
316
+ children: typeof children !== "undefined" ? children : textValue
308
317
  }
309
318
  );
310
319
  }
package/dist/types.mjs CHANGED
@@ -0,0 +1 @@
1
+ import "./chunk-WBQAMGXK.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin-lib-cms",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Agnostic Admin CMS Library",
5
5
  "keywords": [
6
6
  "cms",