@salesforcedevs/dx-components 1.43.0-alpha.0 → 1.43.0

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/LICENSE ADDED
@@ -0,0 +1,12 @@
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.
package/lwc.config.json CHANGED
@@ -93,6 +93,7 @@
93
93
  "dx/sectionBanner",
94
94
  "dx/sectionSignup",
95
95
  "dx/sectionSmall",
96
+ "dx/searchRedirect",
96
97
  "dx/select",
97
98
  "dx/sidebar",
98
99
  "dx/sidebarOld",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.43.0-alpha.0",
3
+ "version": "1.43.0",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -43,5 +43,6 @@
43
43
  "eventsourcemock": "2.0.0",
44
44
  "luxon": "3.4.4",
45
45
  "msw": "^2.12.4"
46
- }
46
+ },
47
+ "gitHead": "bf2f0c89b6910f3aa996548889373eb5d0a5fc4e"
47
48
  }
@@ -0,0 +1 @@
1
+ <template></template>
@@ -0,0 +1,111 @@
1
+ import { LightningElement, api } from "lwc";
2
+
3
+ const DEFAULT_LANG = "en-us";
4
+
5
+ // Language ids accepted by the developer-website /search page (`locales` in its
6
+ // content/en-us/pages/search.njk, lowercase BCP 47). The page ignores any ?lang=
7
+ // value outside this set.
8
+ const SEARCH_LANGS = new Set([
9
+ "en-us",
10
+ "ja-jp",
11
+ "de-de",
12
+ "fr-fr",
13
+ "es-es",
14
+ "es-mx",
15
+ "it-it",
16
+ "pt-br",
17
+ "nl-nl",
18
+ "da-dk",
19
+ "fi-fi",
20
+ "nb-no",
21
+ "sv-se",
22
+ "ru-ru",
23
+ "ko-kr",
24
+ "zh-cn",
25
+ "zh-tw"
26
+ ]);
27
+
28
+ // First-path-segment prefixes that imply a language, e.g. /jp/docs -> ja-jp.
29
+ const PATH_PREFIX_LANG: Record<string, string> = {
30
+ jp: "ja-jp",
31
+ jpblogs: "ja-jp"
32
+ };
33
+ const LOCALE_SEGMENT = /^[a-z]{2}-[a-z]{2}$/i;
34
+
35
+ /**
36
+ * Derives the search language id from a URL path. Docs carry the locale as
37
+ * /docs/<product>/<locale>/... or /docs/atlas.<locale>.<guide>/...; other pages
38
+ * lead with it (/ja-jp/...) or use a prefix such as /jp/. Returns en-us when no
39
+ * supported language is found.
40
+ */
41
+ export function langFromPath(pathname: string): string {
42
+ const segs = pathname.split("/").filter(Boolean);
43
+ const first = (segs[0] || "").toLowerCase();
44
+ if (first === "docs" && segs[1]) {
45
+ const atlas = segs[1].match(/^atlas\.([a-z]{2}-[a-z]{2})\./i);
46
+ const code = (
47
+ atlas ? atlas[1] : LOCALE_SEGMENT.test(segs[2] || "") ? segs[2] : ""
48
+ ).toLowerCase();
49
+ if (SEARCH_LANGS.has(code)) {
50
+ return code;
51
+ }
52
+ }
53
+ if (SEARCH_LANGS.has(first)) {
54
+ return first;
55
+ }
56
+ return PATH_PREFIX_LANG[first] || DEFAULT_LANG;
57
+ }
58
+
59
+ /** Builds the relative search URL, adding `lang` only for non-default languages. */
60
+ export function buildSearchUrl(
61
+ searchPath: string,
62
+ query: string,
63
+ pathname: string
64
+ ): string {
65
+ const params = new URLSearchParams({ q: query });
66
+ const lang = langFromPath(pathname);
67
+ if (lang !== DEFAULT_LANG) {
68
+ params.set("lang", lang);
69
+ }
70
+ return `${searchPath}?${params.toString()}`;
71
+ }
72
+
73
+ /**
74
+ * Redirects global nav searches to a search page on the current host.
75
+ *
76
+ * With `search-spa="true"` in the header settings, the nav doesn't navigate on
77
+ * submit; it dispatches `www_spasearch` with { searchTerm } and leaves navigation
78
+ * to the host page. This component handles that event, redirecting to
79
+ * `<searchPath>?q=<term>` and adding `&lang=<id>` when the page isn't English.
80
+ * Render it once next to <dx-global-header>.
81
+ *
82
+ * Mirrors arch-xsf-mfe-events; once Developer and Architect share a search, this
83
+ * can move into dx-global-header.
84
+ */
85
+ export default class SearchRedirect extends LightningElement {
86
+ @api searchPath: string = "/search";
87
+
88
+ connectedCallback(): void {
89
+ document.addEventListener("www_spasearch", this.handleSearch);
90
+ }
91
+
92
+ disconnectedCallback(): void {
93
+ document.removeEventListener("www_spasearch", this.handleSearch);
94
+ }
95
+
96
+ private handleSearch = (event: Event): void => {
97
+ const searchTerm = (
98
+ (event as CustomEvent<{ searchTerm?: string }>).detail
99
+ ?.searchTerm || ""
100
+ ).trim();
101
+ if (searchTerm) {
102
+ window.location.assign(
103
+ buildSearchUrl(
104
+ this.searchPath,
105
+ searchTerm,
106
+ window.location.pathname
107
+ )
108
+ );
109
+ }
110
+ };
111
+ }
@@ -5,11 +5,6 @@
5
5
  padding: var(--dx-g-spacing-sm) 0 var(--dx-g-spacing-2xl);
6
6
  }
7
7
 
8
- .trees-loading {
9
- margin: var(--dx-g-spacing-sm) var(--dx-g-spacing-lg) var(--dx-g-spacing-md)
10
- var(--dx-g-global-header-padding-horizontal);
11
- }
12
-
13
8
  dx-empty-state {
14
9
  --dx-c-empty-state-background-alt: var(--sds-g-gray-1);
15
10
  --dx-c-empty-state-image-width: 400px;
@@ -77,12 +77,6 @@
77
77
  onselecteditemrendered={onSelectedItemRendered}
78
78
  ></dx-tree>
79
79
  </div>
80
- <img
81
- lwc:elseif={loading}
82
- class="trees-loading"
83
- src="https://developer.salesforce.com/ns-assets/sidebar-item-loading.svg"
84
- alt="Loading"
85
- />
86
80
  <dx-empty-state
87
81
  variant="alt"
88
82
  class="padding-horizontal"
@@ -2,7 +2,7 @@ import cx from "classnames";
2
2
  import { api } from "lwc";
3
3
 
4
4
  import { TreeNode } from "typings/custom";
5
- import { normalizeBoolean, toJson } from "dxUtils/normalizers";
5
+ import { toJson } from "dxUtils/normalizers";
6
6
  import { SidebarBase } from "dxBaseElements/sidebarBase";
7
7
  import { escapeRegExp } from "dxUtils/regexps";
8
8
 
@@ -38,17 +38,6 @@ export default class Sidebar extends SidebarBase {
38
38
  this._emptyStateMessage = value;
39
39
  }
40
40
 
41
- /** Shows a loading placeholder instead of the empty state while the trees load. */
42
- @api
43
- get loading(): boolean {
44
- return this._loading;
45
- }
46
-
47
- set loading(value) {
48
- this._loading = normalizeBoolean(value);
49
- }
50
-
51
- private _loading = false;
52
41
  private _searchTimeout?: number;
53
42
  private _trees!: Array<TreeNode>;
54
43