@chayns-components/core 5.5.24 → 5.5.25
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/AGENTS.md +44 -0
- package/lib/cjs/components/copyable-content/CopyableContent.test.js +38 -4
- package/lib/cjs/components/copyable-content/CopyableContent.test.js.map +1 -1
- package/lib/cjs/components/truncation/Truncation.js +61 -149
- package/lib/cjs/components/truncation/Truncation.js.map +1 -1
- package/lib/cjs/components/truncation/Truncation.styles.js +3 -4
- package/lib/cjs/components/truncation/Truncation.styles.js.map +1 -1
- package/lib/cjs/components/truncation/Truncation.test.js +61 -0
- package/lib/cjs/components/truncation/Truncation.test.js.map +1 -0
- package/lib/esm/components/copyable-content/CopyableContent.test.js +38 -4
- package/lib/esm/components/copyable-content/CopyableContent.test.js.map +1 -1
- package/lib/esm/components/truncation/Truncation.js +61 -149
- package/lib/esm/components/truncation/Truncation.js.map +1 -1
- package/lib/esm/components/truncation/Truncation.styles.js +2 -3
- package/lib/esm/components/truncation/Truncation.styles.js.map +1 -1
- package/lib/esm/components/truncation/Truncation.test.js +58 -0
- package/lib/esm/components/truncation/Truncation.test.js.map +1 -0
- package/lib/types/components/truncation/Truncation.d.ts +1 -1
- package/lib/types/components/truncation/Truncation.styles.d.ts +1 -1
- package/package.json +2 -2
- package/lib/cjs/utils/truncation.js +0 -42
- package/lib/cjs/utils/truncation.js.map +0 -1
- package/lib/esm/utils/truncation.js +0 -35
- package/lib/esm/utils/truncation.js.map +0 -1
- package/lib/types/utils/truncation.d.ts +0 -1
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.truncateElement = void 0;
|
|
7
|
-
const doesElementOverflow = (element, referenceHeight) => element.scrollHeight > referenceHeight;
|
|
8
|
-
const doesElementHasOnlyText = element => {
|
|
9
|
-
// Check if element has no child elements.
|
|
10
|
-
if (element.children.length === 0) {
|
|
11
|
-
// If element has text (not empty), it is only text.
|
|
12
|
-
return element.textContent !== '';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Element has child elements or no text, so it's not only text.
|
|
16
|
-
return false;
|
|
17
|
-
};
|
|
18
|
-
const removeLastLeafElement = element => {
|
|
19
|
-
// remove last element of html element where the last element is a leaf element and its content is a string
|
|
20
|
-
const {
|
|
21
|
-
lastElementChild,
|
|
22
|
-
lastChild
|
|
23
|
-
} = element;
|
|
24
|
-
if (lastElementChild && !doesElementHasOnlyText(lastElementChild) && lastElementChild.hasChildNodes()) {
|
|
25
|
-
removeLastLeafElement(lastElementChild);
|
|
26
|
-
} else if (lastChild && lastChild.nodeType === Node.TEXT_NODE && lastChild.textContent && lastChild.textContent.length > 25) {
|
|
27
|
-
lastChild.textContent = `${lastChild.textContent.substring(0, lastChild.textContent.length - 25)} ...`;
|
|
28
|
-
} else if (lastElementChild && doesElementHasOnlyText(lastElementChild) && lastElementChild.textContent && lastElementChild.textContent.length > 25) {
|
|
29
|
-
lastElementChild.textContent = `${lastElementChild.textContent.substring(0, lastElementChild.textContent.length - 25)} ...`;
|
|
30
|
-
} else if (lastChild) {
|
|
31
|
-
element.removeChild(lastChild);
|
|
32
|
-
} else if (lastElementChild) {
|
|
33
|
-
element.removeChild(lastElementChild);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const truncateElement = (element, referenceHeight) => {
|
|
37
|
-
while (doesElementOverflow(element, referenceHeight)) {
|
|
38
|
-
removeLastLeafElement(element);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
exports.truncateElement = truncateElement;
|
|
42
|
-
//# sourceMappingURL=truncation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"truncation.js","names":["doesElementOverflow","element","referenceHeight","scrollHeight","doesElementHasOnlyText","children","length","textContent","removeLastLeafElement","lastElementChild","lastChild","hasChildNodes","nodeType","Node","TEXT_NODE","substring","removeChild","truncateElement","exports"],"sources":["../../../src/utils/truncation.ts"],"sourcesContent":["const doesElementOverflow = (element: HTMLElement, referenceHeight: number): boolean =>\n element.scrollHeight > referenceHeight;\n\nconst doesElementHasOnlyText = (element: HTMLElement): boolean => {\n // Check if element has no child elements.\n if (element.children.length === 0) {\n // If element has text (not empty), it is only text.\n return element.textContent !== '';\n }\n\n // Element has child elements or no text, so it's not only text.\n return false;\n};\n\nconst removeLastLeafElement = (element: HTMLElement) => {\n // remove last element of html element where the last element is a leaf element and its content is a string\n const { lastElementChild, lastChild } = element;\n\n if (\n lastElementChild &&\n !doesElementHasOnlyText(lastElementChild as HTMLElement) &&\n lastElementChild.hasChildNodes()\n ) {\n removeLastLeafElement(lastElementChild as HTMLElement);\n } else if (\n lastChild &&\n lastChild.nodeType === Node.TEXT_NODE &&\n lastChild.textContent &&\n lastChild.textContent.length > 25\n ) {\n lastChild.textContent = `${lastChild.textContent.substring(0, lastChild.textContent.length - 25)} ...`;\n } else if (\n lastElementChild &&\n doesElementHasOnlyText(lastElementChild as HTMLElement) &&\n lastElementChild.textContent &&\n lastElementChild.textContent.length > 25\n ) {\n lastElementChild.textContent = `${lastElementChild.textContent.substring(\n 0,\n lastElementChild.textContent.length - 25,\n )} ...`;\n } else if (lastChild) {\n element.removeChild(lastChild);\n } else if (lastElementChild) {\n element.removeChild(lastElementChild);\n }\n};\nexport const truncateElement = (element: HTMLElement, referenceHeight: number) => {\n while (doesElementOverflow(element, referenceHeight)) {\n removeLastLeafElement(element);\n }\n};\n"],"mappings":";;;;;;AAAA,MAAMA,mBAAmB,GAAGA,CAACC,OAAoB,EAAEC,eAAuB,KACtED,OAAO,CAACE,YAAY,GAAGD,eAAe;AAE1C,MAAME,sBAAsB,GAAIH,OAAoB,IAAc;EAC9D;EACA,IAAIA,OAAO,CAACI,QAAQ,CAACC,MAAM,KAAK,CAAC,EAAE;IAC/B;IACA,OAAOL,OAAO,CAACM,WAAW,KAAK,EAAE;EACrC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AAC;EAClC;AACJ,CAAC;AAACiB,OAAA,CAAAD,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const doesElementOverflow = (element, referenceHeight) => element.scrollHeight > referenceHeight;
|
|
2
|
-
const doesElementHasOnlyText = element => {
|
|
3
|
-
// Check if element has no child elements.
|
|
4
|
-
if (element.children.length === 0) {
|
|
5
|
-
// If element has text (not empty), it is only text.
|
|
6
|
-
return element.textContent !== '';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Element has child elements or no text, so it's not only text.
|
|
10
|
-
return false;
|
|
11
|
-
};
|
|
12
|
-
const removeLastLeafElement = element => {
|
|
13
|
-
// remove last element of html element where the last element is a leaf element and its content is a string
|
|
14
|
-
const {
|
|
15
|
-
lastElementChild,
|
|
16
|
-
lastChild
|
|
17
|
-
} = element;
|
|
18
|
-
if (lastElementChild && !doesElementHasOnlyText(lastElementChild) && lastElementChild.hasChildNodes()) {
|
|
19
|
-
removeLastLeafElement(lastElementChild);
|
|
20
|
-
} else if (lastChild && lastChild.nodeType === Node.TEXT_NODE && lastChild.textContent && lastChild.textContent.length > 25) {
|
|
21
|
-
lastChild.textContent = `${lastChild.textContent.substring(0, lastChild.textContent.length - 25)} ...`;
|
|
22
|
-
} else if (lastElementChild && doesElementHasOnlyText(lastElementChild) && lastElementChild.textContent && lastElementChild.textContent.length > 25) {
|
|
23
|
-
lastElementChild.textContent = `${lastElementChild.textContent.substring(0, lastElementChild.textContent.length - 25)} ...`;
|
|
24
|
-
} else if (lastChild) {
|
|
25
|
-
element.removeChild(lastChild);
|
|
26
|
-
} else if (lastElementChild) {
|
|
27
|
-
element.removeChild(lastElementChild);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export const truncateElement = (element, referenceHeight) => {
|
|
31
|
-
while (doesElementOverflow(element, referenceHeight)) {
|
|
32
|
-
removeLastLeafElement(element);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=truncation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"truncation.js","names":["doesElementOverflow","element","referenceHeight","scrollHeight","doesElementHasOnlyText","children","length","textContent","removeLastLeafElement","lastElementChild","lastChild","hasChildNodes","nodeType","Node","TEXT_NODE","substring","removeChild","truncateElement"],"sources":["../../../src/utils/truncation.ts"],"sourcesContent":["const doesElementOverflow = (element: HTMLElement, referenceHeight: number): boolean =>\n element.scrollHeight > referenceHeight;\n\nconst doesElementHasOnlyText = (element: HTMLElement): boolean => {\n // Check if element has no child elements.\n if (element.children.length === 0) {\n // If element has text (not empty), it is only text.\n return element.textContent !== '';\n }\n\n // Element has child elements or no text, so it's not only text.\n return false;\n};\n\nconst removeLastLeafElement = (element: HTMLElement) => {\n // remove last element of html element where the last element is a leaf element and its content is a string\n const { lastElementChild, lastChild } = element;\n\n if (\n lastElementChild &&\n !doesElementHasOnlyText(lastElementChild as HTMLElement) &&\n lastElementChild.hasChildNodes()\n ) {\n removeLastLeafElement(lastElementChild as HTMLElement);\n } else if (\n lastChild &&\n lastChild.nodeType === Node.TEXT_NODE &&\n lastChild.textContent &&\n lastChild.textContent.length > 25\n ) {\n lastChild.textContent = `${lastChild.textContent.substring(0, lastChild.textContent.length - 25)} ...`;\n } else if (\n lastElementChild &&\n doesElementHasOnlyText(lastElementChild as HTMLElement) &&\n lastElementChild.textContent &&\n lastElementChild.textContent.length > 25\n ) {\n lastElementChild.textContent = `${lastElementChild.textContent.substring(\n 0,\n lastElementChild.textContent.length - 25,\n )} ...`;\n } else if (lastChild) {\n element.removeChild(lastChild);\n } else if (lastElementChild) {\n element.removeChild(lastElementChild);\n }\n};\nexport const truncateElement = (element: HTMLElement, referenceHeight: number) => {\n while (doesElementOverflow(element, referenceHeight)) {\n removeLastLeafElement(element);\n }\n};\n"],"mappings":"AAAA,MAAMA,mBAAmB,GAAGA,CAACC,OAAoB,EAAEC,eAAuB,KACtED,OAAO,CAACE,YAAY,GAA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CAAC;EACzC;AACJ,CAAC;AACD,OAAO,MAAMQ,eAAe,GAAGA,CAAChB,OAAoB,EAAEC,eAAuB,KAAK;EAC9E,OAAOF,mBAAmB,CAACC,OAAO,EAAEC,eAAe,CAAC,EAAE;IAClDM,qBAAqB,CAACP,OAAO,CAAC;EAClC;AACJ,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const truncateElement: (element: HTMLElement, referenceHeight: number) => void;
|