@swiftsell/react-cpq 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -0
- package/dist/index.cjs +102 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +65 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +65 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +97 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +11 -1
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
## TODO: UPDATE THIS AI-GENERATED README
|
|
2
|
+
|
|
3
|
+
# SwiftSell React CPQ
|
|
4
|
+
|
|
5
|
+
A React-based Configure, Price, Quote (CPQ) solution with Threedium 3D visualization integration.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
SwiftSell React CPQ is a modern TypeScript/React application designed to provide an interactive configure-price-quote experience with real-time 3D product visualization.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Dynamic Configuration Forms**: Build flexible product configuration interfaces
|
|
14
|
+
- **Real-time Pricing**: Automatic price calculation based on configurations
|
|
15
|
+
- **3D Visualization**: Integrated Threedium 3D model support
|
|
16
|
+
- **Type-Safe**: Full TypeScript support for robust development
|
|
17
|
+
- **Context API**: Centralized state management for CPQ operations
|
|
18
|
+
|
|
19
|
+
## Project Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/
|
|
23
|
+
├── components/ # React components
|
|
24
|
+
│ ├── ConfigurationForm.tsx
|
|
25
|
+
│ ├── fields/ # Form field components
|
|
26
|
+
│ │ ├── SelectField.tsx
|
|
27
|
+
│ │ └── TextField.tsx
|
|
28
|
+
│ └── index.ts
|
|
29
|
+
├── context/ # State management
|
|
30
|
+
│ ├── SwiftSellCPQContext.ts
|
|
31
|
+
│ ├── SwiftSellCPQProvider.tsx
|
|
32
|
+
│ └── useSwiftSellCPQ.ts
|
|
33
|
+
├── threedium/ # 3D visualization integration
|
|
34
|
+
│ ├── ThreediumAdapter.ts
|
|
35
|
+
│ └── useThreediumSync.ts
|
|
36
|
+
├── types/ # TypeScript type definitions
|
|
37
|
+
│ ├── cpq.ts
|
|
38
|
+
│ ├── ui.ts
|
|
39
|
+
│ └── index.ts
|
|
40
|
+
└── index.ts
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Getting Started
|
|
44
|
+
|
|
45
|
+
### Prerequisites
|
|
46
|
+
|
|
47
|
+
- Node.js (v16 or higher)
|
|
48
|
+
- npm or yarn
|
|
49
|
+
|
|
50
|
+
### Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Development
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run dev
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Build
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm run build
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
### Basic Setup
|
|
71
|
+
|
|
72
|
+
Import the provider in your application root:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { SwiftSellCPQProvider } from './context/SwiftSellCPQProvider';
|
|
76
|
+
|
|
77
|
+
function App() {
|
|
78
|
+
return (
|
|
79
|
+
<SwiftSellCPQProvider>
|
|
80
|
+
{/* Your app components */}
|
|
81
|
+
</SwiftSellCPQProvider>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Using the CPQ Context
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { useSwiftSellCPQ } from './context/useSwiftSellCPQ';
|
|
90
|
+
|
|
91
|
+
function MyComponent() {
|
|
92
|
+
const cpq = useSwiftSellCPQ();
|
|
93
|
+
// Use CPQ state and functions
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Technologies
|
|
98
|
+
|
|
99
|
+
- **React** - UI framework
|
|
100
|
+
- **TypeScript** - Static typing
|
|
101
|
+
- **Context API** - State management
|
|
102
|
+
- **Threedium** - 3D visualization
|
|
103
|
+
|
|
104
|
+
## Configuration
|
|
105
|
+
|
|
106
|
+
See `tsconfig.json` and `tsdown.config.ts` for build and TypeScript configuration options.
|
|
107
|
+
|
|
108
|
+
## Contributing
|
|
109
|
+
|
|
110
|
+
Please follow the existing code structure and TypeScript conventions when contributing.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
[Add your license information here]
|
|
115
|
+
|
|
116
|
+
## Support
|
|
117
|
+
|
|
118
|
+
For issues and questions, please open an issue in the repository.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
|
|
5
|
+
//#region src/context/SwiftSellCPQContext.ts
|
|
6
|
+
const SwiftSellCPQContext = (0, react.createContext)(null);
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/context/SwiftSellCPQProvider.tsx
|
|
10
|
+
const INITIAL_FIELDS = [{
|
|
11
|
+
id: "color",
|
|
12
|
+
label: "Color",
|
|
13
|
+
type: "select",
|
|
14
|
+
value: "red",
|
|
15
|
+
options: [{
|
|
16
|
+
value: "red",
|
|
17
|
+
label: "Red"
|
|
18
|
+
}, {
|
|
19
|
+
value: "blue",
|
|
20
|
+
label: "Blue"
|
|
21
|
+
}]
|
|
22
|
+
}, {
|
|
23
|
+
id: "name",
|
|
24
|
+
label: "Name",
|
|
25
|
+
type: "text",
|
|
26
|
+
value: ""
|
|
27
|
+
}];
|
|
28
|
+
function SwiftSellCPQProvider({ children }) {
|
|
29
|
+
const [fields, setFields] = (0, react.useState)(INITIAL_FIELDS);
|
|
30
|
+
const setValue = (0, react.useCallback)((fieldId, value) => {
|
|
31
|
+
setFields((prev) => prev.map((f) => f.id === fieldId ? {
|
|
32
|
+
...f,
|
|
33
|
+
value
|
|
34
|
+
} : f));
|
|
35
|
+
}, []);
|
|
36
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwiftSellCPQContext.Provider, {
|
|
37
|
+
value: {
|
|
38
|
+
fields,
|
|
39
|
+
setValue
|
|
40
|
+
},
|
|
41
|
+
children
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/context/useSwiftSellCPQ.ts
|
|
47
|
+
function useSwiftSellCPQ() {
|
|
48
|
+
const ctx = (0, react.useContext)(SwiftSellCPQContext);
|
|
49
|
+
if (!ctx) throw new Error("useSwiftSellCPQ must be used within a SwiftSellCPQProvider");
|
|
50
|
+
return ctx;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/components/fields/SelectField.tsx
|
|
55
|
+
function SelectField({ fieldId, render }) {
|
|
56
|
+
const { fields, setValue } = useSwiftSellCPQ();
|
|
57
|
+
const field = fields.find((f) => f.id === fieldId);
|
|
58
|
+
if (!field || field.type !== "select") return null;
|
|
59
|
+
if (render) return render({
|
|
60
|
+
field,
|
|
61
|
+
setValue: (value) => setValue(fieldId, value)
|
|
62
|
+
});
|
|
63
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
|
|
64
|
+
value: field.value,
|
|
65
|
+
onChange: (e) => setValue(fieldId, e.target.value),
|
|
66
|
+
children: field.options?.map((opt) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
67
|
+
value: opt.value,
|
|
68
|
+
children: opt.label
|
|
69
|
+
}, opt.value))
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/components/fields/TextField.tsx
|
|
75
|
+
function TextField({ fieldId, render }) {
|
|
76
|
+
const { fields, setValue } = useSwiftSellCPQ();
|
|
77
|
+
const field = fields.find((f) => f.id === fieldId);
|
|
78
|
+
if (!field || field.type !== "text") return null;
|
|
79
|
+
if (render) return render({
|
|
80
|
+
field,
|
|
81
|
+
setValue: (value) => setValue(fieldId, value)
|
|
82
|
+
});
|
|
83
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
84
|
+
type: "text",
|
|
85
|
+
value: field.value,
|
|
86
|
+
onChange: (e) => setValue(fieldId, e.target.value)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/components/ConfigurationForm.tsx
|
|
92
|
+
function ConfigurationForm() {
|
|
93
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectField, { fieldId: "color" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, { fieldId: "name" })] });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
exports.ConfigurationForm = ConfigurationForm;
|
|
98
|
+
exports.SelectField = SelectField;
|
|
99
|
+
exports.SwiftSellCPQProvider = SwiftSellCPQProvider;
|
|
100
|
+
exports.TextField = TextField;
|
|
101
|
+
exports.useSwiftSellCPQ = useSwiftSellCPQ;
|
|
102
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/context/SwiftSellCPQContext.ts","../src/context/SwiftSellCPQProvider.tsx","../src/context/useSwiftSellCPQ.ts","../src/components/fields/SelectField.tsx","../src/components/fields/TextField.tsx","../src/components/ConfigurationForm.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { CPQField } from '../types';\n\nexport interface SwiftSellCPQContextValue {\n fields: CPQField[];\n setValue: (fieldId: string, value: string) => void;\n}\n\nexport const SwiftSellCPQContext =\n createContext<SwiftSellCPQContextValue | null>(null);\n","import { useState, useCallback, type ReactNode } from 'react';\nimport { SwiftSellCPQContext } from './SwiftSellCPQContext';\nimport type { CPQField } from '../types';\n\nexport interface SwiftSellCPQProviderProps {\n children: ReactNode;\n}\n\nconst INITIAL_FIELDS: CPQField[] = [\n {\n id: 'color',\n label: 'Color',\n type: 'select',\n value: 'red',\n options: [\n { value: 'red', label: 'Red' },\n { value: 'blue', label: 'Blue' },\n ],\n },\n {\n id: 'name',\n label: 'Name',\n type: 'text',\n value: '',\n },\n];\n\nexport function SwiftSellCPQProvider({ children }: SwiftSellCPQProviderProps) {\n const [fields, setFields] = useState<CPQField[]>(INITIAL_FIELDS);\n\n const setValue = useCallback((fieldId: string, value: string) => {\n setFields((prev) =>\n prev.map((f) => (f.id === fieldId ? { ...f, value } : f)),\n );\n }, []);\n\n return (\n <SwiftSellCPQContext.Provider value={{ fields, setValue }}>\n {children}\n </SwiftSellCPQContext.Provider>\n );\n}\n","import { useContext } from 'react';\nimport { SwiftSellCPQContext } from './SwiftSellCPQContext';\n\nexport function useSwiftSellCPQ() {\n const ctx = useContext(SwiftSellCPQContext);\n if (!ctx) {\n throw new Error(\n 'useSwiftSellCPQ must be used within a SwiftSellCPQProvider',\n );\n }\n return ctx;\n}\n","import { useSwiftSellCPQ } from '../../context/useSwiftSellCPQ';\nimport type { RenderFieldProps } from '../../types';\n\ninterface SelectFieldProps {\n fieldId: string;\n render?: (props: RenderFieldProps) => React.ReactNode;\n}\n\nexport function SelectField({ fieldId, render }: SelectFieldProps) {\n const { fields, setValue } = useSwiftSellCPQ();\n const field = fields.find((f) => f.id === fieldId);\n\n if (!field || field.type !== 'select') return null;\n\n if (render) {\n return render({\n field,\n setValue: (value) => setValue(fieldId, value),\n });\n }\n\n return (\n <select\n value={field.value}\n onChange={(e) => setValue(fieldId, e.target.value)}\n >\n {field.options?.map((opt) => (\n <option\n key={opt.value}\n value={opt.value}\n >\n {opt.label}\n </option>\n ))}\n </select>\n );\n}\n","import { useSwiftSellCPQ } from '../../context/useSwiftSellCPQ';\nimport type { RenderFieldProps } from '../../types';\n\ninterface TextFieldProps {\n fieldId: string;\n render?: (props: RenderFieldProps) => React.ReactNode;\n}\n\nexport function TextField({ fieldId, render }: TextFieldProps) {\n const { fields, setValue } = useSwiftSellCPQ();\n const field = fields.find((f) => f.id === fieldId);\n\n if (!field || field.type !== 'text') return null;\n\n if (render) {\n return render({\n field,\n setValue: (value) => setValue(fieldId, value),\n });\n }\n\n return (\n <input\n type=\"text\"\n value={field.value}\n onChange={(e) => setValue(fieldId, e.target.value)}\n />\n );\n}\n","import { SelectField, TextField } from './fields';\n\nexport function ConfigurationForm() {\n return (\n <div>\n <SelectField fieldId=\"color\" />\n <TextField fieldId=\"name\" />\n </div>\n );\n}\n"],"mappings":";;;;;AAQA,MAAa,+CACoC,KAAK;;;;ACDtD,MAAM,iBAA6B,CACjC;CACE,IAAI;CACJ,OAAO;CACP,MAAM;CACN,OAAO;CACP,SAAS,CACP;EAAE,OAAO;EAAO,OAAO;EAAO,EAC9B;EAAE,OAAO;EAAQ,OAAO;EAAQ,CACjC;CACF,EACD;CACE,IAAI;CACJ,OAAO;CACP,MAAM;CACN,OAAO;CACR,CACF;AAED,SAAgB,qBAAqB,EAAE,YAAuC;CAC5E,MAAM,CAAC,QAAQ,iCAAkC,eAAe;CAEhE,MAAM,mCAAwB,SAAiB,UAAkB;AAC/D,aAAW,SACT,KAAK,KAAK,MAAO,EAAE,OAAO,UAAU;GAAE,GAAG;GAAG;GAAO,GAAG,EAAG,CAC1D;IACA,EAAE,CAAC;AAEN,QACE,2CAAC,oBAAoB;EAAS,OAAO;GAAE;GAAQ;GAAU;EACtD;GAC4B;;;;;ACpCnC,SAAgB,kBAAkB;CAChC,MAAM,4BAAiB,oBAAoB;AAC3C,KAAI,CAAC,IACH,OAAM,IAAI,MACR,6DACD;AAEH,QAAO;;;;;ACFT,SAAgB,YAAY,EAAE,SAAS,UAA4B;CACjE,MAAM,EAAE,QAAQ,aAAa,iBAAiB;CAC9C,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,QAAQ;AAElD,KAAI,CAAC,SAAS,MAAM,SAAS,SAAU,QAAO;AAE9C,KAAI,OACF,QAAO,OAAO;EACZ;EACA,WAAW,UAAU,SAAS,SAAS,MAAM;EAC9C,CAAC;AAGJ,QACE,2CAAC;EACC,OAAO,MAAM;EACb,WAAW,MAAM,SAAS,SAAS,EAAE,OAAO,MAAM;YAEjD,MAAM,SAAS,KAAK,QACnB,2CAAC;GAEC,OAAO,IAAI;aAEV,IAAI;KAHA,IAAI,MAIF,CACT;GACK;;;;;AC1Bb,SAAgB,UAAU,EAAE,SAAS,UAA0B;CAC7D,MAAM,EAAE,QAAQ,aAAa,iBAAiB;CAC9C,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,QAAQ;AAElD,KAAI,CAAC,SAAS,MAAM,SAAS,OAAQ,QAAO;AAE5C,KAAI,OACF,QAAO,OAAO;EACZ;EACA,WAAW,UAAU,SAAS,SAAS,MAAM;EAC9C,CAAC;AAGJ,QACE,2CAAC;EACC,MAAK;EACL,OAAO,MAAM;EACb,WAAW,MAAM,SAAS,SAAS,EAAE,OAAO,MAAM;GAClD;;;;;ACxBN,SAAgB,oBAAoB;AAClC,QACE,4CAAC,oBACC,2CAAC,eAAY,SAAQ,UAAU,EAC/B,2CAAC,aAAU,SAAQ,SAAS,IACxB"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
import * as react from "react";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/context/SwiftSellCPQProvider.d.ts
|
|
6
|
+
interface SwiftSellCPQProviderProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
declare function SwiftSellCPQProvider({
|
|
10
|
+
children
|
|
11
|
+
}: SwiftSellCPQProviderProps): react_jsx_runtime0.JSX.Element;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/types/cpq.d.ts
|
|
14
|
+
interface CPQFieldOption {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
interface CPQField {
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
type: 'text' | 'select';
|
|
22
|
+
value: string;
|
|
23
|
+
options?: CPQFieldOption[];
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/types/ui.d.ts
|
|
27
|
+
interface RenderFieldProps {
|
|
28
|
+
field: CPQField;
|
|
29
|
+
setValue: (value: string) => void;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/context/SwiftSellCPQContext.d.ts
|
|
33
|
+
interface SwiftSellCPQContextValue {
|
|
34
|
+
fields: CPQField[];
|
|
35
|
+
setValue: (fieldId: string, value: string) => void;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/context/useSwiftSellCPQ.d.ts
|
|
39
|
+
declare function useSwiftSellCPQ(): SwiftSellCPQContextValue;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/components/ConfigurationForm.d.ts
|
|
42
|
+
declare function ConfigurationForm(): react_jsx_runtime0.JSX.Element;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/components/fields/SelectField.d.ts
|
|
45
|
+
interface SelectFieldProps {
|
|
46
|
+
fieldId: string;
|
|
47
|
+
render?: (props: RenderFieldProps) => React.ReactNode;
|
|
48
|
+
}
|
|
49
|
+
declare function SelectField({
|
|
50
|
+
fieldId,
|
|
51
|
+
render
|
|
52
|
+
}: SelectFieldProps): string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null | undefined;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/components/fields/TextField.d.ts
|
|
55
|
+
interface TextFieldProps {
|
|
56
|
+
fieldId: string;
|
|
57
|
+
render?: (props: RenderFieldProps) => React.ReactNode;
|
|
58
|
+
}
|
|
59
|
+
declare function TextField({
|
|
60
|
+
fieldId,
|
|
61
|
+
render
|
|
62
|
+
}: TextFieldProps): string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null | undefined;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { CPQField, CPQFieldOption, ConfigurationForm, RenderFieldProps, SelectField, SwiftSellCPQProvider, TextField, useSwiftSellCPQ };
|
|
65
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/context/SwiftSellCPQProvider.tsx","../src/types/cpq.ts","../src/types/ui.ts","../src/context/SwiftSellCPQContext.ts","../src/context/useSwiftSellCPQ.ts","../src/components/ConfigurationForm.tsx","../src/components/fields/SelectField.tsx","../src/components/fields/TextField.tsx"],"mappings":";;;;;UAIiB,yBAAA;EACf,QAAA,EAAU,SAAA;AAAA;AAAA,iBAsBI,oBAAA,CAAA;EAAuB;AAAA,GAAY,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;UC3B3D,cAAA;EACf,KAAA;EACA,KAAA;AAAA;AAAA,UAGe,QAAA;EACf,EAAA;EACA,KAAA;EACA,IAAA;EACA,KAAA;EACA,OAAA,GAAU,cAAA;AAAA;;;UCRK,gBAAA;EACf,KAAA,EAAO,QAAA;EACP,QAAA,GAAW,KAAA;AAAA;;;UCDI,wBAAA;EACf,MAAA,EAAQ,QAAA;EACR,QAAA,GAAW,OAAA,UAAiB,KAAA;AAAA;;;iBCFd,eAAA,CAAA,GAAe,wBAAA;;;iBCDf,iBAAA,CAAA,GAAiB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;UCCvB,gBAAA;EACR,OAAA;EACA,MAAA,IAAU,KAAA,EAAO,gBAAA,KAAqB,KAAA,CAAM,SAAA;AAAA;AAAA,iBAG9B,WAAA,CAAA;EAAc,OAAA;EAAS;AAAA,GAAU,gBAAA,wCAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA,GAAA,QAAA,CAAA,KAAA,CAAA,SAAA,IAAA,OAAA,sCAAA,KAAA,CAAA,WAAA,GAAA,KAAA,CAAA,YAAA,mBAAA,KAAA,CAAA,qBAAA,SAAA,QAAA,CAAA,KAAA,CAAA,SAAA;;;UCLvD,cAAA;EACR,OAAA;EACA,MAAA,IAAU,KAAA,EAAO,gBAAA,KAAqB,KAAA,CAAM,SAAA;AAAA;AAAA,iBAG9B,SAAA,CAAA;EAAY,OAAA;EAAS;AAAA,GAAU,cAAA,wCAAc,kBAAA,CAAA,GAAA,CAAA,OAAA,GAAA,QAAA,CAAA,KAAA,CAAA,SAAA,IAAA,OAAA,sCAAA,KAAA,CAAA,WAAA,GAAA,KAAA,CAAA,YAAA,mBAAA,KAAA,CAAA,qBAAA,SAAA,QAAA,CAAA,KAAA,CAAA,SAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as react from "react";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/context/SwiftSellCPQProvider.d.ts
|
|
6
|
+
interface SwiftSellCPQProviderProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
declare function SwiftSellCPQProvider({
|
|
10
|
+
children
|
|
11
|
+
}: SwiftSellCPQProviderProps): react_jsx_runtime0.JSX.Element;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/types/cpq.d.ts
|
|
14
|
+
interface CPQFieldOption {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
interface CPQField {
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
type: 'text' | 'select';
|
|
22
|
+
value: string;
|
|
23
|
+
options?: CPQFieldOption[];
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/types/ui.d.ts
|
|
27
|
+
interface RenderFieldProps {
|
|
28
|
+
field: CPQField;
|
|
29
|
+
setValue: (value: string) => void;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/context/SwiftSellCPQContext.d.ts
|
|
33
|
+
interface SwiftSellCPQContextValue {
|
|
34
|
+
fields: CPQField[];
|
|
35
|
+
setValue: (fieldId: string, value: string) => void;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/context/useSwiftSellCPQ.d.ts
|
|
39
|
+
declare function useSwiftSellCPQ(): SwiftSellCPQContextValue;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/components/ConfigurationForm.d.ts
|
|
42
|
+
declare function ConfigurationForm(): react_jsx_runtime0.JSX.Element;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/components/fields/SelectField.d.ts
|
|
45
|
+
interface SelectFieldProps {
|
|
46
|
+
fieldId: string;
|
|
47
|
+
render?: (props: RenderFieldProps) => React.ReactNode;
|
|
48
|
+
}
|
|
49
|
+
declare function SelectField({
|
|
50
|
+
fieldId,
|
|
51
|
+
render
|
|
52
|
+
}: SelectFieldProps): string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null | undefined;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/components/fields/TextField.d.ts
|
|
55
|
+
interface TextFieldProps {
|
|
56
|
+
fieldId: string;
|
|
57
|
+
render?: (props: RenderFieldProps) => React.ReactNode;
|
|
58
|
+
}
|
|
59
|
+
declare function TextField({
|
|
60
|
+
fieldId,
|
|
61
|
+
render
|
|
62
|
+
}: TextFieldProps): string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null | undefined;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { CPQField, CPQFieldOption, ConfigurationForm, RenderFieldProps, SelectField, SwiftSellCPQProvider, TextField, useSwiftSellCPQ };
|
|
65
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/context/SwiftSellCPQProvider.tsx","../src/types/cpq.ts","../src/types/ui.ts","../src/context/SwiftSellCPQContext.ts","../src/context/useSwiftSellCPQ.ts","../src/components/ConfigurationForm.tsx","../src/components/fields/SelectField.tsx","../src/components/fields/TextField.tsx"],"mappings":";;;;;UAIiB,yBAAA;EACf,QAAA,EAAU,SAAA;AAAA;AAAA,iBAsBI,oBAAA,CAAA;EAAuB;AAAA,GAAY,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;UC3B3D,cAAA;EACf,KAAA;EACA,KAAA;AAAA;AAAA,UAGe,QAAA;EACf,EAAA;EACA,KAAA;EACA,IAAA;EACA,KAAA;EACA,OAAA,GAAU,cAAA;AAAA;;;UCRK,gBAAA;EACf,KAAA,EAAO,QAAA;EACP,QAAA,GAAW,KAAA;AAAA;;;UCDI,wBAAA;EACf,MAAA,EAAQ,QAAA;EACR,QAAA,GAAW,OAAA,UAAiB,KAAA;AAAA;;;iBCFd,eAAA,CAAA,GAAe,wBAAA;;;iBCDf,iBAAA,CAAA,GAAiB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;UCCvB,gBAAA;EACR,OAAA;EACA,MAAA,IAAU,KAAA,EAAO,gBAAA,KAAqB,KAAA,CAAM,SAAA;AAAA;AAAA,iBAG9B,WAAA,CAAA;EAAc,OAAA;EAAS;AAAA,GAAU,gBAAA,wCAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA,GAAA,QAAA,CAAA,KAAA,CAAA,SAAA,IAAA,OAAA,sCAAA,KAAA,CAAA,WAAA,GAAA,KAAA,CAAA,YAAA,mBAAA,KAAA,CAAA,qBAAA,SAAA,QAAA,CAAA,KAAA,CAAA,SAAA;;;UCLvD,cAAA;EACR,OAAA;EACA,MAAA,IAAU,KAAA,EAAO,gBAAA,KAAqB,KAAA,CAAM,SAAA;AAAA;AAAA,iBAG9B,SAAA,CAAA;EAAY,OAAA;EAAS;AAAA,GAAU,cAAA,wCAAc,kBAAA,CAAA,GAAA,CAAA,OAAA,GAAA,QAAA,CAAA,KAAA,CAAA,SAAA,IAAA,OAAA,sCAAA,KAAA,CAAA,WAAA,GAAA,KAAA,CAAA,YAAA,mBAAA,KAAA,CAAA,qBAAA,SAAA,QAAA,CAAA,KAAA,CAAA,SAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useState } from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/context/SwiftSellCPQContext.ts
|
|
5
|
+
const SwiftSellCPQContext = createContext(null);
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/context/SwiftSellCPQProvider.tsx
|
|
9
|
+
const INITIAL_FIELDS = [{
|
|
10
|
+
id: "color",
|
|
11
|
+
label: "Color",
|
|
12
|
+
type: "select",
|
|
13
|
+
value: "red",
|
|
14
|
+
options: [{
|
|
15
|
+
value: "red",
|
|
16
|
+
label: "Red"
|
|
17
|
+
}, {
|
|
18
|
+
value: "blue",
|
|
19
|
+
label: "Blue"
|
|
20
|
+
}]
|
|
21
|
+
}, {
|
|
22
|
+
id: "name",
|
|
23
|
+
label: "Name",
|
|
24
|
+
type: "text",
|
|
25
|
+
value: ""
|
|
26
|
+
}];
|
|
27
|
+
function SwiftSellCPQProvider({ children }) {
|
|
28
|
+
const [fields, setFields] = useState(INITIAL_FIELDS);
|
|
29
|
+
const setValue = useCallback((fieldId, value) => {
|
|
30
|
+
setFields((prev) => prev.map((f) => f.id === fieldId ? {
|
|
31
|
+
...f,
|
|
32
|
+
value
|
|
33
|
+
} : f));
|
|
34
|
+
}, []);
|
|
35
|
+
return /* @__PURE__ */ jsx(SwiftSellCPQContext.Provider, {
|
|
36
|
+
value: {
|
|
37
|
+
fields,
|
|
38
|
+
setValue
|
|
39
|
+
},
|
|
40
|
+
children
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/context/useSwiftSellCPQ.ts
|
|
46
|
+
function useSwiftSellCPQ() {
|
|
47
|
+
const ctx = useContext(SwiftSellCPQContext);
|
|
48
|
+
if (!ctx) throw new Error("useSwiftSellCPQ must be used within a SwiftSellCPQProvider");
|
|
49
|
+
return ctx;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/components/fields/SelectField.tsx
|
|
54
|
+
function SelectField({ fieldId, render }) {
|
|
55
|
+
const { fields, setValue } = useSwiftSellCPQ();
|
|
56
|
+
const field = fields.find((f) => f.id === fieldId);
|
|
57
|
+
if (!field || field.type !== "select") return null;
|
|
58
|
+
if (render) return render({
|
|
59
|
+
field,
|
|
60
|
+
setValue: (value) => setValue(fieldId, value)
|
|
61
|
+
});
|
|
62
|
+
return /* @__PURE__ */ jsx("select", {
|
|
63
|
+
value: field.value,
|
|
64
|
+
onChange: (e) => setValue(fieldId, e.target.value),
|
|
65
|
+
children: field.options?.map((opt) => /* @__PURE__ */ jsx("option", {
|
|
66
|
+
value: opt.value,
|
|
67
|
+
children: opt.label
|
|
68
|
+
}, opt.value))
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/components/fields/TextField.tsx
|
|
74
|
+
function TextField({ fieldId, render }) {
|
|
75
|
+
const { fields, setValue } = useSwiftSellCPQ();
|
|
76
|
+
const field = fields.find((f) => f.id === fieldId);
|
|
77
|
+
if (!field || field.type !== "text") return null;
|
|
78
|
+
if (render) return render({
|
|
79
|
+
field,
|
|
80
|
+
setValue: (value) => setValue(fieldId, value)
|
|
81
|
+
});
|
|
82
|
+
return /* @__PURE__ */ jsx("input", {
|
|
83
|
+
type: "text",
|
|
84
|
+
value: field.value,
|
|
85
|
+
onChange: (e) => setValue(fieldId, e.target.value)
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/components/ConfigurationForm.tsx
|
|
91
|
+
function ConfigurationForm() {
|
|
92
|
+
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(SelectField, { fieldId: "color" }), /* @__PURE__ */ jsx(TextField, { fieldId: "name" })] });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { ConfigurationForm, SelectField, SwiftSellCPQProvider, TextField, useSwiftSellCPQ };
|
|
97
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/context/SwiftSellCPQContext.ts","../src/context/SwiftSellCPQProvider.tsx","../src/context/useSwiftSellCPQ.ts","../src/components/fields/SelectField.tsx","../src/components/fields/TextField.tsx","../src/components/ConfigurationForm.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { CPQField } from '../types';\n\nexport interface SwiftSellCPQContextValue {\n fields: CPQField[];\n setValue: (fieldId: string, value: string) => void;\n}\n\nexport const SwiftSellCPQContext =\n createContext<SwiftSellCPQContextValue | null>(null);\n","import { useState, useCallback, type ReactNode } from 'react';\nimport { SwiftSellCPQContext } from './SwiftSellCPQContext';\nimport type { CPQField } from '../types';\n\nexport interface SwiftSellCPQProviderProps {\n children: ReactNode;\n}\n\nconst INITIAL_FIELDS: CPQField[] = [\n {\n id: 'color',\n label: 'Color',\n type: 'select',\n value: 'red',\n options: [\n { value: 'red', label: 'Red' },\n { value: 'blue', label: 'Blue' },\n ],\n },\n {\n id: 'name',\n label: 'Name',\n type: 'text',\n value: '',\n },\n];\n\nexport function SwiftSellCPQProvider({ children }: SwiftSellCPQProviderProps) {\n const [fields, setFields] = useState<CPQField[]>(INITIAL_FIELDS);\n\n const setValue = useCallback((fieldId: string, value: string) => {\n setFields((prev) =>\n prev.map((f) => (f.id === fieldId ? { ...f, value } : f)),\n );\n }, []);\n\n return (\n <SwiftSellCPQContext.Provider value={{ fields, setValue }}>\n {children}\n </SwiftSellCPQContext.Provider>\n );\n}\n","import { useContext } from 'react';\nimport { SwiftSellCPQContext } from './SwiftSellCPQContext';\n\nexport function useSwiftSellCPQ() {\n const ctx = useContext(SwiftSellCPQContext);\n if (!ctx) {\n throw new Error(\n 'useSwiftSellCPQ must be used within a SwiftSellCPQProvider',\n );\n }\n return ctx;\n}\n","import { useSwiftSellCPQ } from '../../context/useSwiftSellCPQ';\nimport type { RenderFieldProps } from '../../types';\n\ninterface SelectFieldProps {\n fieldId: string;\n render?: (props: RenderFieldProps) => React.ReactNode;\n}\n\nexport function SelectField({ fieldId, render }: SelectFieldProps) {\n const { fields, setValue } = useSwiftSellCPQ();\n const field = fields.find((f) => f.id === fieldId);\n\n if (!field || field.type !== 'select') return null;\n\n if (render) {\n return render({\n field,\n setValue: (value) => setValue(fieldId, value),\n });\n }\n\n return (\n <select\n value={field.value}\n onChange={(e) => setValue(fieldId, e.target.value)}\n >\n {field.options?.map((opt) => (\n <option\n key={opt.value}\n value={opt.value}\n >\n {opt.label}\n </option>\n ))}\n </select>\n );\n}\n","import { useSwiftSellCPQ } from '../../context/useSwiftSellCPQ';\nimport type { RenderFieldProps } from '../../types';\n\ninterface TextFieldProps {\n fieldId: string;\n render?: (props: RenderFieldProps) => React.ReactNode;\n}\n\nexport function TextField({ fieldId, render }: TextFieldProps) {\n const { fields, setValue } = useSwiftSellCPQ();\n const field = fields.find((f) => f.id === fieldId);\n\n if (!field || field.type !== 'text') return null;\n\n if (render) {\n return render({\n field,\n setValue: (value) => setValue(fieldId, value),\n });\n }\n\n return (\n <input\n type=\"text\"\n value={field.value}\n onChange={(e) => setValue(fieldId, e.target.value)}\n />\n );\n}\n","import { SelectField, TextField } from './fields';\n\nexport function ConfigurationForm() {\n return (\n <div>\n <SelectField fieldId=\"color\" />\n <TextField fieldId=\"name\" />\n </div>\n );\n}\n"],"mappings":";;;;AAQA,MAAa,sBACX,cAA+C,KAAK;;;;ACDtD,MAAM,iBAA6B,CACjC;CACE,IAAI;CACJ,OAAO;CACP,MAAM;CACN,OAAO;CACP,SAAS,CACP;EAAE,OAAO;EAAO,OAAO;EAAO,EAC9B;EAAE,OAAO;EAAQ,OAAO;EAAQ,CACjC;CACF,EACD;CACE,IAAI;CACJ,OAAO;CACP,MAAM;CACN,OAAO;CACR,CACF;AAED,SAAgB,qBAAqB,EAAE,YAAuC;CAC5E,MAAM,CAAC,QAAQ,aAAa,SAAqB,eAAe;CAEhE,MAAM,WAAW,aAAa,SAAiB,UAAkB;AAC/D,aAAW,SACT,KAAK,KAAK,MAAO,EAAE,OAAO,UAAU;GAAE,GAAG;GAAG;GAAO,GAAG,EAAG,CAC1D;IACA,EAAE,CAAC;AAEN,QACE,oBAAC,oBAAoB;EAAS,OAAO;GAAE;GAAQ;GAAU;EACtD;GAC4B;;;;;ACpCnC,SAAgB,kBAAkB;CAChC,MAAM,MAAM,WAAW,oBAAoB;AAC3C,KAAI,CAAC,IACH,OAAM,IAAI,MACR,6DACD;AAEH,QAAO;;;;;ACFT,SAAgB,YAAY,EAAE,SAAS,UAA4B;CACjE,MAAM,EAAE,QAAQ,aAAa,iBAAiB;CAC9C,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,QAAQ;AAElD,KAAI,CAAC,SAAS,MAAM,SAAS,SAAU,QAAO;AAE9C,KAAI,OACF,QAAO,OAAO;EACZ;EACA,WAAW,UAAU,SAAS,SAAS,MAAM;EAC9C,CAAC;AAGJ,QACE,oBAAC;EACC,OAAO,MAAM;EACb,WAAW,MAAM,SAAS,SAAS,EAAE,OAAO,MAAM;YAEjD,MAAM,SAAS,KAAK,QACnB,oBAAC;GAEC,OAAO,IAAI;aAEV,IAAI;KAHA,IAAI,MAIF,CACT;GACK;;;;;AC1Bb,SAAgB,UAAU,EAAE,SAAS,UAA0B;CAC7D,MAAM,EAAE,QAAQ,aAAa,iBAAiB;CAC9C,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,QAAQ;AAElD,KAAI,CAAC,SAAS,MAAM,SAAS,OAAQ,QAAO;AAE5C,KAAI,OACF,QAAO,OAAO;EACZ;EACA,WAAW,UAAU,SAAS,SAAS,MAAM;EAC9C,CAAC;AAGJ,QACE,oBAAC;EACC,MAAK;EACL,OAAO,MAAM;EACb,WAAW,MAAM,SAAS,SAAS,EAAE,OAAO,MAAM;GAClD;;;;;ACxBN,SAAgB,oBAAoB;AAClC,QACE,qBAAC,oBACC,oBAAC,eAAY,SAAQ,UAAU,EAC/B,oBAAC,aAAU,SAAQ,SAAS,IACxB"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swiftsell/react-cpq",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "React CPQ component library for use with Infor CPQ",
|
|
5
5
|
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public",
|
|
8
|
+
"provenance": false,
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/RenTechAdmin/SwiftSellReactCPQ.git"
|
|
14
|
+
},
|
|
6
15
|
"type": "module",
|
|
7
16
|
"files": [
|
|
8
17
|
"dist"
|
|
@@ -30,6 +39,7 @@
|
|
|
30
39
|
},
|
|
31
40
|
"devDependencies": {
|
|
32
41
|
"@changesets/cli": "^2.29.8",
|
|
42
|
+
"@types/node": "^25.2.2",
|
|
33
43
|
"@types/react": "^19.2.13",
|
|
34
44
|
"@types/react-dom": "^19.2.3",
|
|
35
45
|
"eslint": "^10.0.0",
|