@salesforcedevs/docs-components 1.32.0-alpha.8 → 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,420 @@
1
+ // Plain (non-LWC) stateful orchestrator shared by the arch + dx search
2
+ // wrappers. No LWC / arch / dx imports — brand specifics are injected.
3
+
4
+ import {
5
+ DEFAULT_LIMIT,
6
+ fetchSearch,
7
+ isSortOption,
8
+ searchUrl,
9
+ SearchHttpError
10
+ } from "docUtils/searchClient";
11
+ import type {
12
+ FacetBucket,
13
+ SearchRequest,
14
+ SearchResult,
15
+ SortOption
16
+ } from "docUtils/searchClient";
17
+ import { resolveInitialLanguage } from "docUtils/searchLocale";
18
+ import type { LocaleDeps, LocaleOption } from "docUtils/searchLocale";
19
+
20
+ export type SearchStatus = "idle" | "loading" | "results" | "empty" | "error";
21
+
22
+ export interface SearchViewModel {
23
+ status: SearchStatus;
24
+ query: string;
25
+ locale: string;
26
+ selectedType: string | null;
27
+ sort: SortOption;
28
+ results: SearchResult[];
29
+ contentTypeFacets: FacetBucket[];
30
+ total: number;
31
+ count: number;
32
+ limit: number;
33
+ offset: number;
34
+ page: number;
35
+ totalPages: number;
36
+ errorMessage?: string;
37
+ }
38
+
39
+ export interface SearchControllerArgs {
40
+ catalog: LocaleOption[];
41
+ defaultLanguage: string;
42
+ supportedIds: string[];
43
+ site?: string | null;
44
+ limit?: number;
45
+ basePath?: string;
46
+ deps: LocaleDeps;
47
+ instrument?: (event: string, payload: Record<string, unknown>) => void;
48
+ fetchImpl?: typeof fetch;
49
+ historyMethod?: (
50
+ data: unknown,
51
+ unused: string,
52
+ url?: string | null
53
+ ) => void;
54
+ debounceMs?: number;
55
+ }
56
+
57
+ export class SearchController {
58
+ private readonly catalog: LocaleOption[];
59
+ private readonly defaultLanguage: string;
60
+ private readonly supportedIds: string[];
61
+ private readonly site: string | null;
62
+ private readonly limit: number;
63
+ private readonly basePath?: string;
64
+ private readonly deps: LocaleDeps;
65
+ private readonly instrument?: SearchControllerArgs["instrument"];
66
+ private readonly fetchImpl: typeof fetch;
67
+ private readonly historyMethod: (
68
+ data: unknown,
69
+ unused: string,
70
+ url?: string | null
71
+ ) => void;
72
+ private readonly debounceMs: number;
73
+
74
+ // Mutable state.
75
+ private status: SearchStatus = "idle";
76
+ private query = "";
77
+ private locale: string;
78
+ private selectedType: string | null = null;
79
+ private sort: SortOption = "relevance";
80
+ private results: SearchResult[] = [];
81
+ private contentTypeFacets: FacetBucket[] = [];
82
+ private total = 0;
83
+ private count = 0;
84
+ private offset = 0;
85
+ private page = 1;
86
+ private errorMessage?: string;
87
+
88
+ private abortController?: AbortController;
89
+ private debounceTimer?: ReturnType<typeof setTimeout>;
90
+ private subscribers = new Set<(vm: SearchViewModel) => void>();
91
+
92
+ constructor(args: SearchControllerArgs) {
93
+ this.catalog = args.catalog;
94
+ this.defaultLanguage = args.defaultLanguage;
95
+ this.supportedIds = args.supportedIds;
96
+ this.site = args.site ?? null;
97
+ this.limit = args.limit ?? DEFAULT_LIMIT;
98
+ this.basePath = args.basePath;
99
+ this.deps = args.deps;
100
+ this.instrument = args.instrument;
101
+ this.fetchImpl = args.fetchImpl ?? fetch.bind(window);
102
+ this.historyMethod = (
103
+ args.historyMethod ?? window.history.replaceState
104
+ ).bind(window.history);
105
+ this.debounceMs = args.debounceMs ?? 250;
106
+ this.locale = this.defaultLanguage;
107
+ }
108
+
109
+ // ---- public reads -------------------------------------------------
110
+
111
+ get viewModel(): SearchViewModel {
112
+ return {
113
+ status: this.status,
114
+ query: this.query,
115
+ locale: this.locale,
116
+ selectedType: this.selectedType,
117
+ sort: this.sort,
118
+ results: this.results,
119
+ contentTypeFacets: this.contentTypeFacets,
120
+ total: this.total,
121
+ count: this.count,
122
+ limit: this.limit,
123
+ offset: this.offset,
124
+ page: this.page,
125
+ totalPages: Math.max(1, Math.ceil(this.total / this.limit)),
126
+ errorMessage: this.errorMessage
127
+ };
128
+ }
129
+
130
+ get localeOptions(): LocaleOption[] {
131
+ return this.catalog;
132
+ }
133
+
134
+ get showLocaleSelector(): boolean {
135
+ return this.catalog.length > 1;
136
+ }
137
+
138
+ // ---- lifecycle ----------------------------------------------------
139
+
140
+ init(): void {
141
+ const search = window.location.search;
142
+ this.locale = resolveInitialLanguage({
143
+ supportedIds: this.supportedIds,
144
+ defaultLanguage: this.defaultLanguage,
145
+ search,
146
+ navigatorLanguages:
147
+ typeof navigator !== "undefined"
148
+ ? navigator.languages
149
+ : undefined,
150
+ deps: this.deps
151
+ });
152
+
153
+ const params = new URLSearchParams(search);
154
+ this.query = params.get("q") ?? "";
155
+ this.selectedType = params.get("type") || null;
156
+ const rawSort = params.get("sort");
157
+ this.sort = isSortOption(rawSort) ? rawSort : "relevance";
158
+ const rawPage = parseInt(params.get("page") ?? "", 10);
159
+ this.page = Number.isFinite(rawPage) && rawPage >= 1 ? rawPage : 1;
160
+ this.offset = (this.page - 1) * this.limit;
161
+
162
+ window.addEventListener("popstate", this.handlePopState);
163
+
164
+ if (this.query.trim() !== "") {
165
+ this.runQuery();
166
+ } else {
167
+ // No query at boot is the resting state, not an executed empty
168
+ // search — keep status 'idle' so the UI can show its prompt.
169
+ this.status = "idle";
170
+ this.notify();
171
+ }
172
+ }
173
+
174
+ dispose(): void {
175
+ this.abortController?.abort();
176
+ this.abortController = undefined;
177
+ if (this.debounceTimer != null) {
178
+ clearTimeout(this.debounceTimer);
179
+ this.debounceTimer = undefined;
180
+ }
181
+ window.removeEventListener("popstate", this.handlePopState);
182
+ this.subscribers.clear();
183
+ }
184
+
185
+ // ---- subscription -------------------------------------------------
186
+
187
+ subscribe(cb: (vm: SearchViewModel) => void): () => void {
188
+ this.subscribers.add(cb);
189
+ return () => {
190
+ this.subscribers.delete(cb);
191
+ };
192
+ }
193
+
194
+ // ---- mutations ----------------------------------------------------
195
+
196
+ setQuery(q: string): void {
197
+ this.query = q;
198
+ this.page = 1;
199
+ this.offset = 0;
200
+
201
+ // Abort any prior in-flight request before scheduling/firing.
202
+ this.abortController?.abort();
203
+ this.abortController = undefined;
204
+ if (this.debounceTimer != null) {
205
+ clearTimeout(this.debounceTimer);
206
+ this.debounceTimer = undefined;
207
+ }
208
+
209
+ if (q.trim() === "") {
210
+ this.applyEmpty();
211
+ this.syncUrl();
212
+ this.notify();
213
+ return;
214
+ }
215
+
216
+ this.debounceTimer = setTimeout(() => {
217
+ this.debounceTimer = undefined;
218
+ this.syncUrl();
219
+ this.runQuery();
220
+ }, this.debounceMs);
221
+ }
222
+
223
+ setLanguage(id: string): void {
224
+ this.locale = id;
225
+ this.deps.setStored(id);
226
+ this.page = 1;
227
+ this.offset = 0;
228
+ this.syncUrl();
229
+ if (this.query.trim() !== "") {
230
+ this.runQuery();
231
+ } else {
232
+ this.applyEmpty();
233
+ this.notify();
234
+ }
235
+ }
236
+
237
+ setType(type: string | null): void {
238
+ // Disjunctive toggle: selecting the active type clears it.
239
+ this.selectedType = this.selectedType === type ? null : type;
240
+ this.page = 1;
241
+ this.offset = 0;
242
+ this.syncUrl();
243
+ if (this.query.trim() !== "") {
244
+ this.runQuery();
245
+ } else {
246
+ this.applyEmpty();
247
+ this.notify();
248
+ }
249
+ }
250
+
251
+ setSort(s: SortOption): void {
252
+ this.sort = isSortOption(s) ? s : "relevance";
253
+ this.page = 1;
254
+ this.offset = 0;
255
+ this.syncUrl();
256
+ if (this.query.trim() !== "") {
257
+ this.runQuery();
258
+ } else {
259
+ this.applyEmpty();
260
+ this.notify();
261
+ }
262
+ }
263
+
264
+ setPage(page: number): void {
265
+ this.page = Math.max(1, Math.floor(page));
266
+ this.offset = (this.page - 1) * this.limit;
267
+ this.syncUrl();
268
+ if (this.query.trim() !== "") {
269
+ this.runQuery();
270
+ } else {
271
+ this.applyEmpty();
272
+ this.notify();
273
+ }
274
+ }
275
+
276
+ // ---- URLs ---------------------------------------------------------
277
+
278
+ buildUrl(): string {
279
+ return searchUrl(this.currentRequest(), this.basePath);
280
+ }
281
+
282
+ // ---- internals ----------------------------------------------------
283
+
284
+ private currentRequest(): SearchRequest {
285
+ return {
286
+ query: this.query,
287
+ locale: this.locale,
288
+ site: this.site,
289
+ type: this.selectedType,
290
+ sort: this.sort,
291
+ limit: this.limit,
292
+ offset: this.offset
293
+ };
294
+ }
295
+
296
+ private applyEmpty(): void {
297
+ this.status = "empty";
298
+ this.total = 0;
299
+ this.count = 0;
300
+ this.results = [];
301
+ this.contentTypeFacets = [];
302
+ this.errorMessage = undefined;
303
+ }
304
+
305
+ private async runQuery(): Promise<void> {
306
+ // Empty query never fires a request.
307
+ if (this.query.trim() === "") {
308
+ this.applyEmpty();
309
+ this.notify();
310
+ return;
311
+ }
312
+
313
+ this.status = "loading";
314
+ this.errorMessage = undefined;
315
+ this.notify();
316
+
317
+ // Fresh controller; abort the previous one.
318
+ this.abortController?.abort();
319
+ const controller = new AbortController();
320
+ this.abortController = controller;
321
+
322
+ try {
323
+ const response = await fetchSearch(this.currentRequest(), {
324
+ signal: controller.signal,
325
+ basePath: this.basePath,
326
+ fetchImpl: this.fetchImpl
327
+ });
328
+
329
+ this.results = response.results;
330
+ this.contentTypeFacets = response.facets.contentType;
331
+ this.total = response.total;
332
+ this.count = response.results.length;
333
+ this.status = response.results.length ? "results" : "empty";
334
+ this.errorMessage = undefined;
335
+
336
+ if (this.instrument) {
337
+ this.instrument("search", {
338
+ query: this.query,
339
+ locale: this.locale,
340
+ total: this.total
341
+ });
342
+ }
343
+
344
+ this.notify();
345
+ } catch (error) {
346
+ // A superseded/disposed request is not an error.
347
+ if (error instanceof Error && error.name === "AbortError") {
348
+ return;
349
+ }
350
+ this.status = "error";
351
+ this.errorMessage =
352
+ error instanceof SearchHttpError
353
+ ? `Search failed (status ${error.status})`
354
+ : error instanceof Error
355
+ ? error.message
356
+ : "Search failed";
357
+ this.notify();
358
+ }
359
+ }
360
+
361
+ private syncUrl(): void {
362
+ const params = new URLSearchParams(window.location.search);
363
+
364
+ if (this.query.trim() !== "") {
365
+ params.set("q", this.query);
366
+ } else {
367
+ params.delete("q");
368
+ }
369
+
370
+ params.set("lang", this.locale.toLowerCase());
371
+
372
+ if (this.selectedType) {
373
+ params.set("type", this.selectedType);
374
+ } else {
375
+ params.delete("type");
376
+ }
377
+
378
+ if (this.sort && this.sort !== "relevance") {
379
+ params.set("sort", this.sort);
380
+ } else {
381
+ params.delete("sort");
382
+ }
383
+
384
+ if (this.page > 1) {
385
+ params.set("page", String(this.page));
386
+ } else {
387
+ params.delete("page");
388
+ }
389
+
390
+ const url = new URL(window.location.href);
391
+ url.search = params.toString();
392
+ this.historyMethod({}, "", url.toString());
393
+ }
394
+
395
+ private notify(): void {
396
+ const vm = this.viewModel;
397
+ for (const cb of this.subscribers) {
398
+ cb(vm);
399
+ }
400
+ }
401
+
402
+ private handlePopState = (): void => {
403
+ const search = window.location.search;
404
+ const params = new URLSearchParams(search);
405
+ this.query = params.get("q") ?? "";
406
+ this.selectedType = params.get("type") || null;
407
+ const rawSort = params.get("sort");
408
+ this.sort = isSortOption(rawSort) ? rawSort : "relevance";
409
+ const rawPage = parseInt(params.get("page") ?? "", 10);
410
+ this.page = Number.isFinite(rawPage) && rawPage >= 1 ? rawPage : 1;
411
+ this.offset = (this.page - 1) * this.limit;
412
+
413
+ if (this.query.trim() !== "") {
414
+ this.runQuery();
415
+ } else {
416
+ this.applyEmpty();
417
+ this.notify();
418
+ }
419
+ };
420
+ }
@@ -0,0 +1,85 @@
1
+ // Brand-neutral locale cascade for the DWO unified-search UI (P4.1).
2
+ // Lifted from arch/searchList (parseSupportedLocales + resolveInitialLanguage),
3
+ // with browser-match and consent-gated storage INJECTED so the core never
4
+ // imports arch/* or dx/*.
5
+
6
+ export interface LocaleOption {
7
+ id: string;
8
+ displayText?: string;
9
+ label?: string;
10
+ }
11
+
12
+ export interface LocaleDeps {
13
+ getStored: () => string | null;
14
+ setStored: (v: string) => boolean;
15
+ resolveBrowser: (
16
+ langs: readonly string[] | undefined,
17
+ ids: string[]
18
+ ) => string;
19
+ }
20
+
21
+ export const DEFAULT_LANGUAGE = "en-us";
22
+
23
+ /**
24
+ * Parse an injected locale catalog (a JSON string), restricting to entries
25
+ * with a string id. Returns [] on bad / non-array JSON.
26
+ */
27
+ export function parseSupportedLocales(json: string): LocaleOption[] {
28
+ if (!json) {
29
+ return [];
30
+ }
31
+ try {
32
+ const parsed = JSON.parse(json);
33
+ if (!Array.isArray(parsed)) {
34
+ return [];
35
+ }
36
+ return parsed.filter(
37
+ (entry): entry is LocaleOption =>
38
+ !!entry && typeof entry.id === "string"
39
+ );
40
+ } catch (e) {
41
+ return [];
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Resolve the language to search in, most-explicit-wins:
47
+ * 1. ?lang= URL param (shared/bookmarked links)
48
+ * 2. stored preference (consented, from a prior visit)
49
+ * 3. browser preferred language mapped to a supported id
50
+ * 4. the page's server locale, else en-us
51
+ * Any candidate must be in the supported catalog (when one was provided).
52
+ * An unsupported ?lang is IGNORED (we fall through to the next candidate).
53
+ */
54
+ export function resolveInitialLanguage(args: {
55
+ supportedIds: string[];
56
+ defaultLanguage: string;
57
+ search: string;
58
+ navigatorLanguages: readonly string[] | undefined;
59
+ deps: LocaleDeps;
60
+ }): string {
61
+ const { supportedIds, defaultLanguage, search, navigatorLanguages, deps } =
62
+ args;
63
+ const ids = supportedIds;
64
+ const isSupported = (value: string | null | undefined): boolean =>
65
+ !!value && (ids.length === 0 || ids.includes(value));
66
+
67
+ const fromUrl = new URLSearchParams(search).get("lang");
68
+ if (isSupported(fromUrl)) {
69
+ return fromUrl as string;
70
+ }
71
+
72
+ const stored = deps.getStored();
73
+ if (isSupported(stored)) {
74
+ return stored as string;
75
+ }
76
+
77
+ if (ids.length > 0) {
78
+ const detected = deps.resolveBrowser(navigatorLanguages, ids);
79
+ if (isSupported(detected)) {
80
+ return detected;
81
+ }
82
+ }
83
+
84
+ return isSupported(defaultLanguage) ? defaultLanguage : DEFAULT_LANGUAGE;
85
+ }
package/LICENSE DELETED
@@ -1,12 +0,0 @@
1
- Copyright (c) 2020, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.