@elliemae/ds-decision-graph 3.22.0-next.26
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/cjs/DSDecisionGraph.js +73 -0
- package/dist/cjs/DSDecisionGraph.js.map +7 -0
- package/dist/cjs/config/useDecisionGraph.js +62 -0
- package/dist/cjs/config/useDecisionGraph.js.map +7 -0
- package/dist/cjs/config/useValidateProps.js +50 -0
- package/dist/cjs/config/useValidateProps.js.map +7 -0
- package/dist/cjs/constants/index.js +88 -0
- package/dist/cjs/constants/index.js.map +7 -0
- package/dist/cjs/index.js +41 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/parts/mermaid/MermaidDecisionChart.js +61 -0
- package/dist/cjs/parts/mermaid/MermaidDecisionChart.js.map +7 -0
- package/dist/cjs/parts/mermaid/decisionTreeToMermaidMD.js +106 -0
- package/dist/cjs/parts/mermaid/decisionTreeToMermaidMD.js.map +7 -0
- package/dist/cjs/react-desc-prop-types.js +54 -0
- package/dist/cjs/react-desc-prop-types.js.map +7 -0
- package/dist/esm/DSDecisionGraph.js +43 -0
- package/dist/esm/DSDecisionGraph.js.map +7 -0
- package/dist/esm/config/useDecisionGraph.js +32 -0
- package/dist/esm/config/useDecisionGraph.js.map +7 -0
- package/dist/esm/config/useValidateProps.js +20 -0
- package/dist/esm/config/useValidateProps.js.map +7 -0
- package/dist/esm/constants/index.js +58 -0
- package/dist/esm/constants/index.js.map +7 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +7 -0
- package/dist/esm/parts/mermaid/MermaidDecisionChart.js +31 -0
- package/dist/esm/parts/mermaid/MermaidDecisionChart.js.map +7 -0
- package/dist/esm/parts/mermaid/decisionTreeToMermaidMD.js +76 -0
- package/dist/esm/parts/mermaid/decisionTreeToMermaidMD.js.map +7 -0
- package/dist/esm/react-desc-prop-types.js +24 -0
- package/dist/esm/react-desc-prop-types.js.map +7 -0
- package/dist/types/DSDecisionGraph.d.ts +5 -0
- package/dist/types/config/useDecisionGraph.d.ts +15 -0
- package/dist/types/config/useValidateProps.d.ts +3 -0
- package/dist/types/constants/index.d.ts +52 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/parts/mermaid/MermaidDecisionChart.d.ts +8 -0
- package/dist/types/parts/mermaid/decisionTreeToMermaidMD.d.ts +8 -0
- package/dist/types/react-desc-prop-types.d.ts +54 -0
- package/dist/types/tests/DSDecisionGraph.test.d.ts +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react-desc-prop-types.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type { GlobalAttributesT, XstyledProps, DSPropTypesSchema } from '@elliemae/ds-props-helpers';\nimport { PropTypes, globalAttributesPropTypes, xstyledPropTypes } from '@elliemae/ds-props-helpers';\nimport type { WeakValidationMap } from 'react';\nimport { JSON_SCHEMA } from './constants/index.js';\n\nexport declare namespace DSDecisionGraphT {\n export type Directions = 'LR' | 'TD'; // left to right | top down\n export type SemanticMeaning = 'question' | 'conclusion';\n export type NodePath = `${string}${'t' | 'f' | 'o' | 's'}`; // Node ID for a decision node, doubles as the path to the node | T true | F false | O (other) not applicable | S start\n export type ConclusionMarkdown = `${string | NodePath}(${string})`; // Mermaid Markdown for a conclusion node | A node with round edges\n export type QuestionMarkdown = `${string | NodePath}{{${string}}}`; // Mermaid Markdown for a question node | A hexagon node\n export type NodeMarkdown = ConclusionMarkdown | QuestionMarkdown;\n export type TrueLinkMarkdown = `-->|true|`; // Mermaid Markdown for a true path link\n export type FalseLinkMarkdown = `-->|false|`; // Mermaid Markdown for a false path link\n export type NALinkMarkdown = `-->|N/A|`; // Mermaid Markdown for a not applicable path link\n export type LinkMarkdown = TrueLinkMarkdown | FalseLinkMarkdown | NALinkMarkdown | '';\n\n /**\n * Node polymorphism for the \"meaning\" the node has in the decision tree.\n * this influence the node shape in the decision chart.\n */\n // common properties for all nodes\n export interface BaseNode {\n nodeText: string; // Text representing a conclusion or question\n truePath?: DecisionNode; // Decision node for the true path\n falsePath?: DecisionNode; // Decision node for the false path\n notApplicablePath?: DecisionNode; // Decision node for the not applicable path\n repeatedId?: string; // Id of the node if it is repeated in the decision tree and we want to show it only once in the decision chart\n }\n // polymorphism for node with the semantic meaning of \"question\"\n export interface QuestionNode extends BaseNode {\n semanticMeaning: 'question';\n }\n // polymorphism for node with the semantic meaning of \"conclusion\"\n export interface ConclusionNode extends BaseNode {\n semanticMeaning: 'conclusion';\n }\n // polymorphism for all nodes\n export type DecisionNode = QuestionNode | ConclusionNode;\n /**\n * yes, polymorphism in typescript is this verbose and this hard to handle correctly.\n */\n\n export type RootNode = {\n chartTitle: string; // Title of the decision chart\n subtree: DecisionNode; // The root of the decision tree\n };\n\n export interface RequiredProps {\n chartJson: RootNode;\n }\n\n export interface DefaultProps {\n direction: Directions;\n }\n\n export interface OptionalProps {}\n\n export interface Props\n extends Partial<DefaultProps>,\n OptionalProps,\n Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof RequiredProps | keyof XstyledProps>,\n XstyledProps,\n RequiredProps {}\n\n export interface InternalProps\n extends DefaultProps,\n OptionalProps,\n Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof RequiredProps | keyof XstyledProps>,\n XstyledProps,\n RequiredProps {}\n}\n\nexport const defaultProps: DSDecisionGraphT.DefaultProps = {\n direction: 'LR',\n};\n\nexport const DSDecisionGraphPropTypes: DSPropTypesSchema<DSDecisionGraphT.Props> = {\n ...globalAttributesPropTypes,\n ...xstyledPropTypes,\n chartJson: PropTypes.object.description(\n `the json representing the decision chart. must comply with the following json_schema:\\n${JSON.stringify(\n JSON_SCHEMA,\n )}`,\n ).isRequired,\n direction: PropTypes.oneOf(['LR', 'TD'])\n .description('direction of the flowchart, default is LR (left to right)')\n .defaultValue('LR'),\n};\n\nexport const DSDecisionGraphPropTypesSchema =\n DSDecisionGraphPropTypes as unknown as WeakValidationMap<DSDecisionGraphT.Props>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,8BAAuE;AAEvE,uBAA4B;AAsErB,MAAM,eAA8C;AAAA,EACzD,WAAW;AACb;AAEO,MAAM,2BAAsE;AAAA,EACjF,GAAG;AAAA,EACH,GAAG;AAAA,EACH,WAAW,kCAAU,OAAO;AAAA,IAC1B;AAAA,EAA0F,KAAK;AAAA,MAC7F;AAAA,IACF;AAAA,EACF,EAAE;AAAA,EACF,WAAW,kCAAU,MAAM,CAAC,MAAM,IAAI,CAAC,EACpC,YAAY,2DAA2D,EACvE,aAAa,IAAI;AACtB;AAEO,MAAM,iCACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import React2 from "react";
|
|
4
|
+
import { describe } from "@elliemae/ds-props-helpers";
|
|
5
|
+
import { styled } from "@elliemae/ds-system";
|
|
6
|
+
import { Grid } from "@elliemae/ds-grid";
|
|
7
|
+
import { DSDecisionGraphPropTypesSchema } from "./react-desc-prop-types.js";
|
|
8
|
+
import { useDecisionGraph } from "./config/useDecisionGraph.js";
|
|
9
|
+
import { DECISION_GRAPH_SLOTS, DSDecisionGraphName } from "./constants/index.js";
|
|
10
|
+
import { MermaidDecisionChart } from "./parts/mermaid/MermaidDecisionChart.js";
|
|
11
|
+
const StyledWrapper = styled(Grid, { name: "ds-decision-graph", slot: DECISION_GRAPH_SLOTS.WRAPPER })``;
|
|
12
|
+
const mainContentCols = ["1fr"];
|
|
13
|
+
const getOwnerPropsArgumentsNoOp = () => ({});
|
|
14
|
+
const DSDecisionGraph = (props) => {
|
|
15
|
+
const { propsWithDefault, globalProps, xstyledProps, instanceUid } = useDecisionGraph(props);
|
|
16
|
+
const getOwnerProps = React2.useCallback(() => propsWithDefault, [propsWithDefault]);
|
|
17
|
+
return /* @__PURE__ */ jsx(
|
|
18
|
+
StyledWrapper,
|
|
19
|
+
{
|
|
20
|
+
cols: mainContentCols,
|
|
21
|
+
getOwnerProps,
|
|
22
|
+
getOwnerPropsArguments: getOwnerPropsArgumentsNoOp,
|
|
23
|
+
...globalProps,
|
|
24
|
+
...xstyledProps,
|
|
25
|
+
children: /* @__PURE__ */ jsx(
|
|
26
|
+
MermaidDecisionChart,
|
|
27
|
+
{
|
|
28
|
+
uid: instanceUid,
|
|
29
|
+
chartJson: propsWithDefault.chartJson,
|
|
30
|
+
direction: propsWithDefault.direction
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
DSDecisionGraph.displayName = DSDecisionGraphName;
|
|
37
|
+
const DSDecisionGraphWithSchema = describe(DSDecisionGraph);
|
|
38
|
+
DSDecisionGraphWithSchema.propTypes = DSDecisionGraphPropTypesSchema;
|
|
39
|
+
export {
|
|
40
|
+
DSDecisionGraph,
|
|
41
|
+
DSDecisionGraphWithSchema
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=DSDecisionGraph.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSDecisionGraph.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { styled } from '@elliemae/ds-system';\nimport { Grid } from '@elliemae/ds-grid';\nimport { type DSDecisionGraphT, DSDecisionGraphPropTypesSchema } from './react-desc-prop-types.js';\nimport { useDecisionGraph } from './config/useDecisionGraph.js';\nimport { DECISION_GRAPH_SLOTS, DSDecisionGraphName } from './constants/index.js';\nimport { MermaidDecisionChart } from './parts/mermaid/MermaidDecisionChart.js';\n\nconst StyledWrapper = styled(Grid, { name: 'ds-decision-graph', slot: DECISION_GRAPH_SLOTS.WRAPPER })``;\nconst mainContentCols = ['1fr'];\n\nconst getOwnerPropsArgumentsNoOp = () => ({});\nconst DSDecisionGraph: React.ComponentType<DSDecisionGraphT.Props> = (props) => {\n const { propsWithDefault, globalProps, xstyledProps, instanceUid } = useDecisionGraph(props);\n const getOwnerProps = React.useCallback(() => propsWithDefault, [propsWithDefault]);\n return (\n <StyledWrapper\n cols={mainContentCols}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArgumentsNoOp}\n {...globalProps}\n {...xstyledProps}\n >\n <MermaidDecisionChart\n uid={instanceUid}\n chartJson={propsWithDefault.chartJson}\n direction={propsWithDefault.direction}\n />\n </StyledWrapper>\n );\n};\n\nDSDecisionGraph.displayName = DSDecisionGraphName;\nconst DSDecisionGraphWithSchema = describe(DSDecisionGraph);\nDSDecisionGraphWithSchema.propTypes = DSDecisionGraphPropTypesSchema;\n\nexport { DSDecisionGraph, DSDecisionGraphWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACwBjB;AAxBN,OAAOA,YAAW;AAClB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAgC,sCAAsC;AACtE,SAAS,wBAAwB;AACjC,SAAS,sBAAsB,2BAA2B;AAC1D,SAAS,4BAA4B;AAErC,MAAM,gBAAgB,OAAO,MAAM,EAAE,MAAM,qBAAqB,MAAM,qBAAqB,QAAQ,CAAC;AACpG,MAAM,kBAAkB,CAAC,KAAK;AAE9B,MAAM,6BAA6B,OAAO,CAAC;AAC3C,MAAM,kBAA+D,CAAC,UAAU;AAC9E,QAAM,EAAE,kBAAkB,aAAa,cAAc,YAAY,IAAI,iBAAiB,KAAK;AAC3F,QAAM,gBAAgBA,OAAM,YAAY,MAAM,kBAAkB,CAAC,gBAAgB,CAAC;AAClF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAM;AAAA,MACN;AAAA,MACA,wBAAwB;AAAA,MACvB,GAAG;AAAA,MACH,GAAG;AAAA,MAEJ;AAAA,QAAC;AAAA;AAAA,UACC,KAAK;AAAA,UACL,WAAW,iBAAiB;AAAA,UAC5B,WAAW,iBAAiB;AAAA;AAAA,MAC9B;AAAA;AAAA,EACF;AAEJ;AAEA,gBAAgB,cAAc;AAC9B,MAAM,4BAA4B,SAAS,eAAe;AAC1D,0BAA0B,YAAY;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import { omit } from "lodash";
|
|
4
|
+
import { useGetGlobalAttributes, useGetXstyledProps, useMemoMergePropsWithDefault } from "@elliemae/ds-props-helpers";
|
|
5
|
+
import { uid } from "uid";
|
|
6
|
+
import { DSDecisionGraphPropTypes, defaultProps } from "../react-desc-prop-types.js";
|
|
7
|
+
import { useValidateProps } from "./useValidateProps.js";
|
|
8
|
+
const useDecisionGraph = (propsFromUser) => {
|
|
9
|
+
const propsWithDefault = useMemoMergePropsWithDefault(propsFromUser, defaultProps);
|
|
10
|
+
useValidateProps(propsWithDefault, DSDecisionGraphPropTypes);
|
|
11
|
+
const globalProps = omit(useGetGlobalAttributes(propsWithDefault), [
|
|
12
|
+
"cols",
|
|
13
|
+
"rows",
|
|
14
|
+
"wrap"
|
|
15
|
+
]);
|
|
16
|
+
const xstyledProps = useGetXstyledProps(propsWithDefault);
|
|
17
|
+
const { id } = propsWithDefault;
|
|
18
|
+
const instanceUid = React2.useMemo(() => id || uid(5), [id]);
|
|
19
|
+
return React2.useMemo(
|
|
20
|
+
() => ({
|
|
21
|
+
propsWithDefault,
|
|
22
|
+
globalProps,
|
|
23
|
+
xstyledProps,
|
|
24
|
+
instanceUid
|
|
25
|
+
}),
|
|
26
|
+
[propsWithDefault, globalProps, xstyledProps, instanceUid]
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
useDecisionGraph
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=useDecisionGraph.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useDecisionGraph.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { omit } from 'lodash';\nimport { useGetGlobalAttributes, useGetXstyledProps, useMemoMergePropsWithDefault } from '@elliemae/ds-props-helpers';\nimport { uid } from 'uid';\nimport { type DSDecisionGraphT, DSDecisionGraphPropTypes, defaultProps } from '../react-desc-prop-types.js';\nimport { useValidateProps } from './useValidateProps.js';\n\nexport interface DecisionGraphCTX {\n propsWithDefault: DSDecisionGraphT.InternalProps;\n globalProps: ReturnType<typeof useGetGlobalAttributes>;\n xstyledProps: ReturnType<typeof useGetXstyledProps>;\n instanceUid: string;\n}\n\nexport const useDecisionGraph = (propsFromUser: DSDecisionGraphT.Props) => {\n // =============================================================================\n // MERGE WITH DEFAULT AND VALIDATE PROPS\n // =============================================================================\n const propsWithDefault = useMemoMergePropsWithDefault<DSDecisionGraphT.InternalProps>(propsFromUser, defaultProps);\n useValidateProps(propsWithDefault, DSDecisionGraphPropTypes);\n // =============================================================================\n // GLOBAL ATTRIBUTES & XSTYLED PROPS\n // =============================================================================\n const globalProps = omit(useGetGlobalAttributes<DSDecisionGraphT.InternalProps>(propsWithDefault), [\n 'cols',\n 'rows',\n 'wrap',\n ]);\n const xstyledProps = useGetXstyledProps(propsWithDefault);\n // =============================================================================\n // AD HOC PER COMPONENT LOGIC\n // =============================================================================\n // custom code goes here, this is an example\n const { id } = propsWithDefault;\n const instanceUid = React.useMemo(() => id || uid(5), [id]);\n\n // =============================================================================\n // HELPERS HOOKS CONFIGS\n // =============================================================================\n // const eventHandlers = useEventHandlers({ propsWithDefault, instanceUid }); // <-- complex logic should be made atomics this way\n\n return React.useMemo(\n () => ({\n propsWithDefault,\n globalProps,\n xstyledProps,\n instanceUid,\n }),\n [propsWithDefault, globalProps, xstyledProps, instanceUid],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,YAAW;AAClB,SAAS,YAAY;AACrB,SAAS,wBAAwB,oBAAoB,oCAAoC;AACzF,SAAS,WAAW;AACpB,SAAgC,0BAA0B,oBAAoB;AAC9E,SAAS,wBAAwB;AAS1B,MAAM,mBAAmB,CAAC,kBAA0C;AAIzE,QAAM,mBAAmB,6BAA6D,eAAe,YAAY;AACjH,mBAAiB,kBAAkB,wBAAwB;AAI3D,QAAM,cAAc,KAAK,uBAAuD,gBAAgB,GAAG;AAAA,IACjG;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACD,QAAM,eAAe,mBAAmB,gBAAgB;AAKxD,QAAM,EAAE,GAAG,IAAI;AACf,QAAM,cAAcA,OAAM,QAAQ,MAAM,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAO1D,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,CAAC,kBAAkB,aAAa,cAAc,WAAW;AAAA,EAC3D;AACF;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import { useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
|
|
4
|
+
import { DSDecisionGraphName, JSON_SCHEMA } from "../constants/index.js";
|
|
5
|
+
import Ajv from "ajv";
|
|
6
|
+
const useValidateProps = (props, propTypes) => {
|
|
7
|
+
useValidateTypescriptPropTypes(props, propTypes, DSDecisionGraphName);
|
|
8
|
+
React2.useEffect(() => {
|
|
9
|
+
const ajv = new Ajv();
|
|
10
|
+
const validate = ajv.compile(JSON_SCHEMA);
|
|
11
|
+
const valid = validate(props.chartJson);
|
|
12
|
+
if (!valid) {
|
|
13
|
+
throw new Error(`Invalid JSON: ${JSON.stringify(validate.errors)}`);
|
|
14
|
+
}
|
|
15
|
+
}, [props.chartJson]);
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
useValidateProps
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=useValidateProps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useValidateProps.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport type { WeakValidationMap } from 'react';\nimport { useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport { type DSDecisionGraphT } from '../react-desc-prop-types.js';\nimport { DSDecisionGraphName, JSON_SCHEMA } from '../constants/index.js';\nimport Ajv from 'ajv';\n\nexport const useValidateProps = (\n props: DSDecisionGraphT.InternalProps,\n propTypes: WeakValidationMap<unknown>,\n): void => {\n // we validate the \"required if\" via 'isRequiredIf from our custom PropTypes\n useValidateTypescriptPropTypes(props, propTypes, DSDecisionGraphName);\n React.useEffect(() => {\n const ajv = new Ajv();\n const validate = ajv.compile(JSON_SCHEMA);\n const valid = validate(props.chartJson);\n if (!valid) {\n throw new Error(`Invalid JSON: ${JSON.stringify(validate.errors)}`);\n }\n }, [props.chartJson]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,YAAW;AAElB,SAAS,sCAAsC;AAE/C,SAAS,qBAAqB,mBAAmB;AACjD,OAAO,SAAS;AAET,MAAM,mBAAmB,CAC9B,OACA,cACS;AAET,iCAA+B,OAAO,WAAW,mBAAmB;AACpE,EAAAA,OAAM,UAAU,MAAM;AACpB,UAAM,MAAM,IAAI,IAAI;AACpB,UAAM,WAAW,IAAI,QAAQ,WAAW;AACxC,UAAM,QAAQ,SAAS,MAAM,SAAS;AACtC,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,MAAM,iBAAiB,KAAK,UAAU,SAAS,MAAM,GAAG;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,CAAC;AACtB;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { slotObjectToDataTestIds } from "@elliemae/ds-system";
|
|
3
|
+
const DSDecisionGraphName = "DSDecisionGraph";
|
|
4
|
+
const DECISION_GRAPH_SLOTS = {
|
|
5
|
+
WRAPPER: "wrapper"
|
|
6
|
+
};
|
|
7
|
+
const DECISION_GRAPH_DATA_TESTID = slotObjectToDataTestIds(DSDecisionGraphName, DECISION_GRAPH_SLOTS);
|
|
8
|
+
const JSON_SCHEMA = {
|
|
9
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
chartTitle: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Title of the decision chart"
|
|
15
|
+
},
|
|
16
|
+
subtree: {
|
|
17
|
+
$ref: "#/definitions/DecisionNode",
|
|
18
|
+
description: "The root of the decision tree"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
required: ["chartTitle", "subtree"],
|
|
22
|
+
definitions: {
|
|
23
|
+
DecisionNode: {
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
nodeText: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Text representing a conclusion or question"
|
|
29
|
+
},
|
|
30
|
+
semanticMeaning: { type: "string", enum: ["question", "conclusion"] },
|
|
31
|
+
repeatedId: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "optional unique identifier for the node, used to allow pointing multiple paths to the same node in the chart"
|
|
34
|
+
},
|
|
35
|
+
truePath: {
|
|
36
|
+
$ref: "#/definitions/DecisionNode",
|
|
37
|
+
description: "Decision node for the true path"
|
|
38
|
+
},
|
|
39
|
+
falsePath: {
|
|
40
|
+
$ref: "#/definitions/DecisionNode",
|
|
41
|
+
description: "Decision node for the false path"
|
|
42
|
+
},
|
|
43
|
+
notApplicablePath: {
|
|
44
|
+
$ref: "#/definitions/DecisionNode",
|
|
45
|
+
description: "Decision node for the not applicable path"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
required: ["nodeText", "semanticMeaning"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
DECISION_GRAPH_DATA_TESTID,
|
|
54
|
+
DECISION_GRAPH_SLOTS,
|
|
55
|
+
DSDecisionGraphName,
|
|
56
|
+
JSON_SCHEMA
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/constants/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { slotObjectToDataTestIds } from '@elliemae/ds-system';\n// carefull to not implement dependency cycles, especially in react-desc-prop-types.ts\n// this file is meant to host \"simple\" constants\n// this file should never need to refeer the typescript namespace\n// if you need the typescript namespace in this file, you are probably not having to define a constant ?\n// if you are sure it's actually a constant declare a new file like `complex-constants.ts` or something like that to avoid cycle\n\nexport const DSDecisionGraphName = 'DSDecisionGraph';\n\n// we are giving \"component_name_slots\" to avoid errors on duplicate exports variables in aggregators\nexport const DECISION_GRAPH_SLOTS = {\n WRAPPER: 'wrapper',\n} as const;\n\n// we are giving \"component_name_data_testid\" to avoid errors on duplicate exports variables in aggregators\nexport const DECISION_GRAPH_DATA_TESTID = slotObjectToDataTestIds(DSDecisionGraphName, DECISION_GRAPH_SLOTS);\n\nexport const JSON_SCHEMA = {\n $schema: 'http://json-schema.org/draft-07/schema#',\n type: 'object',\n properties: {\n chartTitle: {\n type: 'string',\n description: 'Title of the decision chart',\n },\n subtree: {\n $ref: '#/definitions/DecisionNode',\n description: 'The root of the decision tree',\n },\n },\n required: ['chartTitle', 'subtree'],\n definitions: {\n DecisionNode: {\n type: 'object',\n properties: {\n nodeText: {\n type: 'string',\n description: 'Text representing a conclusion or question',\n },\n semanticMeaning: { type: 'string', enum: ['question', 'conclusion'] },\n repeatedId: {\n type: 'string',\n description:\n 'optional unique identifier for the node, used to allow pointing multiple paths to the same node in the chart',\n },\n truePath: {\n $ref: '#/definitions/DecisionNode',\n description: 'Decision node for the true path',\n },\n falsePath: {\n $ref: '#/definitions/DecisionNode',\n description: 'Decision node for the false path',\n },\n notApplicablePath: {\n $ref: '#/definitions/DecisionNode',\n description: 'Decision node for the not applicable path',\n },\n },\n required: ['nodeText', 'semanticMeaning'],\n },\n },\n} as const;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,+BAA+B;AAOjC,MAAM,sBAAsB;AAG5B,MAAM,uBAAuB;AAAA,EAClC,SAAS;AACX;AAGO,MAAM,6BAA6B,wBAAwB,qBAAqB,oBAAoB;AAEpG,MAAM,cAAc;AAAA,EACzB,SAAS;AAAA,EACT,MAAM;AAAA,EACN,YAAY;AAAA,IACV,YAAY;AAAA,MACV,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,UAAU,CAAC,cAAc,SAAS;AAAA,EAClC,aAAa;AAAA,IACX,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,UAAU;AAAA,UACR,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,iBAAiB,EAAE,MAAM,UAAU,MAAM,CAAC,YAAY,YAAY,EAAE;AAAA,QACpE,YAAY;AAAA,UACV,MAAM;AAAA,UACN,aACE;AAAA,QACJ;AAAA,QACA,UAAU;AAAA,UACR,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,WAAW;AAAA,UACT,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,mBAAmB;AAAA,UACjB,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,MACA,UAAU,CAAC,YAAY,iBAAiB;AAAA,IAC1C;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { DSDecisionGraph, DSDecisionGraphWithSchema } from "./DSDecisionGraph.js";
|
|
3
|
+
import {} from "./react-desc-prop-types.js";
|
|
4
|
+
import { DECISION_GRAPH_SLOTS, DECISION_GRAPH_DATA_TESTID } from "./constants/index.js";
|
|
5
|
+
export {
|
|
6
|
+
DECISION_GRAPH_DATA_TESTID,
|
|
7
|
+
DECISION_GRAPH_SLOTS,
|
|
8
|
+
DSDecisionGraph,
|
|
9
|
+
DSDecisionGraphWithSchema
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "// this is a workaround to typescript error TS2742\n// https://github.com/microsoft/TypeScript/issues/47663\nimport type {} from '@xstyled/system';\nexport { DSDecisionGraph, DSDecisionGraphWithSchema } from './DSDecisionGraph.js';\nexport { type DSDecisionGraphT } from './react-desc-prop-types.js';\nexport { DECISION_GRAPH_SLOTS, DECISION_GRAPH_DATA_TESTID } from './constants/index.js';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,iBAAiB,iCAAiC;AAC3D,eAAsC;AACtC,SAAS,sBAAsB,kCAAkC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import React2 from "react";
|
|
4
|
+
import { decisionTreeToMermaidMD } from "./decisionTreeToMermaidMD.js";
|
|
5
|
+
import mermaid from "mermaid";
|
|
6
|
+
const MermaidDecisionChart = (props) => {
|
|
7
|
+
const { chartJson, uid, direction } = props;
|
|
8
|
+
const mermaidRef = React2.useRef(null);
|
|
9
|
+
const mermaidMD = React2.useMemo(() => decisionTreeToMermaidMD(chartJson, direction), [chartJson, direction]);
|
|
10
|
+
React2.useEffect(() => {
|
|
11
|
+
mermaid.initialize({
|
|
12
|
+
startOnLoad: false
|
|
13
|
+
});
|
|
14
|
+
}, []);
|
|
15
|
+
React2.useEffect(() => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
const renderAsync = async () => {
|
|
18
|
+
const { svg } = await mermaid.render(`mermaid-svg-${uid}`, mermaidMD);
|
|
19
|
+
if (mermaidRef.current) {
|
|
20
|
+
mermaidRef.current.innerHTML = svg;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
void renderAsync();
|
|
24
|
+
}, 0);
|
|
25
|
+
}, [mermaidMD, uid]);
|
|
26
|
+
return /* @__PURE__ */ jsx("pre", { ref: mermaidRef });
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
MermaidDecisionChart
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=MermaidDecisionChart.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/mermaid/MermaidDecisionChart.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport type { DSDecisionGraphT } from '../../react-desc-prop-types.js';\nimport { decisionTreeToMermaidMD } from './decisionTreeToMermaidMD.js';\n// https://github.com/mermaid-js/mermaid/blob/develop/packages/mermaid/src/mermaid.ts#L367\nimport mermaid from 'mermaid';\n\ntype MermaidProps = {\n chartJson: DSDecisionGraphT.Props['chartJson'];\n uid: string;\n direction: DSDecisionGraphT.Directions;\n};\n\nexport const MermaidDecisionChart = (props: MermaidProps) => {\n const { chartJson, uid, direction } = props;\n const mermaidRef = React.useRef<HTMLPreElement>(null);\n // this operation should be O(1), but depending on the size of the decision tree,\n // it is still potentially beneficial to memoize it...\n const mermaidMD = React.useMemo(() => decisionTreeToMermaidMD(chartJson, direction), [chartJson, direction]);\n\n // on mount initialize mermaid\n React.useEffect(() => {\n mermaid.initialize({\n startOnLoad: false,\n });\n }, []);\n\n React.useEffect(() => {\n setTimeout(() => {\n const renderAsync = async () => {\n const { svg } = await mermaid.render(`mermaid-svg-${uid}`, mermaidMD);\n if (mermaidRef.current) {\n mermaidRef.current.innerHTML = svg;\n }\n };\n void renderAsync();\n }, 0);\n }, [mermaidMD, uid]);\n\n return <pre ref={mermaidRef} />;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACsCd;AAtCT,OAAOA,YAAW;AAElB,SAAS,+BAA+B;AAExC,OAAO,aAAa;AAQb,MAAM,uBAAuB,CAAC,UAAwB;AAC3D,QAAM,EAAE,WAAW,KAAK,UAAU,IAAI;AACtC,QAAM,aAAaA,OAAM,OAAuB,IAAI;AAGpD,QAAM,YAAYA,OAAM,QAAQ,MAAM,wBAAwB,WAAW,SAAS,GAAG,CAAC,WAAW,SAAS,CAAC;AAG3G,EAAAA,OAAM,UAAU,MAAM;AACpB,YAAQ,WAAW;AAAA,MACjB,aAAa;AAAA,IACf,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,EAAAA,OAAM,UAAU,MAAM;AACpB,eAAW,MAAM;AACf,YAAM,cAAc,YAAY;AAC9B,cAAM,EAAE,IAAI,IAAI,MAAM,QAAQ,OAAO,eAAe,OAAO,SAAS;AACpE,YAAI,WAAW,SAAS;AACtB,qBAAW,QAAQ,YAAY;AAAA,QACjC;AAAA,MACF;AACA,WAAK,YAAY;AAAA,IACnB,GAAG,CAAC;AAAA,EACN,GAAG,CAAC,WAAW,GAAG,CAAC;AAEnB,SAAO,oBAAC,SAAI,KAAK,YAAY;AAC/B;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function nodePathToLinkMarkdown(nodePath) {
|
|
3
|
+
let linkMarkdown = "";
|
|
4
|
+
switch (nodePath.charAt(nodePath.length - 1)) {
|
|
5
|
+
case "t":
|
|
6
|
+
linkMarkdown = `-->|true|`;
|
|
7
|
+
break;
|
|
8
|
+
case "f":
|
|
9
|
+
linkMarkdown = `-->|false|`;
|
|
10
|
+
break;
|
|
11
|
+
case "o":
|
|
12
|
+
linkMarkdown = `-->|N/A|`;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
return linkMarkdown;
|
|
16
|
+
}
|
|
17
|
+
function isQuestionText(node) {
|
|
18
|
+
return (node.semanticMeaning && node.semanticMeaning === "question") ?? false;
|
|
19
|
+
}
|
|
20
|
+
function nodeToMermaidMD(node, nodePath) {
|
|
21
|
+
let nodeMarkdown;
|
|
22
|
+
if (isQuestionText(node)) {
|
|
23
|
+
nodeMarkdown = `${node?.repeatedId ?? nodePath}{{"${node.nodeText}"}}`;
|
|
24
|
+
} else {
|
|
25
|
+
nodeMarkdown = `${node?.repeatedId ?? nodePath}("${node.nodeText}")`;
|
|
26
|
+
}
|
|
27
|
+
return nodeMarkdown;
|
|
28
|
+
}
|
|
29
|
+
const flatten = (node, decisionNodes, nodePath = "s") => {
|
|
30
|
+
const decisionNode = {
|
|
31
|
+
nodeText: node.nodeText,
|
|
32
|
+
path: nodePath,
|
|
33
|
+
nodeMarkdown: nodeToMermaidMD(node, nodePath)
|
|
34
|
+
};
|
|
35
|
+
decisionNodes.set(nodePath, decisionNode);
|
|
36
|
+
if (node.truePath) {
|
|
37
|
+
flatten(node.truePath, decisionNodes, `${nodePath}t`);
|
|
38
|
+
}
|
|
39
|
+
if (node.falsePath) {
|
|
40
|
+
flatten(node.falsePath, decisionNodes, `${nodePath}f`);
|
|
41
|
+
}
|
|
42
|
+
if (node.notApplicablePath) {
|
|
43
|
+
flatten(node.notApplicablePath, decisionNodes, `${nodePath}o`);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const flattenDecisionTree = (rootNode) => {
|
|
47
|
+
const decisionNodes = /* @__PURE__ */ new Map();
|
|
48
|
+
const treeToFlatten = rootNode.subtree;
|
|
49
|
+
flatten(treeToFlatten, decisionNodes);
|
|
50
|
+
return decisionNodes;
|
|
51
|
+
};
|
|
52
|
+
const decisionTreeToMermaidMD = (rootNode, direction = "LR") => {
|
|
53
|
+
const title = `---
|
|
54
|
+
title: ${rootNode.chartTitle}
|
|
55
|
+
---
|
|
56
|
+
`;
|
|
57
|
+
let mermaidMD = `${title}flowchart ${direction};
|
|
58
|
+
`;
|
|
59
|
+
const decisionNodes = flattenDecisionTree(rootNode);
|
|
60
|
+
decisionNodes.forEach((node, nodePath) => {
|
|
61
|
+
if (nodePath === "s")
|
|
62
|
+
return;
|
|
63
|
+
const parentNodeId = nodePath.slice(0, -1);
|
|
64
|
+
const parentNode = decisionNodes.get(parentNodeId);
|
|
65
|
+
if (parentNode) {
|
|
66
|
+
const linkMarkdown = nodePathToLinkMarkdown(nodePath);
|
|
67
|
+
mermaidMD += ` ${parentNode.nodeMarkdown}${linkMarkdown}${node.nodeMarkdown}
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return mermaidMD;
|
|
72
|
+
};
|
|
73
|
+
export {
|
|
74
|
+
decisionTreeToMermaidMD
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=decisionTreeToMermaidMD.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/mermaid/decisionTreeToMermaidMD.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { DSDecisionGraphT } from '../../react-desc-prop-types.js';\n\n/**************************************************************\n ***************** Mermaid Markdown Generator *****************\n ************************************************************ */\n\ntype FlatDecisionNode = {\n nodeText: string;\n path: DSDecisionGraphT.NodePath;\n nodeMarkdown?: DSDecisionGraphT.NodeMarkdown;\n};\nfunction nodePathToLinkMarkdown(nodePath: DSDecisionGraphT.NodePath): DSDecisionGraphT.LinkMarkdown {\n let linkMarkdown: DSDecisionGraphT.LinkMarkdown = '';\n switch (nodePath.charAt(nodePath.length - 1)) {\n case 't':\n linkMarkdown = `-->|true|`;\n break;\n case 'f':\n linkMarkdown = `-->|false|`;\n break;\n case 'o':\n linkMarkdown = `-->|N/A|`;\n break;\n }\n return linkMarkdown;\n}\nfunction isQuestionText(node: DSDecisionGraphT.DecisionNode): node is DSDecisionGraphT.QuestionNode {\n return (node.semanticMeaning && node.semanticMeaning === 'question') ?? false;\n}\n\nfunction nodeToMermaidMD(\n node: DSDecisionGraphT.DecisionNode,\n nodePath: DSDecisionGraphT.NodePath,\n): DSDecisionGraphT.NodeMarkdown {\n let nodeMarkdown: DSDecisionGraphT.NodeMarkdown;\n\n if (isQuestionText(node)) {\n nodeMarkdown = `${node?.repeatedId ?? nodePath}{{\"${node.nodeText}\"}}`;\n } else {\n nodeMarkdown = `${node?.repeatedId ?? nodePath}(\"${node.nodeText}\")`;\n }\n\n return nodeMarkdown;\n}\n\n/**\n * Recursively flattens a decision tree node and its children.\n * @param {DSDecisionGraphT.DecisionNode} node - The decision tree node to flatten.\n * @param { Map<DSDecisionGraphT.NodePath, FlatDecisionNode>} decisionNodes - the map to track the flattened nodes.\n * @param {DSDecisionGraphT.NodePath} nodePath - The path of the current node in the decision tree.\n */\nconst flatten = (\n node: DSDecisionGraphT.DecisionNode,\n decisionNodes: Map<DSDecisionGraphT.NodePath, FlatDecisionNode>,\n nodePath: DSDecisionGraphT.NodePath = 's' as DSDecisionGraphT.NodePath,\n) => {\n const decisionNode: FlatDecisionNode = {\n nodeText: node.nodeText,\n path: nodePath,\n nodeMarkdown: nodeToMermaidMD(node, nodePath),\n };\n decisionNodes.set(nodePath, decisionNode);\n if (node.truePath) {\n flatten(node.truePath, decisionNodes, `${nodePath}t`);\n }\n if (node.falsePath) {\n flatten(node.falsePath, decisionNodes, `${nodePath}f`);\n }\n if (node.notApplicablePath) {\n flatten(node.notApplicablePath, decisionNodes, `${nodePath}o`);\n }\n};\n\n/**\n * Flattens a decision tree into a map of flat decision nodes.\n * @param {DSDecisionGraphT.RootNode} rootNode - The root node of the decision tree to flatten.\n * @returns {Map<DSDecisionGraphT.NodePath, FlatDecisionNode>} A map of flat decision nodes, where each node is identified by its node ID.\n */\nconst flattenDecisionTree = (rootNode: DSDecisionGraphT.RootNode): Map<DSDecisionGraphT.NodePath, FlatDecisionNode> => {\n const decisionNodes: Map<DSDecisionGraphT.NodePath, FlatDecisionNode> = new Map();\n const treeToFlatten: DSDecisionGraphT.DecisionNode = rootNode.subtree;\n\n flatten(treeToFlatten, decisionNodes);\n return decisionNodes;\n};\n\n/**\n * Flattens a decision tree into a map of flat decision nodes.\n * @param {DSDecisionGraphT.RootNode} rootNode - The root node of the decision tree to flatten.\n * @param {DSDecisionGraphT.Directions} direction - direction of the flowchart, default is LR (left to right)\n * @returns {string} A map of flat decision nodes, where each node is identified by its node ID.\n */\nexport const decisionTreeToMermaidMD = (\n rootNode: DSDecisionGraphT.RootNode,\n direction: DSDecisionGraphT.Directions = 'LR',\n) => {\n const title = `---\\ntitle: ${rootNode.chartTitle}\\n---\\n`;\n let mermaidMD = `${title}flowchart ${direction};\\n`;\n // let mermaidMD = `flowchart LR;\\n subgraph ${rootNode.chartTitle};\\n`; // this add an highlight to the chart and the title\n const decisionNodes = flattenDecisionTree(rootNode);\n decisionNodes.forEach((node, nodePath) => {\n if (nodePath === 's') return;\n const parentNodeId = nodePath.slice(0, -1) as DSDecisionGraphT.NodePath;\n const parentNode = decisionNodes.get(parentNodeId);\n if (parentNode) {\n const linkMarkdown = nodePathToLinkMarkdown(nodePath);\n mermaidMD += `\\t${parentNode.nodeMarkdown}${linkMarkdown}${node.nodeMarkdown}\\n`;\n }\n });\n // mermaidMD += 'end;\\n';\n return mermaidMD;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACWvB,SAAS,uBAAuB,UAAoE;AAClG,MAAI,eAA8C;AAClD,UAAQ,SAAS,OAAO,SAAS,SAAS,CAAC,GAAG;AAAA,IAC5C,KAAK;AACH,qBAAe;AACf;AAAA,IACF,KAAK;AACH,qBAAe;AACf;AAAA,IACF,KAAK;AACH,qBAAe;AACf;AAAA,EACJ;AACA,SAAO;AACT;AACA,SAAS,eAAe,MAA4E;AAClG,UAAQ,KAAK,mBAAmB,KAAK,oBAAoB,eAAe;AAC1E;AAEA,SAAS,gBACP,MACA,UAC+B;AAC/B,MAAI;AAEJ,MAAI,eAAe,IAAI,GAAG;AACxB,mBAAe,GAAG,MAAM,cAAc,cAAc,KAAK;AAAA,EAC3D,OAAO;AACL,mBAAe,GAAG,MAAM,cAAc,aAAa,KAAK;AAAA,EAC1D;AAEA,SAAO;AACT;AAQA,MAAM,UAAU,CACd,MACA,eACA,WAAsC,QACnC;AACH,QAAM,eAAiC;AAAA,IACrC,UAAU,KAAK;AAAA,IACf,MAAM;AAAA,IACN,cAAc,gBAAgB,MAAM,QAAQ;AAAA,EAC9C;AACA,gBAAc,IAAI,UAAU,YAAY;AACxC,MAAI,KAAK,UAAU;AACjB,YAAQ,KAAK,UAAU,eAAe,GAAG,WAAW;AAAA,EACtD;AACA,MAAI,KAAK,WAAW;AAClB,YAAQ,KAAK,WAAW,eAAe,GAAG,WAAW;AAAA,EACvD;AACA,MAAI,KAAK,mBAAmB;AAC1B,YAAQ,KAAK,mBAAmB,eAAe,GAAG,WAAW;AAAA,EAC/D;AACF;AAOA,MAAM,sBAAsB,CAAC,aAA0F;AACrH,QAAM,gBAAkE,oBAAI,IAAI;AAChF,QAAM,gBAA+C,SAAS;AAE9D,UAAQ,eAAe,aAAa;AACpC,SAAO;AACT;AAQO,MAAM,0BAA0B,CACrC,UACA,YAAyC,SACtC;AACH,QAAM,QAAQ;AAAA,SAAe,SAAS;AAAA;AAAA;AACtC,MAAI,YAAY,GAAG,kBAAkB;AAAA;AAErC,QAAM,gBAAgB,oBAAoB,QAAQ;AAClD,gBAAc,QAAQ,CAAC,MAAM,aAAa;AACxC,QAAI,aAAa;AAAK;AACtB,UAAM,eAAe,SAAS,MAAM,GAAG,EAAE;AACzC,UAAM,aAAa,cAAc,IAAI,YAAY;AACjD,QAAI,YAAY;AACd,YAAM,eAAe,uBAAuB,QAAQ;AACpD,mBAAa,IAAK,WAAW,eAAe,eAAe,KAAK;AAAA;AAAA,IAClE;AAAA,EACF,CAAC;AAED,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PropTypes, globalAttributesPropTypes, xstyledPropTypes } from "@elliemae/ds-props-helpers";
|
|
3
|
+
import { JSON_SCHEMA } from "./constants/index.js";
|
|
4
|
+
const defaultProps = {
|
|
5
|
+
direction: "LR"
|
|
6
|
+
};
|
|
7
|
+
const DSDecisionGraphPropTypes = {
|
|
8
|
+
...globalAttributesPropTypes,
|
|
9
|
+
...xstyledPropTypes,
|
|
10
|
+
chartJson: PropTypes.object.description(
|
|
11
|
+
`the json representing the decision chart. must comply with the following json_schema:
|
|
12
|
+
${JSON.stringify(
|
|
13
|
+
JSON_SCHEMA
|
|
14
|
+
)}`
|
|
15
|
+
).isRequired,
|
|
16
|
+
direction: PropTypes.oneOf(["LR", "TD"]).description("direction of the flowchart, default is LR (left to right)").defaultValue("LR")
|
|
17
|
+
};
|
|
18
|
+
const DSDecisionGraphPropTypesSchema = DSDecisionGraphPropTypes;
|
|
19
|
+
export {
|
|
20
|
+
DSDecisionGraphPropTypes,
|
|
21
|
+
DSDecisionGraphPropTypesSchema,
|
|
22
|
+
defaultProps
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=react-desc-prop-types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/react-desc-prop-types.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type { GlobalAttributesT, XstyledProps, DSPropTypesSchema } from '@elliemae/ds-props-helpers';\nimport { PropTypes, globalAttributesPropTypes, xstyledPropTypes } from '@elliemae/ds-props-helpers';\nimport type { WeakValidationMap } from 'react';\nimport { JSON_SCHEMA } from './constants/index.js';\n\nexport declare namespace DSDecisionGraphT {\n export type Directions = 'LR' | 'TD'; // left to right | top down\n export type SemanticMeaning = 'question' | 'conclusion';\n export type NodePath = `${string}${'t' | 'f' | 'o' | 's'}`; // Node ID for a decision node, doubles as the path to the node | T true | F false | O (other) not applicable | S start\n export type ConclusionMarkdown = `${string | NodePath}(${string})`; // Mermaid Markdown for a conclusion node | A node with round edges\n export type QuestionMarkdown = `${string | NodePath}{{${string}}}`; // Mermaid Markdown for a question node | A hexagon node\n export type NodeMarkdown = ConclusionMarkdown | QuestionMarkdown;\n export type TrueLinkMarkdown = `-->|true|`; // Mermaid Markdown for a true path link\n export type FalseLinkMarkdown = `-->|false|`; // Mermaid Markdown for a false path link\n export type NALinkMarkdown = `-->|N/A|`; // Mermaid Markdown for a not applicable path link\n export type LinkMarkdown = TrueLinkMarkdown | FalseLinkMarkdown | NALinkMarkdown | '';\n\n /**\n * Node polymorphism for the \"meaning\" the node has in the decision tree.\n * this influence the node shape in the decision chart.\n */\n // common properties for all nodes\n export interface BaseNode {\n nodeText: string; // Text representing a conclusion or question\n truePath?: DecisionNode; // Decision node for the true path\n falsePath?: DecisionNode; // Decision node for the false path\n notApplicablePath?: DecisionNode; // Decision node for the not applicable path\n repeatedId?: string; // Id of the node if it is repeated in the decision tree and we want to show it only once in the decision chart\n }\n // polymorphism for node with the semantic meaning of \"question\"\n export interface QuestionNode extends BaseNode {\n semanticMeaning: 'question';\n }\n // polymorphism for node with the semantic meaning of \"conclusion\"\n export interface ConclusionNode extends BaseNode {\n semanticMeaning: 'conclusion';\n }\n // polymorphism for all nodes\n export type DecisionNode = QuestionNode | ConclusionNode;\n /**\n * yes, polymorphism in typescript is this verbose and this hard to handle correctly.\n */\n\n export type RootNode = {\n chartTitle: string; // Title of the decision chart\n subtree: DecisionNode; // The root of the decision tree\n };\n\n export interface RequiredProps {\n chartJson: RootNode;\n }\n\n export interface DefaultProps {\n direction: Directions;\n }\n\n export interface OptionalProps {}\n\n export interface Props\n extends Partial<DefaultProps>,\n OptionalProps,\n Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof RequiredProps | keyof XstyledProps>,\n XstyledProps,\n RequiredProps {}\n\n export interface InternalProps\n extends DefaultProps,\n OptionalProps,\n Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof RequiredProps | keyof XstyledProps>,\n XstyledProps,\n RequiredProps {}\n}\n\nexport const defaultProps: DSDecisionGraphT.DefaultProps = {\n direction: 'LR',\n};\n\nexport const DSDecisionGraphPropTypes: DSPropTypesSchema<DSDecisionGraphT.Props> = {\n ...globalAttributesPropTypes,\n ...xstyledPropTypes,\n chartJson: PropTypes.object.description(\n `the json representing the decision chart. must comply with the following json_schema:\\n${JSON.stringify(\n JSON_SCHEMA,\n )}`,\n ).isRequired,\n direction: PropTypes.oneOf(['LR', 'TD'])\n .description('direction of the flowchart, default is LR (left to right)')\n .defaultValue('LR'),\n};\n\nexport const DSDecisionGraphPropTypesSchema =\n DSDecisionGraphPropTypes as unknown as WeakValidationMap<DSDecisionGraphT.Props>;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,WAAW,2BAA2B,wBAAwB;AAEvE,SAAS,mBAAmB;AAsErB,MAAM,eAA8C;AAAA,EACzD,WAAW;AACb;AAEO,MAAM,2BAAsE;AAAA,EACjF,GAAG;AAAA,EACH,GAAG;AAAA,EACH,WAAW,UAAU,OAAO;AAAA,IAC1B;AAAA,EAA0F,KAAK;AAAA,MAC7F;AAAA,IACF;AAAA,EACF,EAAE;AAAA,EACF,WAAW,UAAU,MAAM,CAAC,MAAM,IAAI,CAAC,EACpC,YAAY,2DAA2D,EACvE,aAAa,IAAI;AACtB;AAEO,MAAM,iCACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type DSDecisionGraphT } from './react-desc-prop-types.js';
|
|
3
|
+
declare const DSDecisionGraph: React.ComponentType<DSDecisionGraphT.Props>;
|
|
4
|
+
declare const DSDecisionGraphWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<DSDecisionGraphT.Props>;
|
|
5
|
+
export { DSDecisionGraph, DSDecisionGraphWithSchema };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
2
|
+
import { useGetGlobalAttributes, useGetXstyledProps } from '@elliemae/ds-props-helpers';
|
|
3
|
+
import { type DSDecisionGraphT } from '../react-desc-prop-types.js';
|
|
4
|
+
export interface DecisionGraphCTX {
|
|
5
|
+
propsWithDefault: DSDecisionGraphT.InternalProps;
|
|
6
|
+
globalProps: ReturnType<typeof useGetGlobalAttributes>;
|
|
7
|
+
xstyledProps: ReturnType<typeof useGetXstyledProps>;
|
|
8
|
+
instanceUid: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const useDecisionGraph: (propsFromUser: DSDecisionGraphT.Props) => {
|
|
11
|
+
propsWithDefault: DSDecisionGraphT.InternalProps;
|
|
12
|
+
globalProps: import("lodash").Omit<import("@elliemae/ds-props-helpers").GlobalAttributesT<Element>, "cols" | "rows" | "wrap">;
|
|
13
|
+
xstyledProps: import("@elliemae/ds-props-helpers").XstyledProps;
|
|
14
|
+
instanceUid: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const DSDecisionGraphName = "DSDecisionGraph";
|
|
2
|
+
export declare const DECISION_GRAPH_SLOTS: {
|
|
3
|
+
readonly WRAPPER: "wrapper";
|
|
4
|
+
};
|
|
5
|
+
export declare const DECISION_GRAPH_DATA_TESTID: Record<string, string>;
|
|
6
|
+
export declare const JSON_SCHEMA: {
|
|
7
|
+
readonly $schema: "http://json-schema.org/draft-07/schema#";
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly chartTitle: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
readonly description: "Title of the decision chart";
|
|
13
|
+
};
|
|
14
|
+
readonly subtree: {
|
|
15
|
+
readonly $ref: "#/definitions/DecisionNode";
|
|
16
|
+
readonly description: "The root of the decision tree";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly required: readonly ["chartTitle", "subtree"];
|
|
20
|
+
readonly definitions: {
|
|
21
|
+
readonly DecisionNode: {
|
|
22
|
+
readonly type: "object";
|
|
23
|
+
readonly properties: {
|
|
24
|
+
readonly nodeText: {
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
readonly description: "Text representing a conclusion or question";
|
|
27
|
+
};
|
|
28
|
+
readonly semanticMeaning: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
readonly enum: readonly ["question", "conclusion"];
|
|
31
|
+
};
|
|
32
|
+
readonly repeatedId: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly description: "optional unique identifier for the node, used to allow pointing multiple paths to the same node in the chart";
|
|
35
|
+
};
|
|
36
|
+
readonly truePath: {
|
|
37
|
+
readonly $ref: "#/definitions/DecisionNode";
|
|
38
|
+
readonly description: "Decision node for the true path";
|
|
39
|
+
};
|
|
40
|
+
readonly falsePath: {
|
|
41
|
+
readonly $ref: "#/definitions/DecisionNode";
|
|
42
|
+
readonly description: "Decision node for the false path";
|
|
43
|
+
};
|
|
44
|
+
readonly notApplicablePath: {
|
|
45
|
+
readonly $ref: "#/definitions/DecisionNode";
|
|
46
|
+
readonly description: "Decision node for the not applicable path";
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
readonly required: readonly ["nodeText", "semanticMeaning"];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DSDecisionGraphT } from '../../react-desc-prop-types.js';
|
|
2
|
+
type MermaidProps = {
|
|
3
|
+
chartJson: DSDecisionGraphT.Props['chartJson'];
|
|
4
|
+
uid: string;
|
|
5
|
+
direction: DSDecisionGraphT.Directions;
|
|
6
|
+
};
|
|
7
|
+
export declare const MermaidDecisionChart: (props: MermaidProps) => import("react/jsx-runtime.js").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DSDecisionGraphT } from '../../react-desc-prop-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flattens a decision tree into a map of flat decision nodes.
|
|
4
|
+
* @param {DSDecisionGraphT.RootNode} rootNode - The root node of the decision tree to flatten.
|
|
5
|
+
* @param {DSDecisionGraphT.Directions} direction - direction of the flowchart, default is LR (left to right)
|
|
6
|
+
* @returns {string} A map of flat decision nodes, where each node is identified by its node ID.
|
|
7
|
+
*/
|
|
8
|
+
export declare const decisionTreeToMermaidMD: (rootNode: DSDecisionGraphT.RootNode, direction?: DSDecisionGraphT.Directions) => string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { GlobalAttributesT, XstyledProps, DSPropTypesSchema } from '@elliemae/ds-props-helpers';
|
|
2
|
+
import type { WeakValidationMap } from 'react';
|
|
3
|
+
export declare namespace DSDecisionGraphT {
|
|
4
|
+
type Directions = 'LR' | 'TD';
|
|
5
|
+
type SemanticMeaning = 'question' | 'conclusion';
|
|
6
|
+
type NodePath = `${string}${'t' | 'f' | 'o' | 's'}`;
|
|
7
|
+
type ConclusionMarkdown = `${string | NodePath}(${string})`;
|
|
8
|
+
type QuestionMarkdown = `${string | NodePath}{{${string}}}`;
|
|
9
|
+
type NodeMarkdown = ConclusionMarkdown | QuestionMarkdown;
|
|
10
|
+
type TrueLinkMarkdown = `-->|true|`;
|
|
11
|
+
type FalseLinkMarkdown = `-->|false|`;
|
|
12
|
+
type NALinkMarkdown = `-->|N/A|`;
|
|
13
|
+
type LinkMarkdown = TrueLinkMarkdown | FalseLinkMarkdown | NALinkMarkdown | '';
|
|
14
|
+
/**
|
|
15
|
+
* Node polymorphism for the "meaning" the node has in the decision tree.
|
|
16
|
+
* this influence the node shape in the decision chart.
|
|
17
|
+
*/
|
|
18
|
+
interface BaseNode {
|
|
19
|
+
nodeText: string;
|
|
20
|
+
truePath?: DecisionNode;
|
|
21
|
+
falsePath?: DecisionNode;
|
|
22
|
+
notApplicablePath?: DecisionNode;
|
|
23
|
+
repeatedId?: string;
|
|
24
|
+
}
|
|
25
|
+
interface QuestionNode extends BaseNode {
|
|
26
|
+
semanticMeaning: 'question';
|
|
27
|
+
}
|
|
28
|
+
interface ConclusionNode extends BaseNode {
|
|
29
|
+
semanticMeaning: 'conclusion';
|
|
30
|
+
}
|
|
31
|
+
type DecisionNode = QuestionNode | ConclusionNode;
|
|
32
|
+
/**
|
|
33
|
+
* yes, polymorphism in typescript is this verbose and this hard to handle correctly.
|
|
34
|
+
*/
|
|
35
|
+
type RootNode = {
|
|
36
|
+
chartTitle: string;
|
|
37
|
+
subtree: DecisionNode;
|
|
38
|
+
};
|
|
39
|
+
interface RequiredProps {
|
|
40
|
+
chartJson: RootNode;
|
|
41
|
+
}
|
|
42
|
+
interface DefaultProps {
|
|
43
|
+
direction: Directions;
|
|
44
|
+
}
|
|
45
|
+
interface OptionalProps {
|
|
46
|
+
}
|
|
47
|
+
interface Props extends Partial<DefaultProps>, OptionalProps, Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof RequiredProps | keyof XstyledProps>, XstyledProps, RequiredProps {
|
|
48
|
+
}
|
|
49
|
+
interface InternalProps extends DefaultProps, OptionalProps, Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof RequiredProps | keyof XstyledProps>, XstyledProps, RequiredProps {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export declare const defaultProps: DSDecisionGraphT.DefaultProps;
|
|
53
|
+
export declare const DSDecisionGraphPropTypes: DSPropTypesSchema<DSDecisionGraphT.Props>;
|
|
54
|
+
export declare const DSDecisionGraphPropTypesSchema: WeakValidationMap<DSDecisionGraphT.Props>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|