@csg-org/document-core 0.0.7-alpha.3 → 0.0.9

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.
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { z } from 'zod';
3
+
4
+ type BaseZodDictionary = {
5
+ [name: string]: z.AnyZodObject;
6
+ };
7
+ type DocumentBlocksDictionary<T extends BaseZodDictionary> = {
8
+ [K in keyof T]: {
9
+ schema: T[K];
10
+ Component: (props: z.infer<T[K]>) => JSX.Element;
11
+ };
12
+ };
13
+ type BlockConfiguration<T extends BaseZodDictionary> = {
14
+ [TType in keyof T]: {
15
+ type: TType;
16
+ data: z.infer<T[TType]>;
17
+ };
18
+ }[keyof T];
19
+
20
+ /**
21
+ * @param blocks Main DocumentBlocksDictionary
22
+ * @returns React component that can render a BlockConfiguration that is compatible with blocks
23
+ */
24
+ declare function buildBlockComponent<T extends BaseZodDictionary>(blocks: DocumentBlocksDictionary<T>): ({ type, data }: BlockConfiguration<T>) => React.JSX.Element;
25
+
26
+ /**
27
+ *
28
+ * @param blocks Main DocumentBlocksDictionary
29
+ * @returns zod schema that can parse arbitary objects into a single BlockConfiguration
30
+ */
31
+ declare function buildBlockConfigurationSchema<T extends BaseZodDictionary>(blocks: DocumentBlocksDictionary<T>): z.ZodEffects<z.ZodDiscriminatedUnion<"type", any>, BlockConfiguration<T>, any>;
32
+
33
+ /**
34
+ * Identity function to type a DocumentBlocksDictionary
35
+ * @param blocks Main DocumentBlocksDictionary
36
+ * @returns typed DocumentBlocksDictionary
37
+ */
38
+ declare function buildBlockConfigurationDictionary<T extends BaseZodDictionary>(blocks: DocumentBlocksDictionary<T>): DocumentBlocksDictionary<T>;
39
+
40
+ export { type BlockConfiguration, type DocumentBlocksDictionary, buildBlockComponent, buildBlockConfigurationDictionary, buildBlockConfigurationSchema };
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { z } from 'zod';
3
+
4
+ type BaseZodDictionary = {
5
+ [name: string]: z.AnyZodObject;
6
+ };
7
+ type DocumentBlocksDictionary<T extends BaseZodDictionary> = {
8
+ [K in keyof T]: {
9
+ schema: T[K];
10
+ Component: (props: z.infer<T[K]>) => JSX.Element;
11
+ };
12
+ };
13
+ type BlockConfiguration<T extends BaseZodDictionary> = {
14
+ [TType in keyof T]: {
15
+ type: TType;
16
+ data: z.infer<T[TType]>;
17
+ };
18
+ }[keyof T];
19
+
20
+ /**
21
+ * @param blocks Main DocumentBlocksDictionary
22
+ * @returns React component that can render a BlockConfiguration that is compatible with blocks
23
+ */
24
+ declare function buildBlockComponent<T extends BaseZodDictionary>(blocks: DocumentBlocksDictionary<T>): ({ type, data }: BlockConfiguration<T>) => React.JSX.Element;
25
+
26
+ /**
27
+ *
28
+ * @param blocks Main DocumentBlocksDictionary
29
+ * @returns zod schema that can parse arbitary objects into a single BlockConfiguration
30
+ */
31
+ declare function buildBlockConfigurationSchema<T extends BaseZodDictionary>(blocks: DocumentBlocksDictionary<T>): z.ZodEffects<z.ZodDiscriminatedUnion<"type", any>, BlockConfiguration<T>, any>;
32
+
33
+ /**
34
+ * Identity function to type a DocumentBlocksDictionary
35
+ * @param blocks Main DocumentBlocksDictionary
36
+ * @returns typed DocumentBlocksDictionary
37
+ */
38
+ declare function buildBlockConfigurationDictionary<T extends BaseZodDictionary>(blocks: DocumentBlocksDictionary<T>): DocumentBlocksDictionary<T>;
39
+
40
+ export { type BlockConfiguration, type DocumentBlocksDictionary, buildBlockComponent, buildBlockConfigurationDictionary, buildBlockConfigurationSchema };
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
+
44
+ // src/index.ts
45
+ var index_exports = {};
46
+ __export(index_exports, {
47
+ buildBlockComponent: () => buildBlockComponent,
48
+ buildBlockConfigurationDictionary: () => buildBlockConfigurationDictionary,
49
+ buildBlockConfigurationSchema: () => buildBlockConfigurationSchema
50
+ });
51
+ module.exports = __toCommonJS(index_exports);
52
+
53
+ // src/builders/buildBlockComponent.tsx
54
+ var import_react = __toESM(require("react"));
55
+ function buildBlockComponent(blocks) {
56
+ return function BlockComponent({ type, data }) {
57
+ const Component = blocks[type].Component;
58
+ return /* @__PURE__ */ import_react.default.createElement(Component, __spreadValues({}, data));
59
+ };
60
+ }
61
+
62
+ // src/builders/buildBlockConfigurationSchema.ts
63
+ var import_zod = require("zod");
64
+ function buildBlockConfigurationSchema(blocks) {
65
+ const blockObjects = Object.keys(blocks).map(
66
+ (type) => import_zod.z.object({
67
+ type: import_zod.z.literal(type),
68
+ data: blocks[type].schema
69
+ })
70
+ );
71
+ return import_zod.z.discriminatedUnion("type", blockObjects).transform((v) => v);
72
+ }
73
+
74
+ // src/builders/buildBlockConfigurationDictionary.ts
75
+ function buildBlockConfigurationDictionary(blocks) {
76
+ return blocks;
77
+ }
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ buildBlockComponent,
81
+ buildBlockConfigurationDictionary,
82
+ buildBlockConfigurationSchema
83
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/builders/buildBlockComponent.tsx
19
+ import React from "react";
20
+ function buildBlockComponent(blocks) {
21
+ return function BlockComponent({ type, data }) {
22
+ const Component = blocks[type].Component;
23
+ return /* @__PURE__ */ React.createElement(Component, __spreadValues({}, data));
24
+ };
25
+ }
26
+
27
+ // src/builders/buildBlockConfigurationSchema.ts
28
+ import { z } from "zod";
29
+ function buildBlockConfigurationSchema(blocks) {
30
+ const blockObjects = Object.keys(blocks).map(
31
+ (type) => z.object({
32
+ type: z.literal(type),
33
+ data: blocks[type].schema
34
+ })
35
+ );
36
+ return z.discriminatedUnion("type", blockObjects).transform((v) => v);
37
+ }
38
+
39
+ // src/builders/buildBlockConfigurationDictionary.ts
40
+ function buildBlockConfigurationDictionary(blocks) {
41
+ return blocks;
42
+ }
43
+ export {
44
+ buildBlockComponent,
45
+ buildBlockConfigurationDictionary,
46
+ buildBlockConfigurationSchema
47
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csg-org/document-core",
3
- "version": "0.0.7-alpha.3",
3
+ "version": "0.0.9",
4
4
  "description": "Tools to render waypoint-style documents (core package)",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",