docusaurus-plugin-glossary 3.1.0 → 3.2.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/dist/chunk-4CUFUKUA.js +109 -0
- package/dist/chunk-4CUFUKUA.js.map +1 -0
- package/dist/chunk-PEB4Y6RI.js +311 -0
- package/dist/chunk-PEB4Y6RI.js.map +1 -0
- package/dist/chunk-SNP37IVL.js +212 -0
- package/dist/chunk-SNP37IVL.js.map +1 -0
- package/dist/client/index.cjs +55 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.js +10 -21
- package/dist/client/index.js.map +1 -0
- package/dist/components/GlossaryPage.cjs +130 -0
- package/dist/components/GlossaryPage.cjs.map +1 -0
- package/dist/components/GlossaryPage.js +74 -113
- package/dist/components/GlossaryPage.js.map +1 -0
- package/dist/index.cjs +659 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +173 -0
- package/dist/index.d.ts +82 -11
- package/dist/index.js +23 -173
- package/dist/index.js.map +1 -0
- package/dist/preset.cjs +710 -0
- package/dist/preset.cjs.map +1 -0
- package/dist/preset.d.cts +98 -0
- package/dist/preset.d.ts +8 -7
- package/dist/preset.js +79 -143
- package/dist/preset.js.map +1 -0
- package/dist/remark/glossary-terms.cjs +345 -0
- package/dist/remark/glossary-terms.cjs.map +1 -0
- package/dist/remark/glossary-terms.js +9 -440
- package/dist/remark/glossary-terms.js.map +1 -0
- package/dist/theme/GlossaryTerm/index.cjs +138 -0
- package/dist/theme/GlossaryTerm/index.cjs.map +1 -0
- package/dist/theme/GlossaryTerm/index.js +56 -90
- package/dist/theme/GlossaryTerm/index.js.map +1 -0
- package/dist/validation.cjs +238 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.cts +2 -0
- package/dist/validation.d.ts +2 -44
- package/dist/validation.js +11 -256
- package/dist/validation.js.map +1 -0
- package/package.json +25 -30
- package/dist/components/GlossaryPage.test.js +0 -205
- package/dist/index.d.ts.map +0 -1
- package/dist/preset.d.ts.map +0 -1
- package/dist/remark/glossary-terms.d.ts +0 -28
- package/dist/remark/glossary-terms.d.ts.map +0 -1
- package/dist/theme/GlossaryTerm/index.test.js +0 -143
- package/dist/validation.d.ts.map +0 -1
- /package/dist/{components/GlossaryPage.module.css → GlossaryPage.module-M4DEUP4X.module.css} +0 -0
- /package/dist/{theme/GlossaryTerm/styles.module.css → styles.module-N7ME3MWS.module.css} +0 -0
|
@@ -1,141 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* import GlossaryTerm from '@theme/GlossaryTerm';
|
|
10
|
-
*
|
|
11
|
-
* <GlossaryTerm term="API" definition="Application Programming Interface" />
|
|
12
|
-
* or
|
|
13
|
-
* <GlossaryTerm term="API">custom display text</GlossaryTerm>
|
|
14
|
-
*
|
|
15
|
-
* @param {object} props
|
|
16
|
-
* @param {string} props.term - The glossary term
|
|
17
|
-
* @param {string} props.definition - The definition to show in tooltip
|
|
18
|
-
* @param {string} props.routePath - Route path to glossary page (default: '/glossary')
|
|
19
|
-
* @param {React.ReactNode} props.children - Optional custom display text
|
|
20
|
-
*/
|
|
21
|
-
export default function GlossaryTerm({ term, definition, routePath = '/glossary', children }) {
|
|
1
|
+
// src/theme/GlossaryTerm/index.js
|
|
2
|
+
import React, { useMemo, useState, useRef, useEffect, useCallback } from "react";
|
|
3
|
+
import { usePluginData } from "@docusaurus/useGlobalData";
|
|
4
|
+
import styles from "../../styles.module-N7ME3MWS.module.css";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function GlossaryTerm({ term, definition, routePath = "/glossary", children }) {
|
|
22
7
|
const [showTooltip, setShowTooltip] = useState(false);
|
|
23
8
|
const [tooltipStyle, setTooltipStyle] = useState(null);
|
|
24
|
-
const [placement, setPlacement] = useState(
|
|
9
|
+
const [placement, setPlacement] = useState("top");
|
|
25
10
|
const wrapperRef = useRef(null);
|
|
26
11
|
const tooltipRef = useRef(null);
|
|
27
|
-
|
|
28
12
|
const updatePosition = useCallback(() => {
|
|
29
13
|
if (!wrapperRef.current || !tooltipRef.current) return;
|
|
30
14
|
const wrapperRect = wrapperRef.current.getBoundingClientRect();
|
|
31
15
|
const tooltipRect = tooltipRef.current.getBoundingClientRect();
|
|
32
|
-
|
|
33
16
|
const viewportWidth = window.innerWidth;
|
|
34
17
|
const viewportHeight = window.innerHeight;
|
|
35
|
-
|
|
36
|
-
const preferredGap = 8; // px
|
|
37
|
-
|
|
38
|
-
// Decide top vs bottom based on available space
|
|
18
|
+
const preferredGap = 8;
|
|
39
19
|
const hasSpaceAbove = wrapperRect.top >= tooltipRect.height + preferredGap;
|
|
40
20
|
const hasSpaceBelow = viewportHeight - wrapperRect.bottom >= tooltipRect.height + preferredGap;
|
|
41
|
-
const nextPlacement = hasSpaceAbove || !hasSpaceBelow ?
|
|
42
|
-
|
|
21
|
+
const nextPlacement = hasSpaceAbove || !hasSpaceBelow ? "top" : "bottom";
|
|
43
22
|
let top;
|
|
44
|
-
if (nextPlacement ===
|
|
23
|
+
if (nextPlacement === "top") {
|
|
45
24
|
top = wrapperRect.top - tooltipRect.height - preferredGap;
|
|
46
25
|
} else {
|
|
47
26
|
top = wrapperRect.bottom + preferredGap;
|
|
48
27
|
}
|
|
49
|
-
|
|
50
|
-
// Center horizontally on the wrapper, then clamp within viewport with margin
|
|
51
28
|
const horizontalMargin = 8;
|
|
52
29
|
let left = wrapperRect.left + wrapperRect.width / 2 - tooltipRect.width / 2;
|
|
53
30
|
left = Math.max(
|
|
54
31
|
horizontalMargin,
|
|
55
32
|
Math.min(left, viewportWidth - tooltipRect.width - horizontalMargin)
|
|
56
33
|
);
|
|
57
|
-
|
|
58
34
|
setPlacement(nextPlacement);
|
|
59
35
|
setTooltipStyle({ top: Math.max(4, top), left });
|
|
60
36
|
}, []);
|
|
61
|
-
|
|
62
37
|
useEffect(() => {
|
|
63
38
|
if (!showTooltip) return;
|
|
64
|
-
|
|
65
|
-
// Use double requestAnimationFrame to ensure DOM is fully rendered and layout is complete
|
|
66
|
-
// This ensures tooltipRef.current is available and has proper dimensions
|
|
67
39
|
let rafId2;
|
|
68
40
|
const rafId1 = requestAnimationFrame(() => {
|
|
69
41
|
rafId2 = requestAnimationFrame(() => {
|
|
70
42
|
updatePosition();
|
|
71
43
|
});
|
|
72
44
|
});
|
|
73
|
-
|
|
74
45
|
const onScroll = () => updatePosition();
|
|
75
46
|
const onResize = () => updatePosition();
|
|
76
|
-
window.addEventListener(
|
|
77
|
-
window.addEventListener(
|
|
47
|
+
window.addEventListener("scroll", onScroll, true);
|
|
48
|
+
window.addEventListener("resize", onResize);
|
|
78
49
|
return () => {
|
|
79
50
|
cancelAnimationFrame(rafId1);
|
|
80
51
|
if (rafId2) cancelAnimationFrame(rafId2);
|
|
81
|
-
window.removeEventListener(
|
|
82
|
-
window.removeEventListener(
|
|
52
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
53
|
+
window.removeEventListener("resize", onResize);
|
|
83
54
|
};
|
|
84
55
|
}, [showTooltip, updatePosition]);
|
|
85
|
-
|
|
86
|
-
// Pull definition/route from plugin global data if not provided
|
|
87
|
-
const pluginData = usePluginData('docusaurus-plugin-glossary');
|
|
56
|
+
const pluginData = usePluginData("docusaurus-plugin-glossary");
|
|
88
57
|
const effectiveDefinition = useMemo(() => {
|
|
89
|
-
if (definition && typeof definition ===
|
|
58
|
+
if (definition && typeof definition === "string" && definition.length > 0) {
|
|
90
59
|
return definition;
|
|
91
60
|
}
|
|
92
|
-
const terms =
|
|
61
|
+
const terms = pluginData && pluginData.terms || [];
|
|
93
62
|
const found = terms.find(
|
|
94
|
-
t => typeof t.term ===
|
|
63
|
+
(t) => typeof t.term === "string" && t.term.toLowerCase() === String(term).toLowerCase()
|
|
95
64
|
);
|
|
96
|
-
return found && found.definition ? found.definition :
|
|
65
|
+
return found && found.definition ? found.definition : void 0;
|
|
97
66
|
}, [definition, pluginData, term]);
|
|
98
|
-
|
|
99
67
|
const effectiveRoutePath = useMemo(() => {
|
|
100
|
-
if (routePath && typeof routePath ===
|
|
101
|
-
return
|
|
68
|
+
if (routePath && typeof routePath === "string" && routePath.length > 0) return routePath;
|
|
69
|
+
return pluginData && pluginData.routePath || "/glossary";
|
|
102
70
|
}, [pluginData, routePath]);
|
|
103
|
-
|
|
104
71
|
const displayText = children || term;
|
|
105
|
-
const termId = term.toLowerCase().replace(/\s+/g,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
href
|
|
111
|
-
className
|
|
112
|
-
onMouseEnter
|
|
113
|
-
onMouseLeave
|
|
114
|
-
onFocus
|
|
115
|
-
onBlur
|
|
116
|
-
aria-describedby
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
<strong>{term}</strong> {effectiveDefinition}
|
|
137
|
-
</span>
|
|
138
|
-
)}
|
|
139
|
-
</span>
|
|
140
|
-
);
|
|
72
|
+
const termId = term.toLowerCase().replace(/\s+/g, "-");
|
|
73
|
+
return /* @__PURE__ */ jsxs("span", { ref: wrapperRef, className: styles.glossaryTermWrapper, children: [
|
|
74
|
+
/* @__PURE__ */ jsx(
|
|
75
|
+
"a",
|
|
76
|
+
{
|
|
77
|
+
href: `${effectiveRoutePath}#${termId}`,
|
|
78
|
+
className: styles.glossaryTerm,
|
|
79
|
+
onMouseEnter: () => setShowTooltip(true),
|
|
80
|
+
onMouseLeave: () => setShowTooltip(false),
|
|
81
|
+
onFocus: () => setShowTooltip(true),
|
|
82
|
+
onBlur: () => setShowTooltip(false),
|
|
83
|
+
"aria-describedby": `tooltip-${termId}`,
|
|
84
|
+
children: displayText
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
effectiveDefinition && /* @__PURE__ */ jsxs(
|
|
88
|
+
"span",
|
|
89
|
+
{
|
|
90
|
+
ref: tooltipRef,
|
|
91
|
+
id: `tooltip-${termId}`,
|
|
92
|
+
className: `${styles.tooltip} ${showTooltip ? styles.tooltipVisible : ""} ${placement === "top" ? styles.tooltipTop : styles.tooltipBottom} ${styles.tooltipFloating}`,
|
|
93
|
+
role: "tooltip",
|
|
94
|
+
style: showTooltip && tooltipStyle ? { top: `${tooltipStyle.top}px`, left: `${tooltipStyle.left}px` } : void 0,
|
|
95
|
+
children: [
|
|
96
|
+
/* @__PURE__ */ jsx("strong", { children: term }),
|
|
97
|
+
" ",
|
|
98
|
+
effectiveDefinition
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
] });
|
|
141
103
|
}
|
|
104
|
+
export {
|
|
105
|
+
GlossaryTerm as default
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/theme/GlossaryTerm/index.js"],"sourcesContent":["import React, { useMemo, useState, useRef, useEffect, useCallback } from 'react';\nimport { usePluginData } from '@docusaurus/useGlobalData';\nimport styles from './styles.module.css';\n\n/**\n * GlossaryTerm component - displays an inline term with tooltip\n *\n * Usage:\n * import GlossaryTerm from '@theme/GlossaryTerm';\n *\n * <GlossaryTerm term=\"API\" definition=\"Application Programming Interface\" />\n * or\n * <GlossaryTerm term=\"API\">custom display text</GlossaryTerm>\n *\n * @param {object} props\n * @param {string} props.term - The glossary term\n * @param {string} props.definition - The definition to show in tooltip\n * @param {string} props.routePath - Route path to glossary page (default: '/glossary')\n * @param {React.ReactNode} props.children - Optional custom display text\n */\nexport default function GlossaryTerm({ term, definition, routePath = '/glossary', children }) {\n const [showTooltip, setShowTooltip] = useState(false);\n const [tooltipStyle, setTooltipStyle] = useState(null);\n const [placement, setPlacement] = useState('top'); // 'top' | 'bottom'\n const wrapperRef = useRef(null);\n const tooltipRef = useRef(null);\n\n const updatePosition = useCallback(() => {\n if (!wrapperRef.current || !tooltipRef.current) return;\n const wrapperRect = wrapperRef.current.getBoundingClientRect();\n const tooltipRect = tooltipRef.current.getBoundingClientRect();\n\n const viewportWidth = window.innerWidth;\n const viewportHeight = window.innerHeight;\n\n const preferredGap = 8; // px\n\n // Decide top vs bottom based on available space\n const hasSpaceAbove = wrapperRect.top >= tooltipRect.height + preferredGap;\n const hasSpaceBelow = viewportHeight - wrapperRect.bottom >= tooltipRect.height + preferredGap;\n const nextPlacement = hasSpaceAbove || !hasSpaceBelow ? 'top' : 'bottom';\n\n let top;\n if (nextPlacement === 'top') {\n top = wrapperRect.top - tooltipRect.height - preferredGap;\n } else {\n top = wrapperRect.bottom + preferredGap;\n }\n\n // Center horizontally on the wrapper, then clamp within viewport with margin\n const horizontalMargin = 8;\n let left = wrapperRect.left + wrapperRect.width / 2 - tooltipRect.width / 2;\n left = Math.max(\n horizontalMargin,\n Math.min(left, viewportWidth - tooltipRect.width - horizontalMargin)\n );\n\n setPlacement(nextPlacement);\n setTooltipStyle({ top: Math.max(4, top), left });\n }, []);\n\n useEffect(() => {\n if (!showTooltip) return;\n\n // Use double requestAnimationFrame to ensure DOM is fully rendered and layout is complete\n // This ensures tooltipRef.current is available and has proper dimensions\n let rafId2;\n const rafId1 = requestAnimationFrame(() => {\n rafId2 = requestAnimationFrame(() => {\n updatePosition();\n });\n });\n\n const onScroll = () => updatePosition();\n const onResize = () => updatePosition();\n window.addEventListener('scroll', onScroll, true);\n window.addEventListener('resize', onResize);\n return () => {\n cancelAnimationFrame(rafId1);\n if (rafId2) cancelAnimationFrame(rafId2);\n window.removeEventListener('scroll', onScroll, true);\n window.removeEventListener('resize', onResize);\n };\n }, [showTooltip, updatePosition]);\n\n // Pull definition/route from plugin global data if not provided\n const pluginData = usePluginData('docusaurus-plugin-glossary');\n const effectiveDefinition = useMemo(() => {\n if (definition && typeof definition === 'string' && definition.length > 0) {\n return definition;\n }\n const terms = (pluginData && pluginData.terms) || [];\n const found = terms.find(\n t => typeof t.term === 'string' && t.term.toLowerCase() === String(term).toLowerCase()\n );\n return found && found.definition ? found.definition : undefined;\n }, [definition, pluginData, term]);\n\n const effectiveRoutePath = useMemo(() => {\n if (routePath && typeof routePath === 'string' && routePath.length > 0) return routePath;\n return (pluginData && pluginData.routePath) || '/glossary';\n }, [pluginData, routePath]);\n\n const displayText = children || term;\n const termId = term.toLowerCase().replace(/\\s+/g, '-');\n\n return (\n <span ref={wrapperRef} className={styles.glossaryTermWrapper}>\n <a\n href={`${effectiveRoutePath}#${termId}`}\n className={styles.glossaryTerm}\n onMouseEnter={() => setShowTooltip(true)}\n onMouseLeave={() => setShowTooltip(false)}\n onFocus={() => setShowTooltip(true)}\n onBlur={() => setShowTooltip(false)}\n aria-describedby={`tooltip-${termId}`}\n >\n {displayText}\n </a>\n {effectiveDefinition && (\n <span\n ref={tooltipRef}\n id={`tooltip-${termId}`}\n className={\n `${styles.tooltip} ${showTooltip ? styles.tooltipVisible : ''} ` +\n `${placement === 'top' ? styles.tooltipTop : styles.tooltipBottom} ` +\n `${styles.tooltipFloating}`\n }\n role=\"tooltip\"\n style={\n showTooltip && tooltipStyle\n ? { top: `${tooltipStyle.top}px`, left: `${tooltipStyle.left}px` }\n : undefined\n }\n >\n <strong>{term}</strong> {effectiveDefinition}\n </span>\n )}\n </span>\n );\n}\n"],"mappings":";AAAA,OAAO,SAAS,SAAS,UAAU,QAAQ,WAAW,mBAAmB;AACzE,SAAS,qBAAqB;AAC9B,OAAO,YAAY;AA0Gb,cAYE,YAZF;AAxFS,SAAR,aAA8B,EAAE,MAAM,YAAY,YAAY,aAAa,SAAS,GAAG;AAC5F,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AACpD,QAAM,CAAC,cAAc,eAAe,I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C;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,IAAI,WAAW,MAAM;AAAA,QACrB,WACE,GAAG,OAAO,OAAO,IAAI,cAAc,OAAO,iBAAiB,EAAE,IAC1D,cAAc,QAAQ,OAAO,aAAa,OAAO,aAAa,IAC9D,OAAO,eAAe;AAAA,QAE3B,MAAK;AAAA,QACL,OACE,eAAe,eACX,EAAE,KAAK,GAAG,aAAa,GAAG,MAAM,MAAM,GAAG,aAAa,IAAI,KAAK,IAC/D;AAAA,QAGN;AAAA,8BAAC,YAAQ,gBAAK;AAAA,UAAS;AAAA,UAAE;AAAA;AAAA;AAAA,IAC3B;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/validation.ts
|
|
21
|
+
var validation_exports = {};
|
|
22
|
+
__export(validation_exports, {
|
|
23
|
+
GlossaryValidationError: () => GlossaryValidationError,
|
|
24
|
+
formatValidationErrors: () => formatValidationErrors,
|
|
25
|
+
validateGlossaryData: () => validateGlossaryData
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(validation_exports);
|
|
28
|
+
function validateTerm(term, index) {
|
|
29
|
+
const errors = [];
|
|
30
|
+
const prefix = `terms[${index}]`;
|
|
31
|
+
if (term === null || term === void 0) {
|
|
32
|
+
errors.push({
|
|
33
|
+
field: prefix,
|
|
34
|
+
message: "Term cannot be null or undefined",
|
|
35
|
+
value: term
|
|
36
|
+
});
|
|
37
|
+
return errors;
|
|
38
|
+
}
|
|
39
|
+
if (typeof term !== "object") {
|
|
40
|
+
errors.push({
|
|
41
|
+
field: prefix,
|
|
42
|
+
message: `Term must be an object, got ${typeof term}`,
|
|
43
|
+
value: term
|
|
44
|
+
});
|
|
45
|
+
return errors;
|
|
46
|
+
}
|
|
47
|
+
const termObj = term;
|
|
48
|
+
if (!("term" in termObj)) {
|
|
49
|
+
errors.push({
|
|
50
|
+
field: `${prefix}.term`,
|
|
51
|
+
message: 'Missing required field "term"'
|
|
52
|
+
});
|
|
53
|
+
} else if (typeof termObj.term !== "string") {
|
|
54
|
+
errors.push({
|
|
55
|
+
field: `${prefix}.term`,
|
|
56
|
+
message: `Field "term" must be a string, got ${typeof termObj.term}`,
|
|
57
|
+
value: termObj.term
|
|
58
|
+
});
|
|
59
|
+
} else if (termObj.term.trim() === "") {
|
|
60
|
+
errors.push({
|
|
61
|
+
field: `${prefix}.term`,
|
|
62
|
+
message: 'Field "term" cannot be empty',
|
|
63
|
+
value: termObj.term
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!("definition" in termObj)) {
|
|
67
|
+
errors.push({
|
|
68
|
+
field: `${prefix}.definition`,
|
|
69
|
+
message: 'Missing required field "definition"'
|
|
70
|
+
});
|
|
71
|
+
} else if (typeof termObj.definition !== "string") {
|
|
72
|
+
errors.push({
|
|
73
|
+
field: `${prefix}.definition`,
|
|
74
|
+
message: `Field "definition" must be a string, got ${typeof termObj.definition}`,
|
|
75
|
+
value: termObj.definition
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if ("abbreviation" in termObj && termObj.abbreviation !== void 0) {
|
|
79
|
+
if (typeof termObj.abbreviation !== "string") {
|
|
80
|
+
errors.push({
|
|
81
|
+
field: `${prefix}.abbreviation`,
|
|
82
|
+
message: `Field "abbreviation" must be a string, got ${typeof termObj.abbreviation}`,
|
|
83
|
+
value: termObj.abbreviation
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if ("relatedTerms" in termObj && termObj.relatedTerms !== void 0) {
|
|
88
|
+
if (!Array.isArray(termObj.relatedTerms)) {
|
|
89
|
+
errors.push({
|
|
90
|
+
field: `${prefix}.relatedTerms`,
|
|
91
|
+
message: `Field "relatedTerms" must be an array, got ${typeof termObj.relatedTerms}`,
|
|
92
|
+
value: termObj.relatedTerms
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
termObj.relatedTerms.forEach((relatedTerm, relatedIndex) => {
|
|
96
|
+
if (typeof relatedTerm !== "string") {
|
|
97
|
+
errors.push({
|
|
98
|
+
field: `${prefix}.relatedTerms[${relatedIndex}]`,
|
|
99
|
+
message: `Related term must be a string, got ${typeof relatedTerm}`,
|
|
100
|
+
value: relatedTerm
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if ("id" in termObj && termObj.id !== void 0) {
|
|
107
|
+
if (typeof termObj.id !== "string") {
|
|
108
|
+
errors.push({
|
|
109
|
+
field: `${prefix}.id`,
|
|
110
|
+
message: `Field "id" must be a string, got ${typeof termObj.id}`,
|
|
111
|
+
value: termObj.id
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if ("autoLink" in termObj && termObj.autoLink !== void 0) {
|
|
116
|
+
if (typeof termObj.autoLink !== "boolean") {
|
|
117
|
+
errors.push({
|
|
118
|
+
field: `${prefix}.autoLink`,
|
|
119
|
+
message: `Field "autoLink" must be a boolean, got ${typeof termObj.autoLink}`,
|
|
120
|
+
value: termObj.autoLink
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return errors;
|
|
125
|
+
}
|
|
126
|
+
function validateGlossaryData(data, options = {}) {
|
|
127
|
+
const { throwOnError = true } = options;
|
|
128
|
+
const errors = [];
|
|
129
|
+
if (data === null || data === void 0) {
|
|
130
|
+
errors.push({
|
|
131
|
+
field: "root",
|
|
132
|
+
message: "Glossary data cannot be null or undefined",
|
|
133
|
+
value: data
|
|
134
|
+
});
|
|
135
|
+
if (throwOnError && errors.length > 0) {
|
|
136
|
+
throw new GlossaryValidationError(errors);
|
|
137
|
+
}
|
|
138
|
+
return { valid: false, errors, data: { terms: [] } };
|
|
139
|
+
}
|
|
140
|
+
if (typeof data !== "object") {
|
|
141
|
+
errors.push({
|
|
142
|
+
field: "root",
|
|
143
|
+
message: `Glossary data must be an object, got ${typeof data}`,
|
|
144
|
+
value: data
|
|
145
|
+
});
|
|
146
|
+
if (throwOnError && errors.length > 0) {
|
|
147
|
+
throw new GlossaryValidationError(errors);
|
|
148
|
+
}
|
|
149
|
+
return { valid: false, errors, data: { terms: [] } };
|
|
150
|
+
}
|
|
151
|
+
const glossaryData = data;
|
|
152
|
+
if (!("terms" in glossaryData)) {
|
|
153
|
+
errors.push({
|
|
154
|
+
field: "terms",
|
|
155
|
+
message: 'Glossary data must contain a "terms" array'
|
|
156
|
+
});
|
|
157
|
+
if (throwOnError && errors.length > 0) {
|
|
158
|
+
throw new GlossaryValidationError(errors);
|
|
159
|
+
}
|
|
160
|
+
return { valid: false, errors, data: { terms: [] } };
|
|
161
|
+
}
|
|
162
|
+
if (!Array.isArray(glossaryData.terms)) {
|
|
163
|
+
errors.push({
|
|
164
|
+
field: "terms",
|
|
165
|
+
message: `Field "terms" must be an array, got ${typeof glossaryData.terms}`,
|
|
166
|
+
value: glossaryData.terms
|
|
167
|
+
});
|
|
168
|
+
if (throwOnError && errors.length > 0) {
|
|
169
|
+
throw new GlossaryValidationError(errors);
|
|
170
|
+
}
|
|
171
|
+
return { valid: false, errors, data: { terms: [] } };
|
|
172
|
+
}
|
|
173
|
+
const validTerms = [];
|
|
174
|
+
glossaryData.terms.forEach((term, index) => {
|
|
175
|
+
const termErrors = validateTerm(term, index);
|
|
176
|
+
if (termErrors.length > 0) {
|
|
177
|
+
errors.push(...termErrors);
|
|
178
|
+
} else {
|
|
179
|
+
validTerms.push(term);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const termNames = /* @__PURE__ */ new Map();
|
|
183
|
+
validTerms.forEach((term, index) => {
|
|
184
|
+
const lowerName = term.term.toLowerCase();
|
|
185
|
+
if (termNames.has(lowerName)) {
|
|
186
|
+
errors.push({
|
|
187
|
+
field: `terms[${index}].term`,
|
|
188
|
+
message: `Duplicate term "${term.term}" (first occurrence at index ${termNames.get(lowerName)})`,
|
|
189
|
+
value: term.term
|
|
190
|
+
});
|
|
191
|
+
} else {
|
|
192
|
+
termNames.set(lowerName, index);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
if (throwOnError && errors.length > 0) {
|
|
196
|
+
throw new GlossaryValidationError(errors);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
valid: errors.length === 0,
|
|
200
|
+
errors,
|
|
201
|
+
data: { terms: validTerms }
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
var GlossaryValidationError = class _GlossaryValidationError extends Error {
|
|
205
|
+
constructor(errors) {
|
|
206
|
+
const message = formatValidationErrors(errors);
|
|
207
|
+
super(message);
|
|
208
|
+
this.name = "GlossaryValidationError";
|
|
209
|
+
this.errors = errors;
|
|
210
|
+
if (Error.captureStackTrace) {
|
|
211
|
+
Error.captureStackTrace(this, _GlossaryValidationError);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
function formatValidationErrors(errors) {
|
|
216
|
+
if (errors.length === 0) {
|
|
217
|
+
return "No validation errors";
|
|
218
|
+
}
|
|
219
|
+
const header = `Glossary validation failed with ${errors.length} error${errors.length > 1 ? "s" : ""}:`;
|
|
220
|
+
const errorList = errors.map((err, index) => {
|
|
221
|
+
let msg = ` ${index + 1}. [${err.field}] ${err.message}`;
|
|
222
|
+
if (err.value !== void 0) {
|
|
223
|
+
const valueStr = typeof err.value === "object" ? JSON.stringify(err.value) : String(err.value);
|
|
224
|
+
const truncated = valueStr.length > 50 ? valueStr.substring(0, 50) + "..." : valueStr;
|
|
225
|
+
msg += ` (got: ${truncated})`;
|
|
226
|
+
}
|
|
227
|
+
return msg;
|
|
228
|
+
}).join("\n");
|
|
229
|
+
return `${header}
|
|
230
|
+
${errorList}`;
|
|
231
|
+
}
|
|
232
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
+
0 && (module.exports = {
|
|
234
|
+
GlossaryValidationError,
|
|
235
|
+
formatValidationErrors,
|
|
236
|
+
validateGlossaryData
|
|
237
|
+
});
|
|
238
|
+
//# sourceMappingURL=validation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/validation.ts"],"sourcesContent":["import type { GlossaryData, GlossaryTerm } from './index.js';\n\nexport interface ValidationError {\n field: string;\n message: string;\n value?: unknown;\n}\n\nexport interface ValidationResult {\n valid: boolean;\n errors: ValidationError[];\n data: GlossaryData;\n}\n\n/**\n * Validates a single glossary term object\n *\n * @param term - The term object to validate\n * @param index - The index in the terms array (for error messages)\n * @returns Array of validation errors (empty if valid)\n */\nfunction validateTerm(term: unknown, index: number): ValidationError[] {\n const errors: ValidationError[] = [];\n const prefix = `terms[${index}]`;\n\n if (term === null || term === undefined) {\n errors.push({\n field: prefix,\n message: 'Term cannot be null or undefined',\n value: term,\n });\n return errors;\n }\n\n if (typeof term !== 'object') {\n errors.push({\n field: prefix,\n message: `Term must be an object, got ${typeof term}`,\n value: term,\n });\n return errors;\n }\n\n const termObj = term as Record<string, unknown>;\n\n // Required: term (string)\n if (!('term' in termObj)) {\n errors.push({\n field: `${prefix}.term`,\n message: 'Missing required field \"term\"',\n });\n } else if (typeof termObj.term !== 'string') {\n errors.push({\n field: `${prefix}.term`,\n message: `Field \"term\" must be a string, got ${typeof termObj.term}`,\n value: termObj.term,\n });\n } else if (termObj.term.trim() === '') {\n errors.push({\n field: `${prefix}.term`,\n message: 'Field \"term\" cannot be empty',\n value: termObj.term,\n });\n }\n\n // Required: definition (string)\n if (!('definition' in termObj)) {\n errors.push({\n field: `${prefix}.definition`,\n message: 'Missing required field \"definition\"',\n });\n } else if (typeof termObj.definition !== 'string') {\n errors.push({\n field: `${prefix}.definition`,\n message: `Field \"definition\" must be a string, got ${typeof termObj.definition}`,\n value: termObj.definition,\n });\n }\n\n // Optional: abbreviation (string)\n if ('abbreviation' in termObj && termObj.abbreviation !== undefined) {\n if (typeof termObj.abbreviation !== 'string') {\n errors.push({\n field: `${prefix}.abbreviation`,\n message: `Field \"abbreviation\" must be a string, got ${typeof termObj.abbreviation}`,\n value: termObj.abbreviation,\n });\n }\n }\n\n // Optional: relatedTerms (string[])\n if ('relatedTerms' in termObj && termObj.relatedTerms !== undefined) {\n if (!Array.isArray(termObj.relatedTerms)) {\n errors.push({\n field: `${prefix}.relatedTerms`,\n message: `Field \"relatedTerms\" must be an array, got ${typeof termObj.relatedTerms}`,\n value: termObj.relatedTerms,\n });\n } else {\n termObj.relatedTerms.forEach((relatedTerm, relatedIndex) => {\n if (typeof relatedTerm !== 'string') {\n errors.push({\n field: `${prefix}.relatedTerms[${relatedIndex}]`,\n message: `Related term must be a string, got ${typeof relatedTerm}`,\n value: relatedTerm,\n });\n }\n });\n }\n }\n\n // Optional: id (string)\n if ('id' in termObj && termObj.id !== undefined) {\n if (typeof termObj.id !== 'string') {\n errors.push({\n field: `${prefix}.id`,\n message: `Field \"id\" must be a string, got ${typeof termObj.id}`,\n value: termObj.id,\n });\n }\n }\n\n // Optional: autoLink (boolean)\n if ('autoLink' in termObj && termObj.autoLink !== undefined) {\n if (typeof termObj.autoLink !== 'boolean') {\n errors.push({\n field: `${prefix}.autoLink`,\n message: `Field \"autoLink\" must be a boolean, got ${typeof termObj.autoLink}`,\n value: termObj.autoLink,\n });\n }\n }\n\n return errors;\n}\n\n/**\n * Validates glossary data structure\n *\n * Ensures the glossary data conforms to the expected schema:\n * - Must be an object with a \"terms\" array\n * - Each term must have \"term\" (string) and \"definition\" (string)\n * - Optional fields: abbreviation (string), relatedTerms (string[]), id (string)\n *\n * @param data - The data to validate\n * @param options - Validation options\n * @param options.throwOnError - If true, throws an error on validation failure (default: true)\n * @returns Validation result with errors and sanitized data\n * @throws Error if data is invalid and throwOnError is true\n */\nexport function validateGlossaryData(\n data: unknown,\n options: { throwOnError?: boolean } = {}\n): ValidationResult {\n const { throwOnError = true } = options;\n const errors: ValidationError[] = [];\n\n // Check if data is null or undefined\n if (data === null || data === undefined) {\n errors.push({\n field: 'root',\n message: 'Glossary data cannot be null or undefined',\n value: data,\n });\n\n if (throwOnError && errors.length > 0) {\n throw new GlossaryValidationError(errors);\n }\n\n return { valid: false, errors, data: { terms: [] } };\n }\n\n // Check if data is an object\n if (typeof data !== 'object') {\n errors.push({\n field: 'root',\n message: `Glossary data must be an object, got ${typeof data}`,\n value: data,\n });\n\n if (throwOnError && errors.length > 0) {\n throw new GlossaryValidationError(errors);\n }\n\n return { valid: false, errors, data: { terms: [] } };\n }\n\n const glossaryData = data as Record<string, unknown>;\n\n // Check for terms array\n if (!('terms' in glossaryData)) {\n errors.push({\n field: 'terms',\n message: 'Glossary data must contain a \"terms\" array',\n });\n\n if (throwOnError && errors.length > 0) {\n throw new GlossaryValidationError(errors);\n }\n\n return { valid: false, errors, data: { terms: [] } };\n }\n\n if (!Array.isArray(glossaryData.terms)) {\n errors.push({\n field: 'terms',\n message: `Field \"terms\" must be an array, got ${typeof glossaryData.terms}`,\n value: glossaryData.terms,\n });\n\n if (throwOnError && errors.length > 0) {\n throw new GlossaryValidationError(errors);\n }\n\n return { valid: false, errors, data: { terms: [] } };\n }\n\n // Validate each term\n const validTerms: GlossaryTerm[] = [];\n glossaryData.terms.forEach((term, index) => {\n const termErrors = validateTerm(term, index);\n if (termErrors.length > 0) {\n errors.push(...termErrors);\n } else {\n // Term is valid, add to valid terms\n validTerms.push(term as GlossaryTerm);\n }\n });\n\n // Check for duplicate terms\n const termNames = new Map<string, number>();\n validTerms.forEach((term, index) => {\n const lowerName = term.term.toLowerCase();\n if (termNames.has(lowerName)) {\n errors.push({\n field: `terms[${index}].term`,\n message: `Duplicate term \"${term.term}\" (first occurrence at index ${termNames.get(lowerName)})`,\n value: term.term,\n });\n } else {\n termNames.set(lowerName, index);\n }\n });\n\n if (throwOnError && errors.length > 0) {\n throw new GlossaryValidationError(errors);\n }\n\n return {\n valid: errors.length === 0,\n errors,\n data: { terms: validTerms },\n };\n}\n\n/**\n * Custom error class for glossary validation errors\n * Provides detailed error messages for debugging\n */\nexport class GlossaryValidationError extends Error {\n public readonly errors: ValidationError[];\n\n constructor(errors: ValidationError[]) {\n const message = formatValidationErrors(errors);\n super(message);\n this.name = 'GlossaryValidationError';\n this.errors = errors;\n\n // Maintains proper stack trace for where error was thrown (V8 engines)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, GlossaryValidationError);\n }\n }\n}\n\n/**\n * Formats validation errors into a readable string\n *\n * @param errors - Array of validation errors\n * @returns Formatted error message\n */\nexport function formatValidationErrors(errors: ValidationError[]): string {\n if (errors.length === 0) {\n return 'No validation errors';\n }\n\n const header = `Glossary validation failed with ${errors.length} error${errors.length > 1 ? 's' : ''}:`;\n const errorList = errors\n .map((err, index) => {\n let msg = ` ${index + 1}. [${err.field}] ${err.message}`;\n if (err.value !== undefined) {\n const valueStr =\n typeof err.value === 'object' ? JSON.stringify(err.value) : String(err.value);\n // Truncate long values\n const truncated = valueStr.length > 50 ? valueStr.substring(0, 50) + '...' : valueStr;\n msg += ` (got: ${truncated})`;\n }\n return msg;\n })\n .join('\\n');\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AQO,SAAS,uBAAuB,QAAmC;AACxE,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,mCAAmC,OAAO,MAAM,SAAS,OAAO,SAAS,IAAI,MAAM,EAAE;AACpG,QAAM,YAAY,OACf,IAAI,CAAC,KAAK,UAAU;AACnB,QAAI,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,KAAK,KAAK,IAAI,OAAO;AACvD,QAAI,IAAI,UAAU,QAAW;AAC3B,YAAM,WACJ,OAAO,IAAI,UAAU,WAAW,KAAK,UAAU,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK;AAE9E,YAAM,YAAY,SAAS,SAAS,KAAK,SAAS,UAAU,GAAG,EAAE,IAAI,QAAQ;AAC7E,aAAO,UAAU,SAAS;AAAA,IAC5B;AACA,WAAO;AAAA,EACT,CAAC,EACA,KAAK,IAAI;AAEZ,SAAO,GAAG,MAAM;AAAA,EAAK,SAAS;AAChC;","names":[]}
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
field: string;
|
|
4
|
-
message: string;
|
|
5
|
-
value?: unknown;
|
|
6
|
-
}
|
|
7
|
-
export interface ValidationResult {
|
|
8
|
-
valid: boolean;
|
|
9
|
-
errors: ValidationError[];
|
|
10
|
-
data: GlossaryData;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Validates glossary data structure
|
|
14
|
-
*
|
|
15
|
-
* Ensures the glossary data conforms to the expected schema:
|
|
16
|
-
* - Must be an object with a "terms" array
|
|
17
|
-
* - Each term must have "term" (string) and "definition" (string)
|
|
18
|
-
* - Optional fields: abbreviation (string), relatedTerms (string[]), id (string)
|
|
19
|
-
*
|
|
20
|
-
* @param data - The data to validate
|
|
21
|
-
* @param options - Validation options
|
|
22
|
-
* @param options.throwOnError - If true, throws an error on validation failure (default: true)
|
|
23
|
-
* @returns Validation result with errors and sanitized data
|
|
24
|
-
* @throws Error if data is invalid and throwOnError is true
|
|
25
|
-
*/
|
|
26
|
-
export declare function validateGlossaryData(data: unknown, options?: {
|
|
27
|
-
throwOnError?: boolean;
|
|
28
|
-
}): ValidationResult;
|
|
29
|
-
/**
|
|
30
|
-
* Custom error class for glossary validation errors
|
|
31
|
-
* Provides detailed error messages for debugging
|
|
32
|
-
*/
|
|
33
|
-
export declare class GlossaryValidationError extends Error {
|
|
34
|
-
readonly errors: ValidationError[];
|
|
35
|
-
constructor(errors: ValidationError[]);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Formats validation errors into a readable string
|
|
39
|
-
*
|
|
40
|
-
* @param errors - Array of validation errors
|
|
41
|
-
* @returns Formatted error message
|
|
42
|
-
*/
|
|
43
|
-
export declare function formatValidationErrors(errors: ValidationError[]): string;
|
|
44
|
-
//# sourceMappingURL=validation.d.ts.map
|
|
1
|
+
export { GlossaryValidationError, ValidationError, ValidationResult, formatValidationErrors, validateGlossaryData } from './index.js';
|
|
2
|
+
import '@docusaurus/types';
|