@salesforce/ui-bundle-template-feature-cms-toolkit 11.59.1

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.
Files changed (123) hide show
  1. package/LICENSE.txt +82 -0
  2. package/README.md +88 -0
  3. package/dist/.forceignore +15 -0
  4. package/dist/.husky/pre-commit +4 -0
  5. package/dist/.prettierignore +11 -0
  6. package/dist/.prettierrc +17 -0
  7. package/dist/CHANGELOG.md +4705 -0
  8. package/dist/README.md +77 -0
  9. package/dist/config/project-scratch-def.json +13 -0
  10. package/dist/eslint.config.js +7 -0
  11. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.forceignore +15 -0
  12. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.graphqlrc.yml +2 -0
  13. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.prettierignore +9 -0
  14. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.prettierrc +11 -0
  15. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/CHANGELOG.md +10 -0
  16. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/README.md +75 -0
  17. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/codegen.yml +95 -0
  18. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/components.json +18 -0
  19. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/e2e/app.spec.ts +17 -0
  20. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/eslint.config.js +169 -0
  21. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/feature-cms-toolkit.uibundle-meta.xml +7 -0
  22. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/index.html +12 -0
  23. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/package.json +76 -0
  24. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/playwright.config.ts +24 -0
  25. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/scripts/get-graphql-schema.mjs +71 -0
  26. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/scripts/rewrite-e2e-assets.mjs +23 -0
  27. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/api/graphqlClient.ts +44 -0
  28. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/app.tsx +17 -0
  29. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/appLayout.tsx +83 -0
  30. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/book.svg +3 -0
  31. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/copy.svg +4 -0
  32. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/rocket.svg +3 -0
  33. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/star.svg +3 -0
  34. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/codey-1.png +0 -0
  35. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/codey-2.png +0 -0
  36. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/codey-3.png +0 -0
  37. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/vibe-codey.svg +194 -0
  38. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/alerts/status-alert.tsx +52 -0
  39. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/layouts/card-layout.tsx +29 -0
  40. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/alert.tsx +76 -0
  41. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/avatar.tsx +109 -0
  42. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/badge.tsx +48 -0
  43. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/breadcrumb.tsx +109 -0
  44. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/button.tsx +67 -0
  45. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/calendar.tsx +232 -0
  46. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/card.tsx +103 -0
  47. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/checkbox.tsx +32 -0
  48. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/collapsible.tsx +33 -0
  49. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/datePicker.tsx +127 -0
  50. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/dialog.tsx +162 -0
  51. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/dropdown-menu.tsx +257 -0
  52. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/field.tsx +237 -0
  53. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/index.ts +109 -0
  54. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/input.tsx +19 -0
  55. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/label.tsx +22 -0
  56. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/pagination.tsx +132 -0
  57. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/popover.tsx +89 -0
  58. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/select.tsx +193 -0
  59. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/separator.tsx +26 -0
  60. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/skeleton.tsx +14 -0
  61. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/sonner.tsx +20 -0
  62. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/spinner.tsx +16 -0
  63. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/table.tsx +121 -0
  64. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/tabs.tsx +88 -0
  65. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/catalog.ts +140 -0
  66. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsContent.ts +127 -0
  67. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsPaths.ts +37 -0
  68. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/envelope.ts +30 -0
  69. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/errors.ts +54 -0
  70. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/httpClient.ts +102 -0
  71. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/config/env.ts +46 -0
  72. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/index.ts +46 -0
  73. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/types/cms.ts +96 -0
  74. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/htmlEntities.ts +58 -0
  75. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/imageUrl.ts +88 -0
  76. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/hooks/useAsyncData.ts +67 -0
  77. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts +10 -0
  78. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/lib/utils.ts +6 -0
  79. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/navigationMenu.tsx +80 -0
  80. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/pages/Home.tsx +12 -0
  81. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/pages/NotFound.tsx +18 -0
  82. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/router-utils.tsx +35 -0
  83. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/routes.tsx +22 -0
  84. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/styles/global.css +135 -0
  85. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/tsconfig.json +45 -0
  86. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/tsconfig.node.json +13 -0
  87. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/tsconfig.tsbuildinfo +1 -0
  88. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/ui-bundle.json +7 -0
  89. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vite-env.d.ts +4 -0
  90. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vite.config.ts +26 -0
  91. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vitest-env.d.ts +2 -0
  92. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vitest.config.ts +11 -0
  93. package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vitest.setup.ts +1 -0
  94. package/dist/jest.config.js +6 -0
  95. package/dist/package-lock.json +10066 -0
  96. package/dist/package.json +46 -0
  97. package/dist/scripts/apex/hello.apex +10 -0
  98. package/dist/scripts/gitignore-templates.json +4 -0
  99. package/dist/scripts/graphql-search.sh +191 -0
  100. package/dist/scripts/org-setup-config-schema.mjs +120 -0
  101. package/dist/scripts/org-setup-dev.mjs +87 -0
  102. package/dist/scripts/org-setup-utils.mjs +569 -0
  103. package/dist/scripts/org-setup-xml.mjs +182 -0
  104. package/dist/scripts/org-setup.config.json +5 -0
  105. package/dist/scripts/org-setup.mjs +2345 -0
  106. package/dist/scripts/sf-project-setup.mjs +103 -0
  107. package/dist/scripts/soql/account.soql +6 -0
  108. package/dist/scripts/validate-org-setup-config.mjs +38 -0
  109. package/dist/sfdx-project.json +12 -0
  110. package/package.json +50 -0
  111. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/catalog.ts +140 -0
  112. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsContent.ts +127 -0
  113. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsPaths.ts +37 -0
  114. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/envelope.ts +30 -0
  115. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/errors.ts +54 -0
  116. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/httpClient.ts +102 -0
  117. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/config/env.ts +46 -0
  118. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/index.ts +46 -0
  119. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/types/cms.ts +96 -0
  120. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/htmlEntities.ts +58 -0
  121. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/imageUrl.ts +88 -0
  122. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts +10 -0
  123. package/src/force-app/main/default/uiBundles/feature-cms-toolkit/vite.config.ts +26 -0
@@ -0,0 +1,96 @@
1
+ /**
2
+ * CMS toolkit shared types (framework-agnostic).
3
+ *
4
+ * The public contract is tiny and grows ADDITIVELY only:
5
+ * - CmsReadOptions — the single options object every read method accepts. New
6
+ * parameters (locale, fields, apiVersion…) arrive as NEW OPTIONAL fields here,
7
+ * so no existing call site ever breaks.
8
+ * - CmsBulkResult — one per-key result for the array overload of getCmsContentByKey.
9
+ * - CmsContentBody — default body type; callers refine with their own TBody.
10
+ * - CmsContentCatalog — shape of the runtime public/content-metadata.json.
11
+ *
12
+ */
13
+
14
+ /** Default content body: an open bag of per-type fields. Callers refine via TBody. */
15
+ export type CmsContentBody = Record<string, unknown>;
16
+
17
+ /**
18
+ * Structured image field as Delivery returns it — the one field that is an object, not
19
+ * a primitive. Two variants (`resolveCmsImageUrl` handles both):
20
+ * - CMS image (`source.type === 'imageReference'`): a root-relative top-level `url`
21
+ * plus `source.ref = { contentKey }`.
22
+ * - Foreign image (`source.type === 'url'`): no top-level `url`; the absolute url is
23
+ * the string in `source.ref`.
24
+ */
25
+ export interface CmsImageField {
26
+ /** Resolved media path — ROOT-RELATIVE for a CMS imageReference; absent for a foreign url image. */
27
+ url?: string;
28
+ altText?: string;
29
+ overrideAltText?: boolean;
30
+ source?: {
31
+ type?: "url" | "imageReference" | string;
32
+ /** Legacy/alternate slot for a `type: 'url'` absolute url. */
33
+ url?: string;
34
+ mimeType?: string;
35
+ size?: number;
36
+ /**
37
+ * For `type: 'url'`, the absolute image URL STRING (the payload puts it HERE,
38
+ * not in `source.url`). For `type: 'imageReference'`, a `{ contentKey }` identity
39
+ * for a CMS media item, resolved via the optional `resolveRef` callback.
40
+ */
41
+ ref?: string | { contentKey?: string };
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Options common to every read method. A required positional subject (url / key /
47
+ * keys) plus this ONE optional object. Every future parameter is a new optional
48
+ * field here — additive, never breaking.
49
+ */
50
+ export interface CmsReadOptions {
51
+ signal?: AbortSignal;
52
+ channelId?: string;
53
+ // ← future options (locale, apiVersion, fields…) are ADDED here. Additive only.
54
+ }
55
+
56
+ /**
57
+ * Bulk-read result for one requested contentKey. Best-effort: a key that is
58
+ * unpublished / wrong-channel / absent from the response comes back with `error`
59
+ * set instead of failing the whole batch. Matched BY contentKey, never positionally.
60
+ */
61
+ export interface CmsBulkResult<TBody = CmsContentBody> {
62
+ /** The requested contentKey — echoed back so callers can match results. */
63
+ contentKey: string;
64
+ /** The unwrapped content body (with title lifted), when the key resolved. */
65
+ body?: TBody;
66
+ /** Populated when this key failed to resolve (e.g. CmsNotFoundError). */
67
+ error?: Error;
68
+ }
69
+
70
+ /**
71
+ * Shape of the runtime public/content-metadata.json. Grows additively.
72
+ * Loaded once and memoized; fail-open (missing/malformed → `{}`). See api/catalog.ts.
73
+ */
74
+ export interface CmsContentCatalog {
75
+ channelId?: string;
76
+ contentKeyMap?: ReadonlyMap<string, string>;
77
+ // ← future: defaults, … (additive only)
78
+ }
79
+
80
+ /**
81
+ * Delivery envelope. BOTH transports (public CDN + authenticated Connect) return
82
+ * this same shape: the managed content item DIRECTLY.
83
+ * `contentBody` holds the per-type renderable fields.
84
+ */
85
+ export interface CmsDeliveryEnvelope<TBody = CmsContentBody> {
86
+ /** Per-type renderable fields — its keys vary by content type. */
87
+ contentBody: TBody;
88
+ /** Envelope-level display title; merged into the body by unwrapContent. */
89
+ title?: string;
90
+ contentKey?: string;
91
+ publishedDate?: string;
92
+ urlName?: string;
93
+ language?: string;
94
+ unauthenticatedUrl?: string;
95
+ contentType?: { fullyQualifiedName?: string };
96
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Decode entity-encoded RichText (Delivery returns `"&lt;div&gt;…"`) to its literal
3
+ * characters before you sanitize + inject it. Sanitizing is the consumer's concern —
4
+ * add DOMPurify at your injection site.
5
+ *
6
+ * Pure JS, no DOM — works in browser, Node, and SSR. Decodes in a SINGLE pass, so a
7
+ * double-encoded payload (`&amp;lt;`) decodes one level only (→ `&lt;`). Never also
8
+ * HTML-escape the same string — the round-trip cancels out.
9
+ */
10
+
11
+ /** Named entities RichText delivery emits; everything else arrives as a numeric ref.
12
+ * Keys are without the leading `&`/trailing `;`. */
13
+ const NAMED_ENTITIES: Record<string, string> = {
14
+ amp: "&",
15
+ lt: "<",
16
+ gt: ">",
17
+ quot: '"',
18
+ apos: "'",
19
+ nbsp: " ",
20
+ };
21
+
22
+ // One reference per match: `&name;`, `&#123;`, or `&#xAB;` (hex case-insensitive).
23
+ const ENTITY_RE = /&(#x[0-9a-f]+|#\d+|[a-z][a-z0-9]*);/gi;
24
+
25
+ /** Resolve a numeric character reference (`#123` decimal or `#x7b` hex); returns the
26
+ * original text unchanged for invalid or out-of-range code points. */
27
+ function decodeNumericEntity(entityBody: string, fullMatch: string): string {
28
+ const codePoint =
29
+ entityBody[1] === "x" || entityBody[1] === "X"
30
+ ? Number.parseInt(entityBody.slice(2), 16)
31
+ : Number.parseInt(entityBody.slice(1), 10);
32
+
33
+ // Reject NaN, surrogates, and anything past the Unicode max — fromCodePoint throws on these.
34
+ if (!Number.isFinite(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {
35
+ return fullMatch;
36
+ }
37
+ if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
38
+ return fullMatch;
39
+ }
40
+ return String.fromCodePoint(codePoint);
41
+ }
42
+
43
+ /**
44
+ * Decode entity-encoded RichText to its literal characters. Handles named entities
45
+ * (`&lt;`), decimal (`&#60;`), and hex (`&#x3c;`) references in one pass; unknown
46
+ * names and invalid numeric references are left verbatim.
47
+ */
48
+ export function decodeRichHtmlEntities(encoded: string): string {
49
+ if (!encoded || encoded.indexOf("&") === -1) return encoded;
50
+
51
+ return encoded.replace(ENTITY_RE, (fullMatch, entityBody: string) => {
52
+ if (entityBody[0] === "#") {
53
+ return decodeNumericEntity(entityBody, fullMatch);
54
+ }
55
+ const named = NAMED_ENTITIES[entityBody.toLowerCase()];
56
+ return named !== undefined ? named : fullMatch;
57
+ });
58
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * CMS image URL resolution. A Delivery image field (`CmsImageField`) does not hand you
3
+ * a ready `src`; this turns it into a loadable URL, covering both variants:
4
+ * - Foreign image (`source.type === 'url'`) → an absolute CDN url, returned as-is.
5
+ * - CMS image (`source.type === 'imageReference'`) → a root-relative `url`, prefixed
6
+ * with `options.instanceOrigin` when supplied (else returned unchanged).
7
+ */
8
+ import type { CmsImageField } from "../types/cms";
9
+
10
+ /** Options for {@link resolveCmsImageUrl}. */
11
+ export interface CmsImageOptions {
12
+ /**
13
+ * Instance origin (e.g. `https://my-org.my.salesforce.com`) used to prefix a
14
+ * root-relative media path. Absolute/protocol-relative URLs ignore it; omit it and
15
+ * a root-relative path is returned unchanged.
16
+ */
17
+ instanceOrigin?: string;
18
+ /**
19
+ * Resolve a nested `imageReference` contentKey to its media item — for the rare
20
+ * "references bag" payload with no top-level `url`. Returns the media field (with
21
+ * its own `url`), or undefined if unknown.
22
+ */
23
+ resolveRef?: (contentKey: string) => CmsImageField | undefined;
24
+ }
25
+
26
+ /** Prefix a root-relative url with `origin`; leave absolute and protocol-relative urls untouched. */
27
+ function prefixOrigin(rawUrl: string, origin?: string): string {
28
+ if (/^https?:\/\//i.test(rawUrl) || rawUrl.startsWith("//")) return rawUrl;
29
+ if (rawUrl.startsWith("/") && origin) {
30
+ return `${origin.endsWith("/") ? origin.slice(0, -1) : origin}${rawUrl}`;
31
+ }
32
+ return rawUrl;
33
+ }
34
+
35
+ /** Extract the delivered (un-prefixed) image url from a `CmsImageField`, or undefined. */
36
+ function extractRawUrl(
37
+ field: CmsImageField,
38
+ resolveRef?: CmsImageOptions["resolveRef"],
39
+ ): string | undefined {
40
+ // A top-level `url` is the resolved media path for a CMS imageReference image
41
+ // (root-relative) — it must win over the `source` branches below.
42
+ if (field.url) return field.url;
43
+
44
+ const source = field.source;
45
+ if (!source) return undefined;
46
+
47
+ // Foreign image: the absolute url lives in `source.ref` (a plain string) in the
48
+ // current payload; older shapes put it in `source.url`.
49
+ if (source.type === "url") {
50
+ if (typeof source.ref === "string") return source.ref;
51
+ if (source.url) return source.url;
52
+ return undefined;
53
+ }
54
+
55
+ // imageReference WITHOUT a top-level url (references-bag shape): resolve the CMS
56
+ // media item via the caller's callback. `ref` may be a bare contentKey string or
57
+ // a `{ contentKey }` object.
58
+ if (source.type === "imageReference" && resolveRef) {
59
+ const contentKey = typeof source.ref === "string" ? source.ref : source.ref?.contentKey;
60
+ if (!contentKey) return undefined;
61
+ return resolveRef(contentKey)?.url;
62
+ }
63
+
64
+ return undefined;
65
+ }
66
+
67
+ /**
68
+ * Resolve a `CmsImageField` to a loadable image URL — external (absolute CDN) or CMS
69
+ * imageReference (root-relative, prefixed with `options.instanceOrigin`). Returns
70
+ * undefined when the field has no resolvable url.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * // Foreign/CDN image — absolute url, origin not needed:
75
+ * resolveCmsImageUrl(body.bannerImage);
76
+ * // CMS image — root-relative, prefixed to load:
77
+ * resolveCmsImageUrl(body.bannerImage, { instanceOrigin });
78
+ * ```
79
+ */
80
+ export function resolveCmsImageUrl(
81
+ field: CmsImageField | undefined,
82
+ options?: CmsImageOptions,
83
+ ): string | undefined {
84
+ if (!field || typeof field !== "object") return undefined;
85
+ const rawUrl = extractRawUrl(field, options?.resolveRef);
86
+ if (!rawUrl) return undefined;
87
+ return prefixOrigin(rawUrl, options?.instanceOrigin);
88
+ }
@@ -0,0 +1,67 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+
3
+ interface UseAsyncDataResult<T> {
4
+ data: T | null;
5
+ loading: boolean;
6
+ error: string | null;
7
+ }
8
+
9
+ /**
10
+ * Runs an async fetcher on mount and whenever `deps` change.
11
+ * Returns the loading/error/data state. Does not cache — every call
12
+ * to the fetcher hits the source directly.
13
+ *
14
+ * A cleanup flag prevents state updates if the component unmounts
15
+ * or deps change before the fetch completes (avoids React warnings
16
+ * and stale updates from out-of-order responses).
17
+ */
18
+ export function useAsyncData<T>(
19
+ fetcher: () => Promise<T>,
20
+ deps: React.DependencyList
21
+ ): UseAsyncDataResult<T> {
22
+ const [data, setData] = useState<T | null>(null);
23
+ const [loading, setLoading] = useState(true);
24
+ const [error, setError] = useState<string | null>(null);
25
+ const [generation, setGeneration] = useState(0);
26
+
27
+ const fetcherRef = useRef(fetcher);
28
+ useEffect(() => {
29
+ fetcherRef.current = fetcher;
30
+ });
31
+
32
+ // Detect dep changes during render to reset loading state and bump generation
33
+ const [prevDeps, setPrevDeps] = useState(deps);
34
+ if (
35
+ deps.length !== prevDeps.length ||
36
+ deps.some((d, i) => d !== prevDeps[i])
37
+ ) {
38
+ setPrevDeps(deps);
39
+ setGeneration(g => g + 1);
40
+ if (!loading) setLoading(true);
41
+ if (error !== null) setError(null);
42
+ }
43
+
44
+ useEffect(() => {
45
+ let cancelled = false;
46
+
47
+ fetcherRef
48
+ .current()
49
+ .then(result => {
50
+ if (!cancelled) setData(result);
51
+ })
52
+ .catch(err => {
53
+ console.error(err);
54
+ if (!cancelled)
55
+ setError(err instanceof Error ? err.message : 'An error occurred');
56
+ })
57
+ .finally(() => {
58
+ if (!cancelled) setLoading(false);
59
+ });
60
+
61
+ return () => {
62
+ cancelled = true;
63
+ };
64
+ }, [generation]);
65
+
66
+ return { data, loading, error };
67
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * feature-cms-toolkit — framework-agnostic CMS delivery APIs.
3
+ *
4
+ * Package entry point. The public surface is defined in features/cmsToolkit/index.ts;
5
+ * this re-exports it so the toolkit can be consumed as a package or a local feature dir.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+
10
+ export * from "./features/cmsToolkit";
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,80 @@
1
+ import { Link, useLocation } from 'react-router';
2
+ import { getAllRoutes } from './router-utils';
3
+ import { useState } from 'react';
4
+
5
+ export default function NavigationMenu() {
6
+ const [isOpen, setIsOpen] = useState(false);
7
+ const location = useLocation();
8
+
9
+ const isActive = (path: string) => location.pathname === path;
10
+
11
+ const toggleMenu = () => setIsOpen(!isOpen);
12
+
13
+ const navigationRoutes: { path: string; label: string }[] = getAllRoutes()
14
+ .filter(
15
+ route =>
16
+ route.handle?.showInNavigation === true &&
17
+ route.fullPath !== undefined &&
18
+ route.handle?.label !== undefined
19
+ )
20
+ .map(
21
+ route =>
22
+ ({
23
+ path: route.fullPath,
24
+ label: route.handle?.label,
25
+ }) as { path: string; label: string }
26
+ );
27
+
28
+ return (
29
+ <nav className="bg-white border-b border-gray-200">
30
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
31
+ <div className="flex justify-between items-center h-16">
32
+ <Link to="/" className="text-xl font-semibold text-gray-900">
33
+ React App
34
+ </Link>
35
+ <button
36
+ onClick={toggleMenu}
37
+ className="p-2 rounded-md text-gray-700 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
38
+ aria-label="Toggle menu"
39
+ >
40
+ <div className="w-6 h-6 flex flex-col justify-center space-y-1.5">
41
+ <span
42
+ className={`block h-0.5 w-6 bg-current transition-all ${
43
+ isOpen ? 'rotate-45 translate-y-2' : ''
44
+ }`}
45
+ />
46
+ <span
47
+ className={`block h-0.5 w-6 bg-current transition-all ${isOpen ? 'opacity-0' : ''}`}
48
+ />
49
+ <span
50
+ className={`block h-0.5 w-6 bg-current transition-all ${
51
+ isOpen ? '-rotate-45 -translate-y-2' : ''
52
+ }`}
53
+ />
54
+ </div>
55
+ </button>
56
+ </div>
57
+ {isOpen && (
58
+ <div className="pb-4">
59
+ <div className="flex flex-col space-y-2">
60
+ {navigationRoutes.map(item => (
61
+ <Link
62
+ key={item.path}
63
+ to={item.path}
64
+ onClick={() => setIsOpen(false)}
65
+ className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
66
+ isActive(item.path)
67
+ ? 'bg-blue-100 text-blue-700'
68
+ : 'text-gray-700 hover:bg-gray-100'
69
+ }`}
70
+ >
71
+ {item.label}
72
+ </Link>
73
+ ))}
74
+ </div>
75
+ </div>
76
+ )}
77
+ </div>
78
+ </nav>
79
+ );
80
+ }
@@ -0,0 +1,12 @@
1
+ export default function Home() {
2
+ return (
3
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
4
+ <div className="text-center">
5
+ <h1 className="text-4xl font-bold text-gray-900 mb-4">Home</h1>
6
+ <p className="text-lg text-gray-600 mb-8">
7
+ Welcome to your React application.
8
+ </p>
9
+ </div>
10
+ </div>
11
+ );
12
+ }
@@ -0,0 +1,18 @@
1
+ import { Link } from 'react-router';
2
+
3
+ export default function NotFound() {
4
+ return (
5
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
6
+ <div className="text-center">
7
+ <h1 className="text-4xl font-bold text-gray-900 mb-4">404</h1>
8
+ <p className="text-lg text-gray-600 mb-8">Page not found</p>
9
+ <Link
10
+ to="/"
11
+ className="inline-block px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors"
12
+ >
13
+ Go to Home
14
+ </Link>
15
+ </div>
16
+ </div>
17
+ );
18
+ }
@@ -0,0 +1,35 @@
1
+ import type { RouteObject } from 'react-router';
2
+ import { routes } from './routes';
3
+
4
+ export type RouteWithFullPath = RouteObject & { fullPath: string };
5
+
6
+ const flatMapRoutes = (
7
+ route: RouteObject,
8
+ parentPath: string = ''
9
+ ): RouteWithFullPath[] => {
10
+ let fullPath: string;
11
+
12
+ if (route.index) {
13
+ fullPath = parentPath || '/';
14
+ } else if (route.path) {
15
+ if (route.path.startsWith('/')) {
16
+ fullPath = route.path;
17
+ } else {
18
+ fullPath =
19
+ parentPath === '/' ? `/${route.path}` : `${parentPath}/${route.path}`;
20
+ }
21
+ } else {
22
+ fullPath = parentPath;
23
+ }
24
+
25
+ const routeWithPath = { ...route, fullPath };
26
+
27
+ const childRoutes =
28
+ route.children?.flatMap(child => flatMapRoutes(child, fullPath)) || [];
29
+
30
+ return [routeWithPath, ...childRoutes];
31
+ };
32
+
33
+ export const getAllRoutes = (): RouteWithFullPath[] => {
34
+ return routes.flatMap(route => flatMapRoutes(route));
35
+ };
@@ -0,0 +1,22 @@
1
+ import type { RouteObject } from 'react-router';
2
+ import AppLayout from '@/appLayout';
3
+ import Home from './pages/Home';
4
+ import NotFound from './pages/NotFound';
5
+
6
+ export const routes: RouteObject[] = [
7
+ {
8
+ path: '/',
9
+ element: <AppLayout />,
10
+ children: [
11
+ {
12
+ index: true,
13
+ element: <Home />,
14
+ handle: { showInNavigation: true, label: 'Home' },
15
+ },
16
+ {
17
+ path: '*',
18
+ element: <NotFound />,
19
+ },
20
+ ],
21
+ },
22
+ ];
@@ -0,0 +1,135 @@
1
+ @import 'tailwindcss';
2
+
3
+ @layer base {
4
+ html,
5
+ body,
6
+ #root {
7
+ @apply min-h-screen;
8
+ }
9
+
10
+ body {
11
+ @apply antialiased bg-white;
12
+ }
13
+ }
14
+
15
+ @import 'tw-animate-css';
16
+ @import 'shadcn/tailwind.css';
17
+
18
+ @custom-variant dark (&:is(.dark *));
19
+
20
+ @theme inline {
21
+ --color-background: var(--background);
22
+ --color-foreground: var(--foreground);
23
+ --color-card: var(--card);
24
+ --color-card-foreground: var(--card-foreground);
25
+ --color-popover: var(--popover);
26
+ --color-popover-foreground: var(--popover-foreground);
27
+ --color-primary: var(--primary);
28
+ --color-primary-foreground: var(--primary-foreground);
29
+ --color-secondary: var(--secondary);
30
+ --color-secondary-foreground: var(--secondary-foreground);
31
+ --color-muted: var(--muted);
32
+ --color-muted-foreground: var(--muted-foreground);
33
+ --color-accent: var(--accent);
34
+ --color-accent-foreground: var(--accent-foreground);
35
+ --color-destructive: var(--destructive);
36
+ --color-destructive-foreground: var(--destructive-foreground);
37
+ --color-border: var(--border);
38
+ --color-input: var(--input);
39
+ --color-ring: var(--ring);
40
+ --color-chart-1: var(--chart-1);
41
+ --color-chart-2: var(--chart-2);
42
+ --color-chart-3: var(--chart-3);
43
+ --color-chart-4: var(--chart-4);
44
+ --color-chart-5: var(--chart-5);
45
+ --radius-sm: calc(var(--radius) - 4px);
46
+ --radius-md: calc(var(--radius) - 2px);
47
+ --radius-lg: var(--radius);
48
+ --radius-xl: calc(var(--radius) + 4px);
49
+ --color-sidebar: var(--sidebar);
50
+ --color-sidebar-foreground: var(--sidebar-foreground);
51
+ --color-sidebar-primary: var(--sidebar-primary);
52
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
53
+ --color-sidebar-accent: var(--sidebar-accent);
54
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
55
+ --color-sidebar-border: var(--sidebar-border);
56
+ --color-sidebar-ring: var(--sidebar-ring);
57
+ }
58
+
59
+ :root {
60
+ --radius: 0.625rem;
61
+ --background: oklch(1 0 0);
62
+ --foreground: oklch(0.145 0 0);
63
+ --card: oklch(1 0 0);
64
+ --card-foreground: oklch(0.145 0 0);
65
+ --popover: oklch(1 0 0);
66
+ --popover-foreground: oklch(0.145 0 0);
67
+ --primary: oklch(0.205 0 0);
68
+ --primary-foreground: oklch(0.985 0 0);
69
+ --secondary: oklch(0.97 0 0);
70
+ --secondary-foreground: oklch(0.205 0 0);
71
+ --muted: oklch(0.97 0 0);
72
+ --muted-foreground: oklch(0.556 0 0);
73
+ --accent: oklch(0.97 0 0);
74
+ --accent-foreground: oklch(0.205 0 0);
75
+ --destructive: oklch(0.577 0.245 27.325);
76
+ --border: oklch(0.922 0 0);
77
+ --input: oklch(0.922 0 0);
78
+ --ring: oklch(0.708 0 0);
79
+ --chart-1: oklch(0.646 0.222 41.116);
80
+ --chart-2: oklch(0.6 0.118 184.704);
81
+ --chart-3: oklch(0.398 0.07 227.392);
82
+ --chart-4: oklch(0.828 0.189 84.429);
83
+ --chart-5: oklch(0.769 0.188 70.08);
84
+ --sidebar: oklch(0.985 0 0);
85
+ --sidebar-foreground: oklch(0.145 0 0);
86
+ --sidebar-primary: oklch(0.205 0 0);
87
+ --sidebar-primary-foreground: oklch(0.985 0 0);
88
+ --sidebar-accent: oklch(0.97 0 0);
89
+ --sidebar-accent-foreground: oklch(0.205 0 0);
90
+ --sidebar-border: oklch(0.922 0 0);
91
+ --sidebar-ring: oklch(0.708 0 0);
92
+ }
93
+
94
+ .dark {
95
+ --background: oklch(0.145 0 0);
96
+ --foreground: oklch(0.985 0 0);
97
+ --card: oklch(0.205 0 0);
98
+ --card-foreground: oklch(0.985 0 0);
99
+ --popover: oklch(0.205 0 0);
100
+ --popover-foreground: oklch(0.985 0 0);
101
+ --primary: oklch(0.922 0 0);
102
+ --primary-foreground: oklch(0.205 0 0);
103
+ --secondary: oklch(0.269 0 0);
104
+ --secondary-foreground: oklch(0.985 0 0);
105
+ --muted: oklch(0.269 0 0);
106
+ --muted-foreground: oklch(0.708 0 0);
107
+ --accent: oklch(0.269 0 0);
108
+ --accent-foreground: oklch(0.985 0 0);
109
+ --destructive: oklch(0.704 0.191 22.216);
110
+ --border: oklch(1 0 0 / 10%);
111
+ --input: oklch(1 0 0 / 15%);
112
+ --ring: oklch(0.556 0 0);
113
+ --chart-1: oklch(0.488 0.243 264.376);
114
+ --chart-2: oklch(0.696 0.17 162.48);
115
+ --chart-3: oklch(0.769 0.188 70.08);
116
+ --chart-4: oklch(0.627 0.265 303.9);
117
+ --chart-5: oklch(0.645 0.246 16.439);
118
+ --sidebar: oklch(0.205 0 0);
119
+ --sidebar-foreground: oklch(0.985 0 0);
120
+ --sidebar-primary: oklch(0.488 0.243 264.376);
121
+ --sidebar-primary-foreground: oklch(0.985 0 0);
122
+ --sidebar-accent: oklch(0.269 0 0);
123
+ --sidebar-accent-foreground: oklch(0.985 0 0);
124
+ --sidebar-border: oklch(1 0 0 / 10%);
125
+ --sidebar-ring: oklch(0.556 0 0);
126
+ }
127
+
128
+ @layer base {
129
+ * {
130
+ @apply border-border outline-ring/50;
131
+ }
132
+ body {
133
+ @apply bg-background text-foreground;
134
+ }
135
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react-jsx",
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+
23
+ /* Path mapping */
24
+ "paths": {
25
+ "@/*": ["./src/*"],
26
+ "@api/*": ["./src/api/*"],
27
+ "@components/*": ["./src/components/*"],
28
+ "@utils/*": ["./src/utils/*"],
29
+ "@styles/*": ["./src/styles/*"],
30
+ "@assets/*": ["./src/assets/*"],
31
+ "@salesforce/platform-sdk": [
32
+ "../../../../../../../../../../packages/sdk/platform-sdk/src/index.ts"
33
+ ]
34
+ }
35
+ },
36
+ "include": [
37
+ "src",
38
+ "e2e",
39
+ "vite-env.d.ts",
40
+ "vitest-env.d.ts",
41
+ "vitest.setup.ts",
42
+ "../../../../../../../../../../packages/sdk/platform-sdk/types"
43
+ ],
44
+ "references": [{ "path": "./tsconfig.node.json" }]
45
+ }