@rh-support/utils 2.1.1-beta.0 → 2.1.2

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.
@@ -0,0 +1,20 @@
1
+ export declare enum CustomElements {
2
+ pfeTabs = "pfe-tabs",
3
+ pfeCollapse = "pfe-collapse"
4
+ }
5
+ interface RequireCustomElementObject {
6
+ /** The custom element you want to check if it has been defined */
7
+ element: CustomElements;
8
+ /** cb that will be called if the custom element has yet to be defined */
9
+ requireCb: () => void;
10
+ }
11
+ /**
12
+ * This function is to check if custom elements exist and require them if they do not.
13
+ * The check is needed because of how the packages are split and that patternfly elements
14
+ * use window.customElements.define without checking if it is already defined, which throws an
15
+ * error. Since our packages are split up and lazy loaded this check is necessary to make sure that
16
+ * the pfelement does not get defined twice.
17
+ */
18
+ export declare function requireCustomElement(elements: RequireCustomElementObject[]): void;
19
+ export {};
20
+ //# sourceMappingURL=customElementUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customElementUtils.d.ts","sourceRoot":"","sources":["../../src/customElementUtils.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACtB,OAAO,aAAa;IACpB,WAAW,iBAAiB;CAC/B;AAED,UAAU,0BAA0B;IAChC,kEAAkE;IAClE,OAAO,EAAE,cAAc,CAAC;IAExB,yEAAyE;IACzE,SAAS,EAAE,MAAM,IAAI,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,0BAA0B,EAAE,QAM1E"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireCustomElement = exports.CustomElements = void 0;
4
+ var CustomElements;
5
+ (function (CustomElements) {
6
+ CustomElements["pfeTabs"] = "pfe-tabs";
7
+ CustomElements["pfeCollapse"] = "pfe-collapse";
8
+ })(CustomElements = exports.CustomElements || (exports.CustomElements = {}));
9
+ /**
10
+ * This function is to check if custom elements exist and require them if they do not.
11
+ * The check is needed because of how the packages are split and that patternfly elements
12
+ * use window.customElements.define without checking if it is already defined, which throws an
13
+ * error. Since our packages are split up and lazy loaded this check is necessary to make sure that
14
+ * the pfelement does not get defined twice.
15
+ */
16
+ function requireCustomElement(elements) {
17
+ elements.forEach((elementObj) => {
18
+ if (window.customElements.get(elementObj.element) === undefined) {
19
+ elementObj.requireCb();
20
+ }
21
+ });
22
+ }
23
+ exports.requireCustomElement = requireCustomElement;
@@ -19,6 +19,7 @@ export * from './searchApiUtils';
19
19
  export * from './scrollUtils';
20
20
  export * from './urlUtils';
21
21
  export * from './validatorUtils';
22
+ export * from './customElementUtils';
22
23
  export * from './userUtils';
23
24
  export * from './styleUtils';
24
25
  export * from './translation-helper';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,gCAAgC,CAAC"}
package/lib/cjs/index.js CHANGED
@@ -31,6 +31,7 @@ __exportStar(require("./searchApiUtils"), exports);
31
31
  __exportStar(require("./scrollUtils"), exports);
32
32
  __exportStar(require("./urlUtils"), exports);
33
33
  __exportStar(require("./validatorUtils"), exports);
34
+ __exportStar(require("./customElementUtils"), exports);
34
35
  __exportStar(require("./userUtils"), exports);
35
36
  __exportStar(require("./styleUtils"), exports);
36
37
  __exportStar(require("./translation-helper"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"recommendationUtils.d.ts","sourceRoot":"","sources":["../../src/recommendationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,0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,MAAM,UAU1C"}
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cleanupMarkDown = exports.decodeMarkTag = exports.truncate = exports.replaceHighlightingData = exports.computeRecommendationAbstract = exports.computeRecommendationTitle = exports.getRecommendationAbstract = exports.getRecommendationTitle = void 0;
7
+ const dompurify_1 = __importDefault(require("dompurify"));
7
8
  const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
8
9
  function getRecommendationTitle(doc) {
9
10
  return !isEmpty_1.default(doc.publishedTitle) ? doc.publishedTitle : doc.allTitle;
@@ -15,12 +16,13 @@ function getRecommendationAbstract(doc) {
15
16
  exports.getRecommendationAbstract = getRecommendationAbstract;
16
17
  function computeRecommendationTitle(doc) {
17
18
  const title = getRecommendationTitle(doc);
18
- return { __html: decodeMarkTag(title) };
19
+ return { __html: dompurify_1.default.sanitize(decodeMarkTag(title)) };
19
20
  }
20
21
  exports.computeRecommendationTitle = computeRecommendationTitle;
21
22
  const computeRecommendationAbstract = (doc, truncateLen = 128) => {
22
23
  const abstract = getRecommendationAbstract(doc);
23
- return { __html: truncate(cleanupMarkDown(decodeMarkTag(abstract)), truncateLen) };
24
+ const processedAbstract = truncate(cleanupMarkDown(decodeMarkTag(abstract)), truncateLen);
25
+ return { __html: dompurify_1.default.sanitize(processedAbstract) };
24
26
  };
25
27
  exports.computeRecommendationAbstract = computeRecommendationAbstract;
26
28
  function replaceHighlightingData(docs, highlighting) {
@@ -0,0 +1,20 @@
1
+ export declare enum CustomElements {
2
+ pfeTabs = "pfe-tabs",
3
+ pfeCollapse = "pfe-collapse"
4
+ }
5
+ interface RequireCustomElementObject {
6
+ /** The custom element you want to check if it has been defined */
7
+ element: CustomElements;
8
+ /** cb that will be called if the custom element has yet to be defined */
9
+ requireCb: () => void;
10
+ }
11
+ /**
12
+ * This function is to check if custom elements exist and require them if they do not.
13
+ * The check is needed because of how the packages are split and that patternfly elements
14
+ * use window.customElements.define without checking if it is already defined, which throws an
15
+ * error. Since our packages are split up and lazy loaded this check is necessary to make sure that
16
+ * the pfelement does not get defined twice.
17
+ */
18
+ export declare function requireCustomElement(elements: RequireCustomElementObject[]): void;
19
+ export {};
20
+ //# sourceMappingURL=customElementUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customElementUtils.d.ts","sourceRoot":"","sources":["../../src/customElementUtils.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACtB,OAAO,aAAa;IACpB,WAAW,iBAAiB;CAC/B;AAED,UAAU,0BAA0B;IAChC,kEAAkE;IAClE,OAAO,EAAE,cAAc,CAAC;IAExB,yEAAyE;IACzE,SAAS,EAAE,MAAM,IAAI,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,0BAA0B,EAAE,QAM1E"}
@@ -0,0 +1,19 @@
1
+ export var CustomElements;
2
+ (function (CustomElements) {
3
+ CustomElements["pfeTabs"] = "pfe-tabs";
4
+ CustomElements["pfeCollapse"] = "pfe-collapse";
5
+ })(CustomElements || (CustomElements = {}));
6
+ /**
7
+ * This function is to check if custom elements exist and require them if they do not.
8
+ * The check is needed because of how the packages are split and that patternfly elements
9
+ * use window.customElements.define without checking if it is already defined, which throws an
10
+ * error. Since our packages are split up and lazy loaded this check is necessary to make sure that
11
+ * the pfelement does not get defined twice.
12
+ */
13
+ export function requireCustomElement(elements) {
14
+ elements.forEach((elementObj) => {
15
+ if (window.customElements.get(elementObj.element) === undefined) {
16
+ elementObj.requireCb();
17
+ }
18
+ });
19
+ }
@@ -19,6 +19,7 @@ export * from './searchApiUtils';
19
19
  export * from './scrollUtils';
20
20
  export * from './urlUtils';
21
21
  export * from './validatorUtils';
22
+ export * from './customElementUtils';
22
23
  export * from './userUtils';
23
24
  export * from './styleUtils';
24
25
  export * from './translation-helper';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../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C5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,gCAAgC,CAAC"}
package/lib/esm/index.js CHANGED
@@ -19,6 +19,7 @@ export * from './searchApiUtils';
19
19
  export * from './scrollUtils';
20
20
  export * from './urlUtils';
21
21
  export * from './validatorUtils';
22
+ export * from './customElementUtils';
22
23
  export * from './userUtils';
23
24
  export * from './styleUtils';
24
25
  export * from './translation-helper';
@@ -1 +1 @@
1
- {"version":3,"file":"recommendationUtils.d.ts","sourceRoot":"","sources":["../../src/recommendationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAG7F,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,mBAAmB,GAAG,MAAM,CAEvE;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,mBAAmB,GAAG,MAAM,CAE1E;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,mBAAmB;;EAGlE;AACD,eAAO,MAAM,6BAA6B;;CAGzC,CAAC;AAEF,wBAAgB,uBAAuB,CACnC,IAAI,EAAE,mBAAmB,EAAE,EAC3B,YAAY,EAAE,YAAY,GAC3B,mBAAmB,EAAE,CAevB;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,UAU1C"}
1
+ {"version":3,"file":"recommendationUtils.d.ts","sourceRoot":"","sources":["../../src/recommendationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAI7F,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,mBAAmB,GAAG,MAAM,CAEvE;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,mBAAmB,GAAG,MAAM,CAE1E;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,mBAAmB;;EAGlE;AACD,eAAO,MAAM,6BAA6B;;CAIzC,CAAC;AAEF,wBAAgB,uBAAuB,CACnC,IAAI,EAAE,mBAAmB,EAAE,EAC3B,YAAY,EAAE,YAAY,GAC3B,mBAAmB,EAAE,CAevB;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,UAU1C"}
@@ -1,3 +1,4 @@
1
+ import DOMPurify from 'dompurify';
1
2
  import isEmpty from 'lodash/isEmpty';
2
3
  export function getRecommendationTitle(doc) {
3
4
  return !isEmpty(doc.publishedTitle) ? doc.publishedTitle : doc.allTitle;
@@ -7,11 +8,12 @@ export function getRecommendationAbstract(doc) {
7
8
  }
8
9
  export function computeRecommendationTitle(doc) {
9
10
  const title = getRecommendationTitle(doc);
10
- return { __html: decodeMarkTag(title) };
11
+ return { __html: DOMPurify.sanitize(decodeMarkTag(title)) };
11
12
  }
12
13
  export const computeRecommendationAbstract = (doc, truncateLen = 128) => {
13
14
  const abstract = getRecommendationAbstract(doc);
14
- return { __html: truncate(cleanupMarkDown(decodeMarkTag(abstract)), truncateLen) };
15
+ const processedAbstract = truncate(cleanupMarkDown(decodeMarkTag(abstract)), truncateLen);
16
+ return { __html: DOMPurify.sanitize(processedAbstract) };
15
17
  };
16
18
  export function replaceHighlightingData(docs, highlighting) {
17
19
  return docs.map((doc) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/utils",
3
- "version": "2.1.1-beta.0",
3
+ "version": "2.1.2",
4
4
  "description": "> TODO: description",
5
5
  "author": "Vikas Rathee <vrathee@redhat.com>",
6
6
  "license": "ISC",
@@ -88,5 +88,5 @@
88
88
  "defaults and supports es6-module",
89
89
  "maintained node versions"
90
90
  ],
91
- "gitHead": "26b230a88e7957f7162cbd51622a640abaa328f8"
91
+ "gitHead": "8f7f0aee0461c78e8a5cc0e16777371c4ae1305d"
92
92
  }