@csg-org/document-core 0.0.7-alpha.3
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/LICENSE +21 -0
- package/README.md +53 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Waypoint (Metaccountant, Inc.)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @usewaypoint/document-core
|
|
2
|
+
|
|
3
|
+
This is the core library used to build the email messages at [Waypoint](https://www.usewaypoint.com). It is non-opinionated and light on dependencies so that it can be used to compose complex documents.
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> This library is still under development and the final interface is subject
|
|
7
|
+
> to change
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
**Installation with npm**
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install --save @usewaypoint/document-core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
The root of the library is the `DocumentBlocksDictionary` dictionary. This is a mapping of block names to an object with a zod schema and a corresponding React Component.
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
const dictionary = {
|
|
23
|
+
Alert: {
|
|
24
|
+
schema: z.object({
|
|
25
|
+
message: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
Component: ({ message }: { message: string }) => {
|
|
28
|
+
return <div>{message.toUpperCase()}</div>
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This dictionary object is passed as an argument to the builder functions.
|
|
35
|
+
|
|
36
|
+
### `buildBlockComponent`
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
const Block = buildBlockComponent(dictionary);
|
|
40
|
+
|
|
41
|
+
<Block type="Alert" data={{message: 'Hello World' }} />
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `buildBlockConfigurationSchema`
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
const Schema = buildBlockConfigurationSchema(dictionary);
|
|
48
|
+
|
|
49
|
+
const parsedData = Schema.safeParse({
|
|
50
|
+
type: 'Alert',
|
|
51
|
+
data: { message: 'Hello World' },
|
|
52
|
+
});
|
|
53
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@csg-org/document-core",
|
|
3
|
+
"version": "0.0.7-alpha.3",
|
|
4
|
+
"description": "Tools to render waypoint-style documents (core package)",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npx tsup src/index.ts --format cjs,esm --dts --clean"
|
|
20
|
+
},
|
|
21
|
+
"author": "carlos@usewaypoint.com",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^16 || ^17 || ^18",
|
|
25
|
+
"zod": "^1 || ^2 || ^3"
|
|
26
|
+
}
|
|
27
|
+
}
|