@salesforcedevs/docs-components 1.3.156-canary.0 → 1.3.168

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.3.156-canary.0",
3
+ "version": "1.3.168",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -24,5 +24,5 @@
24
24
  "@types/lodash.orderby": "^4.6.7",
25
25
  "@types/lodash.uniqby": "^4.7.7"
26
26
  },
27
- "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
27
+ "gitHead": "a300f0b70cfe59d640dd1d9d339201e9441534b6"
28
28
  }
@@ -9,7 +9,7 @@ type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
9
9
 
10
10
  declare const Sprig: (eventType: string, eventNme: string) => void;
11
11
 
12
- const TOC_HEADER_TAG = "DOC-HEADING";
12
+ const TOC_HEADER_TAG = "doc-heading";
13
13
  const HIGHLIGHTABLE_SELECTOR = [
14
14
  "p",
15
15
  "h1",
@@ -23,7 +23,7 @@ const HIGHLIGHTABLE_SELECTOR = [
23
23
  "th",
24
24
  "td"
25
25
  ].join(",");
26
- const OBSERVER_ATTACH_WAIT_TIME = 500;
26
+ export const OBSERVER_ATTACH_WAIT_TIME = 500;
27
27
 
28
28
  export default class ContentLayout extends LightningElement {
29
29
  @api sidebarValue: string;
@@ -255,8 +255,9 @@ export default class ContentLayout extends LightningElement {
255
255
  });
256
256
 
257
257
  // Adjust right nav bar position when doc phase is present
258
- const rightNavBarEl =
259
- this.template.querySelector(".right-nav-bar");
258
+ const rightNavBarEl = this.template.querySelector(
259
+ ".right-nav-bar"
260
+ );
260
261
 
261
262
  if (rightNavBarEl) {
262
263
  rightNavBarEl.style.top = `${
@@ -302,6 +303,7 @@ export default class ContentLayout extends LightningElement {
302
303
 
303
304
  // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
304
305
  const headingElements = document.querySelectorAll(TOC_HEADER_TAG);
306
+
305
307
  for (const headingElement of headingElements) {
306
308
  // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
307
309
  const id = headingElement.getAttribute("id");
@@ -318,17 +320,14 @@ export default class ContentLayout extends LightningElement {
318
320
  };
319
321
 
320
322
  onSlotChange(event: Event): void {
321
- const slotElements = (
322
- event.target as HTMLSlotElement
323
- ).assignedElements();
323
+ const slotElements = (event.target as HTMLSlotElement).assignedElements();
324
324
 
325
325
  if (slotElements.length) {
326
326
  this.contentLoaded = true;
327
327
  const slotContentElement = slotElements[0];
328
- const headingElements =
329
- slotContentElement.ownerDocument?.getElementsByTagName(
330
- TOC_HEADER_TAG
331
- );
328
+ const headingElements = slotContentElement.ownerDocument?.getElementsByTagName(
329
+ TOC_HEADER_TAG
330
+ );
332
331
 
333
332
  for (const headingElement of headingElements) {
334
333
  // Sometimes elements hash is not being set when slot content is wrapped with div
@@ -13,7 +13,7 @@ import {
13
13
  TocMap
14
14
  } from "./types";
15
15
  import { SearchSyncer } from "docUtils/SearchSyncer";
16
- import { LightningElementWithState } from "dxBaseElements/lightningElementWithState";
16
+ import { LightningElementWithState } from "docBaseElements/lightningElementWithState";
17
17
  import { oldVersionDocInfo } from "docUtils/utils";
18
18
  import { Breadcrumb, DocPhaseInfo, Language } from "typings/custom";
19
19
  import { track as trackGTM } from "dxUtils/analytics";
@@ -0,0 +1,93 @@
1
+ import { LightningElement, track } from "lwc";
2
+
3
+ /**
4
+ * This is a helper class for when you want your LWC component to have state
5
+ * that is automatically tracked _along with_ its previous state, in a React-
6
+ * like fashion, so that you can compare current state with previous state
7
+ * after a render (like React's `commponentDidUpdate`). One benefit of doing
8
+ * things this way is that you can put all of your reactions to state changes
9
+ * in one place, in `renderedCallback`, rather than having them in various
10
+ * places throughout the component.
11
+ *
12
+ * The API consists in `this.prevState`, `this.state`, and `this.setState`.
13
+ *
14
+ * Usage:
15
+ *
16
+ * ```
17
+ * type MyState = {
18
+ * isFetchingContent: boolean;
19
+ * };
20
+ *
21
+ * class MyFetchingComponent extends LightningElementWithState<MyState> {
22
+ * constructor() {
23
+ * // `this.state` can only be initialized once
24
+ * this.state = {
25
+ * isFetchingContent: false
26
+ * };
27
+ * }
28
+ *
29
+ * // Queued for execution whenever a `setState` call completes
30
+ * renderedCallback() {
31
+ * if (this.prevState.isFetchingContent && !this.state.isFetchingContent) {
32
+ * // Do something knowing that we just finished fetching.
33
+ * notifyFetchSuccessful();
34
+ * }
35
+ * }
36
+ *
37
+ * fetchSomething() {
38
+ * this.setState({
39
+ * isFetchingContent: true
40
+ * });
41
+ *
42
+ * fetch(whatever).then(() => {
43
+ * this.setState({
44
+ * isFetching: false
45
+ * }
46
+ * });
47
+ * }
48
+ * }
49
+ * ```
50
+ */
51
+ export abstract class LightningElementWithState<
52
+ T extends { [key: string]: unknown }
53
+ > extends LightningElement {
54
+ private _prevState = {} as T;
55
+ @track private _state = {} as T;
56
+
57
+ private _didInitializeState = false;
58
+
59
+ protected get prevState(): T {
60
+ return Object.freeze({
61
+ ...this._prevState
62
+ });
63
+ }
64
+
65
+ protected get state(): T {
66
+ return Object.freeze({
67
+ ...this._state
68
+ });
69
+ }
70
+
71
+ protected set state(initialState: T) {
72
+ if (!this._didInitializeState) {
73
+ this._state = {
74
+ ...initialState
75
+ };
76
+ this._didInitializeState = true;
77
+ } else {
78
+ throw new Error(
79
+ "To mutate state after initialization, use `this.setState`."
80
+ );
81
+ }
82
+ }
83
+
84
+ protected setState = (state: Partial<T>): void => {
85
+ this._prevState = {
86
+ ...this._state
87
+ };
88
+ this._state = {
89
+ ...this._state,
90
+ ...state
91
+ };
92
+ };
93
+ }