@salesforcedevs/docs-components 1.32.0-alpha.9 → 1.32.0-docs-content-type-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 (26) hide show
  1. package/.npmrc +1 -0
  2. package/lwc.config.json +5 -0
  3. package/package.json +29 -28
  4. package/src/modules/doc/amfReference/amfReference.html +1 -0
  5. package/src/modules/doc/amfReference/amfReference.ts +54 -10
  6. package/src/modules/doc/amfReference/types.ts +5 -0
  7. package/src/modules/doc/contentActionToolbar/contentActionToolbar.css +31 -0
  8. package/src/modules/doc/contentActionToolbar/contentActionToolbar.html +53 -0
  9. package/src/modules/doc/contentActionToolbar/contentActionToolbar.ts +151 -0
  10. package/src/modules/doc/contentActionToolbar/contentActionToolbarMocks.ts +48 -0
  11. package/src/modules/doc/contentLayout/contentLayout.css +0 -7
  12. package/src/modules/doc/contentLayout/contentLayout.html +17 -36
  13. package/src/modules/doc/contentLayout/contentLayout.ts +104 -46
  14. package/src/modules/doc/header/header.html +0 -1
  15. package/src/modules/doc/lwcContentLayout/lwcContentLayout.html +1 -12
  16. package/src/modules/doc/redocReference/redocReference.ts +304 -0
  17. package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.css +19 -0
  18. package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.html +28 -0
  19. package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.ts +87 -0
  20. package/src/modules/doc/xmlContent/xmlContent.html +0 -1
  21. package/src/modules/doc/xmlContent/xmlContent.ts +11 -0
  22. package/src/modules/docUtils/searchClient/searchClient.ts +160 -0
  23. package/src/modules/docUtils/searchController/__mocks__/searchController.ts +90 -0
  24. package/src/modules/docUtils/searchController/searchController.ts +420 -0
  25. package/src/modules/docUtils/searchLocale/searchLocale.ts +85 -0
  26. package/LICENSE +0 -12
@@ -0,0 +1,87 @@
1
+ import { LightningElement, api } from "lwc";
2
+ import { toJson } from "dxUtils/normalizers";
3
+ import type { OptionWithLink, TreeNode } from "typings/custom";
4
+
5
+ /**
6
+ * Per-topic type emitted by the docs content-type parser
7
+ * (see @salesforcedevs/sfdocs-doc-framework: `TopicTypeEnum`). Only `spec`
8
+ * is meaningful inside this component; everything else renders as a plain
9
+ * markdown-style tile.
10
+ */
11
+ const TOPIC_TYPE_SPEC = "spec";
12
+
13
+ /**
14
+ * Translates per-topic `topicType` into the generic `showForwardArrow` flag
15
+ * that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc).
16
+ */
17
+ function decorateTopicsWithForwardArrow(
18
+ topics: Array<TreeNode & { topicType?: string }> | undefined
19
+ ): TreeNode[] | undefined {
20
+ return topics?.map((topic) => {
21
+ const { topicType, ...decorated } = topic;
22
+ if (topicType === TOPIC_TYPE_SPEC) {
23
+ decorated.showForwardArrow = true;
24
+ }
25
+ if (decorated.children) {
26
+ decorated.children = decorateTopicsWithForwardArrow(
27
+ decorated.children
28
+ );
29
+ }
30
+ return decorated;
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Wrapper around `doc-content-layout` for the "docs" content type emitted by
36
+ * the `DocsContentTypeParser`.
37
+ */
38
+ export default class UnifiedContentLayout extends LightningElement {
39
+ @api breadcrumbs: string | null = null;
40
+ @api sidebarHeader?: string;
41
+ @api sidebarValue?: string;
42
+ @api tocTitle?: string;
43
+ @api tocOptions?: string;
44
+ @api tocAriaLevel?: string;
45
+ @api languages?: OptionWithLink[];
46
+ @api language?: string;
47
+ @api devCenter: any = null;
48
+ @api brand: any = null;
49
+
50
+ /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). */
51
+ @api origin: string | null = null;
52
+
53
+ /** Article name from breadcrumbs, used as share title (e.g. for social share). */
54
+ @api shareTitle: string | null = null;
55
+
56
+ /** Optional Twitter "via" handle (e.g. SalesforceDevs) for social share. */
57
+ @api twitterVia: string | null = null;
58
+
59
+ @api hideFooter = false;
60
+
61
+ private _docPhaseInfo: string | null = null;
62
+ private _sidebarContent: unknown = null;
63
+
64
+ @api
65
+ get docPhaseInfo(): string | null {
66
+ return this._docPhaseInfo;
67
+ }
68
+
69
+ set docPhaseInfo(value: string | null) {
70
+ this._docPhaseInfo = value || null;
71
+ }
72
+
73
+ @api
74
+ get sidebarContent(): unknown {
75
+ return this._sidebarContent;
76
+ }
77
+
78
+ set sidebarContent(value: string) {
79
+ this._sidebarContent = decorateTopicsWithForwardArrow(
80
+ toJson(value)?.topics
81
+ );
82
+ }
83
+
84
+ private get enableFooter(): boolean {
85
+ return !this.hideFooter;
86
+ }
87
+ }
@@ -2,7 +2,6 @@
2
2
  <doc-content-layout
3
3
  lwc:if={displayContent}
4
4
  lwc:ref="docContentLayout"
5
- enable-data-cloud-search
6
5
  sidebar-header={docTitle}
7
6
  sidebar-content={sidebarContent}
8
7
  sidebar-value={sidebarValue}
@@ -254,6 +254,17 @@ export default class DocXmlContent extends LightningElementWithState<{
254
254
  return this.pageReference.deliverable;
255
255
  }
256
256
 
257
+ private get useOldSidebar(): boolean {
258
+ // Coveo is enabled and the version is greater than 51 (within the latest 3 versions)
259
+ // TODO: we need a better fix for version number check
260
+ return !(
261
+ !this.version?.releaseVersion ||
262
+ (this.version?.releaseVersion &&
263
+ parseInt(this.version.releaseVersion.replace("v", ""), 10) >=
264
+ 53)
265
+ );
266
+ }
267
+
257
268
  private get pageHeader(): Header {
258
269
  if (!this._pageHeader) {
259
270
  this._pageHeader = document.querySelector("doc-header")!;
@@ -0,0 +1,160 @@
1
+ // Neutral shared core for the DWO unified-search UI (P4.1).
2
+ // The ONLY place a /api/search URL is built, and the ONLY place the HTTP
3
+ // contract lives. No LWC / arch / dx imports — browser DOM APIs only.
4
+
5
+ export interface SearchResult {
6
+ url: string;
7
+ title: string;
8
+ description: string | null;
9
+ locale: string;
10
+ site: string | null;
11
+ contentType: string | null;
12
+ lastmod: string | null;
13
+ score: number;
14
+ lexScore: number;
15
+ semScore: number;
16
+ matchType: string;
17
+ }
18
+
19
+ export interface FacetBucket {
20
+ value: string;
21
+ count: number;
22
+ }
23
+
24
+ export type SortOption = "relevance" | "date";
25
+
26
+ export interface SearchResponse {
27
+ query: string;
28
+ locale: string;
29
+ site: string | null;
30
+ sort: SortOption;
31
+ limit: number;
32
+ offset: number;
33
+ total: number;
34
+ count: number;
35
+ facets: { contentType: FacetBucket[] };
36
+ results: SearchResult[];
37
+ }
38
+
39
+ export interface SearchRequest {
40
+ query: string;
41
+ locale: string;
42
+ site?: string | null;
43
+ type?: string | null;
44
+ sort?: SortOption;
45
+ limit?: number;
46
+ offset?: number;
47
+ page?: number;
48
+ }
49
+
50
+ export const DEFAULT_LIMIT = 20;
51
+
52
+ export const SORT_OPTIONS: SortOption[] = ["relevance", "date"];
53
+
54
+ export function isSortOption(v: unknown): v is SortOption {
55
+ return v === "relevance" || v === "date";
56
+ }
57
+
58
+ /**
59
+ * Build the query string for a /api/search request.
60
+ * - 'q' always carries the query.
61
+ * - 'lang' (lowercased) ONLY when the query has non-whitespace content.
62
+ * - 'site' / 'type' ONLY when truthy.
63
+ * - 'sort' ONLY when it is a known SortOption (never send an unknown sort).
64
+ * - 'limit' when provided.
65
+ * - OFFSET WINS OVER PAGE: if offset is given, emit it; otherwise derive
66
+ * offset from page. Never emit both, and never emit 'page'.
67
+ */
68
+ export function buildSearchParams(req: SearchRequest): URLSearchParams {
69
+ const params = new URLSearchParams();
70
+
71
+ params.set("q", req.query);
72
+
73
+ if (req.query.trim() !== "") {
74
+ params.set("lang", req.locale.toLowerCase());
75
+ }
76
+
77
+ if (req.site) {
78
+ params.set("site", req.site);
79
+ }
80
+ if (req.type) {
81
+ params.set("type", req.type);
82
+ }
83
+ if (isSortOption(req.sort)) {
84
+ params.set("sort", req.sort);
85
+ }
86
+ if (req.limit != null) {
87
+ params.set("limit", String(req.limit));
88
+ }
89
+
90
+ if (req.offset != null) {
91
+ params.set("offset", String(req.offset));
92
+ } else if (req.page != null) {
93
+ const limit = req.limit || DEFAULT_LIMIT;
94
+ const offset = (Math.max(1, req.page) - 1) * limit;
95
+ params.set("offset", String(offset));
96
+ }
97
+
98
+ return params;
99
+ }
100
+
101
+ export function searchUrl(
102
+ req: SearchRequest,
103
+ basePath = "/api/search"
104
+ ): string {
105
+ return `${basePath}?${buildSearchParams(req)}`;
106
+ }
107
+
108
+ export class SearchHttpError extends Error {
109
+ readonly status: number;
110
+
111
+ constructor(status: number, message?: string) {
112
+ super(message ?? `Search request failed with status ${status}`);
113
+ this.name = "SearchHttpError";
114
+ this.status = status;
115
+ }
116
+ }
117
+
118
+ export async function fetchSearch(
119
+ req: SearchRequest,
120
+ opts?: { signal?: AbortSignal; basePath?: string; fetchImpl?: typeof fetch }
121
+ ): Promise<SearchResponse> {
122
+ const fetchImpl = opts?.fetchImpl ?? fetch.bind(window);
123
+ const url = searchUrl(req, opts?.basePath);
124
+
125
+ const response = await fetchImpl(url, { signal: opts?.signal });
126
+
127
+ if (!response.ok) {
128
+ throw new SearchHttpError(response.status);
129
+ }
130
+
131
+ const data = (await response.json()) as Partial<SearchResponse>;
132
+
133
+ if (
134
+ !Array.isArray(data.results) ||
135
+ typeof data.total !== "number" ||
136
+ !data.facets ||
137
+ !Array.isArray(data.facets.contentType)
138
+ ) {
139
+ throw new Error(
140
+ "Malformed search response: missing results/total/facets"
141
+ );
142
+ }
143
+
144
+ return data as SearchResponse;
145
+ }
146
+
147
+ /**
148
+ * Decode HTML entities in a backend-supplied string (a response-normalization
149
+ * concern, ported from arch/searchList). No-op on plain strings.
150
+ */
151
+ export function decodeHtmlEntities(value: unknown): string {
152
+ if (typeof value !== "string" || value.length === 0) {
153
+ return String(value ?? "");
154
+ }
155
+ if (!value.includes("&")) {
156
+ return value;
157
+ }
158
+ const doc = new DOMParser().parseFromString(value, "text/html");
159
+ return doc.documentElement.textContent ?? "";
160
+ }
@@ -0,0 +1,90 @@
1
+ // Manual mock of SearchController for wrapper-test isolation.
2
+ //
3
+ // USE THE AUTOMOCK FORM — bare jest.mock with NO factory:
4
+ //
5
+ // jest.mock("docUtils/searchController");
6
+ //
7
+ // Despite docUtils/* being remapped by jest's moduleNameMapper ($1/$2/$2),
8
+ // jest still resolves the bare jest.mock() to this adjacent __mocks__ folder
9
+ // (verified by probe). Do NOT use a factory that re-requires the BARE
10
+ // specifier `docUtils/searchController/__mocks__/searchController` — the
11
+ // mapper rewrites it to .../__mocks__/searchController/searchController and
12
+ // jest cannot find it (also verified by probe). If a factory is ever needed,
13
+ // use a RELATIVE require: require("../__mocks__/searchController").
14
+
15
+ import type {
16
+ SearchControllerArgs,
17
+ SearchViewModel
18
+ } from "docUtils/searchController";
19
+
20
+ const baseViewModel: SearchViewModel = {
21
+ status: "idle",
22
+ query: "",
23
+ locale: "en-us",
24
+ selectedType: null,
25
+ sort: "relevance",
26
+ results: [],
27
+ contentTypeFacets: [],
28
+ total: 0,
29
+ count: 0,
30
+ limit: 20,
31
+ offset: 0,
32
+ page: 1,
33
+ totalPages: 1,
34
+ errorMessage: undefined
35
+ };
36
+
37
+ export class SearchController {
38
+ // eslint-disable-next-line no-use-before-define
39
+ static instances: SearchController[] = [];
40
+
41
+ args: SearchControllerArgs;
42
+ vm: SearchViewModel = { ...baseViewModel };
43
+ private subscribers = new Set<(vm: SearchViewModel) => void>();
44
+
45
+ init = jest.fn();
46
+ setQuery = jest.fn();
47
+ setLanguage = jest.fn();
48
+ setType = jest.fn();
49
+ setSort = jest.fn();
50
+ setPage = jest.fn();
51
+ buildUrl = jest.fn(() => "/api/search?q=&lang=en-us");
52
+ dispose = jest.fn();
53
+
54
+ constructor(args: SearchControllerArgs) {
55
+ this.args = args;
56
+ this.vm = {
57
+ ...baseViewModel,
58
+ locale: args.defaultLanguage ?? baseViewModel.locale,
59
+ limit: args.limit ?? baseViewModel.limit
60
+ };
61
+ SearchController.instances.push(this);
62
+ }
63
+
64
+ get viewModel(): SearchViewModel {
65
+ return this.vm;
66
+ }
67
+
68
+ get localeOptions() {
69
+ return this.args.catalog;
70
+ }
71
+
72
+ get showLocaleSelector(): boolean {
73
+ return this.args.catalog.length > 1;
74
+ }
75
+
76
+ subscribe = jest.fn((cb: (vm: SearchViewModel) => void): (() => void) => {
77
+ this.subscribers.add(cb);
78
+ return () => {
79
+ this.subscribers.delete(cb);
80
+ };
81
+ });
82
+
83
+ /** Test helper: push a (partial) view-model to all subscribers. */
84
+ __emit(vm: Partial<SearchViewModel>): void {
85
+ this.vm = { ...this.vm, ...vm };
86
+ for (const cb of this.subscribers) {
87
+ cb(this.vm);
88
+ }
89
+ }
90
+ }