@01.software/sdk 0.2.9-dev.260305.4f1735b → 0.2.9-dev.260306.4e16dd4

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.
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
20
32
  var __async = (__this, __arguments, generator) => {
21
33
  return new Promise((resolve, reject) => {
22
34
  var fulfilled = (value) => {
@@ -39,34 +51,205 @@ var __async = (__this, __arguments, generator) => {
39
51
  };
40
52
 
41
53
  // src/components/RichTextContent/index.tsx
42
- import React from "react";
54
+ import React2 from "react";
43
55
  import {
44
56
  defaultJSXConverters,
45
57
  LinkJSXConverter,
46
- RichText
58
+ RichText,
59
+ TextJSXConverter
47
60
  } from "@payloadcms/richtext-lexical/react";
61
+
62
+ // src/components/RichTextContent/styled.tsx
63
+ import React from "react";
64
+ function createComponentConverters(components, internalDocToHref) {
65
+ const converters = {};
66
+ if (components.Heading) {
67
+ const Heading = components.Heading;
68
+ converters.heading = ({ node, nodesToJSX }) => /* @__PURE__ */ React.createElement(Heading, { tag: node.tag, node }, nodesToJSX({ nodes: node.children }));
69
+ }
70
+ if (components.Paragraph) {
71
+ const Paragraph = components.Paragraph;
72
+ converters.paragraph = ({ node, nodesToJSX }) => {
73
+ const children = nodesToJSX({ nodes: node.children });
74
+ return /* @__PURE__ */ React.createElement(Paragraph, { isEmpty: !(children == null ? void 0 : children.length), node }, (children == null ? void 0 : children.length) ? children : /* @__PURE__ */ React.createElement("br", null));
75
+ };
76
+ }
77
+ if (components.Blockquote) {
78
+ const Blockquote = components.Blockquote;
79
+ converters.quote = ({ node, nodesToJSX }) => /* @__PURE__ */ React.createElement(Blockquote, { node }, nodesToJSX({ nodes: node.children }));
80
+ }
81
+ if (components.List) {
82
+ const List = components.List;
83
+ converters.list = ({ node, nodesToJSX }) => /* @__PURE__ */ React.createElement(List, { tag: node.tag, listType: node.listType, node }, nodesToJSX({ nodes: node.children }));
84
+ }
85
+ if (components.ListItem) {
86
+ const ListItem = components.ListItem;
87
+ converters.listitem = ({ node, nodesToJSX }) => {
88
+ const hasSubLists = node.children.some(
89
+ (child) => child.type === "list"
90
+ );
91
+ return /* @__PURE__ */ React.createElement(
92
+ ListItem,
93
+ {
94
+ hasSubLists,
95
+ checked: node.checked,
96
+ value: node.value,
97
+ node
98
+ },
99
+ nodesToJSX({ nodes: node.children })
100
+ );
101
+ };
102
+ }
103
+ if (components.Link) {
104
+ const Link = components.Link;
105
+ const resolveHref = (node) => {
106
+ var _a;
107
+ if (node.fields.linkType === "internal") {
108
+ return internalDocToHref ? internalDocToHref({ linkNode: node }) : "#";
109
+ }
110
+ return (_a = node.fields.url) != null ? _a : "";
111
+ };
112
+ converters.link = ({ node, nodesToJSX }) => /* @__PURE__ */ React.createElement(
113
+ Link,
114
+ {
115
+ href: resolveHref(node),
116
+ rel: node.fields.newTab ? "noopener noreferrer" : void 0,
117
+ target: node.fields.newTab ? "_blank" : void 0,
118
+ node
119
+ },
120
+ nodesToJSX({ nodes: node.children })
121
+ );
122
+ converters.autolink = ({ node, nodesToJSX }) => {
123
+ var _a;
124
+ return /* @__PURE__ */ React.createElement(
125
+ Link,
126
+ {
127
+ href: (_a = node.fields.url) != null ? _a : "",
128
+ rel: node.fields.newTab ? "noopener noreferrer" : void 0,
129
+ target: node.fields.newTab ? "_blank" : void 0,
130
+ node
131
+ },
132
+ nodesToJSX({ nodes: node.children })
133
+ );
134
+ };
135
+ }
136
+ if (components.HorizontalRule) {
137
+ const HorizontalRule = components.HorizontalRule;
138
+ converters.horizontalrule = /* @__PURE__ */ React.createElement(HorizontalRule, null);
139
+ }
140
+ if (components.Upload) {
141
+ const Upload = components.Upload;
142
+ converters.upload = ({ node }) => {
143
+ var _a;
144
+ const uploadNode = node;
145
+ if (typeof uploadNode.value !== "object") return null;
146
+ const doc = uploadNode.value;
147
+ return /* @__PURE__ */ React.createElement(
148
+ Upload,
149
+ {
150
+ src: doc.url,
151
+ alt: ((_a = uploadNode.fields) == null ? void 0 : _a.alt) || (doc == null ? void 0 : doc.alt) || "",
152
+ width: doc.width,
153
+ height: doc.height,
154
+ mimeType: doc.mimeType,
155
+ filename: doc.filename,
156
+ sizes: doc.sizes,
157
+ node
158
+ }
159
+ );
160
+ };
161
+ }
162
+ if (components.Table) {
163
+ const Table = components.Table;
164
+ converters.table = ({ node, nodesToJSX }) => /* @__PURE__ */ React.createElement(Table, { node }, nodesToJSX({ nodes: node.children }));
165
+ }
166
+ if (components.TableRow) {
167
+ const TableRow = components.TableRow;
168
+ converters.tablerow = ({ node, nodesToJSX }) => /* @__PURE__ */ React.createElement(TableRow, { node }, nodesToJSX({ nodes: node.children }));
169
+ }
170
+ if (components.TableCell) {
171
+ const TableCell = components.TableCell;
172
+ converters.tablecell = ({ node, nodesToJSX }) => /* @__PURE__ */ React.createElement(
173
+ TableCell,
174
+ {
175
+ tag: node.headerState > 0 ? "th" : "td",
176
+ colSpan: node.colSpan > 1 ? node.colSpan : void 0,
177
+ rowSpan: node.rowSpan > 1 ? node.rowSpan : void 0,
178
+ backgroundColor: node.backgroundColor || void 0,
179
+ node
180
+ },
181
+ nodesToJSX({ nodes: node.children })
182
+ );
183
+ }
184
+ return converters;
185
+ }
186
+ function StyledRichTextContent(_a) {
187
+ var _b = _a, {
188
+ components = {},
189
+ internalDocToHref,
190
+ blocks,
191
+ textState
192
+ } = _b, props = __objRest(_b, [
193
+ "components",
194
+ "internalDocToHref",
195
+ "blocks",
196
+ "textState"
197
+ ]);
198
+ const converters = createComponentConverters(components, internalDocToHref);
199
+ return /* @__PURE__ */ React.createElement(
200
+ RichTextContent,
201
+ __spreadProps(__spreadValues({}, props), {
202
+ internalDocToHref,
203
+ converters,
204
+ blocks,
205
+ textState
206
+ })
207
+ );
208
+ }
209
+
210
+ // src/components/RichTextContent/index.tsx
211
+ function hyphenToCamel(str) {
212
+ return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
213
+ }
214
+ function createTextStateConverter(state) {
215
+ const defaultTextConverter = TextJSXConverter.text;
216
+ return (_a) => {
217
+ var _b = _a, { node } = _b, rest = __objRest(_b, ["node"]);
218
+ var _a2, _b2;
219
+ const base = defaultTextConverter(__spreadValues({ node }, rest));
220
+ const nodeState = node.$;
221
+ if (!nodeState || typeof nodeState !== "object") return base;
222
+ const style = {};
223
+ for (const stateKey in nodeState) {
224
+ const stateValue = nodeState[stateKey];
225
+ if (!stateValue) continue;
226
+ const css = (_b2 = (_a2 = state[stateKey]) == null ? void 0 : _a2[stateValue]) == null ? void 0 : _b2.css;
227
+ if (css) {
228
+ for (const prop in css) {
229
+ const val = css[prop];
230
+ if (val) style[hyphenToCamel(prop)] = val;
231
+ }
232
+ }
233
+ }
234
+ if (Object.keys(style).length === 0) return base;
235
+ return /* @__PURE__ */ React2.createElement("span", { style }, base);
236
+ };
237
+ }
48
238
  function RichTextContent({
49
239
  data,
50
240
  className,
51
241
  internalDocToHref,
52
- blocks
242
+ converters,
243
+ blocks,
244
+ disableDefaultConverters,
245
+ textState
53
246
  }) {
54
- return /* @__PURE__ */ React.createElement(
55
- RichText,
56
- {
57
- data,
58
- className,
59
- converters: __spreadProps(__spreadValues(__spreadValues({}, defaultJSXConverters), LinkJSXConverter({
60
- internalDocToHref
61
- })), {
62
- blocks: blocks ? blocks : void 0
63
- })
64
- }
65
- );
247
+ const baseConverters = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, disableDefaultConverters ? {} : defaultJSXConverters), LinkJSXConverter({ internalDocToHref })), textState ? { text: createTextStateConverter(textState) } : {}), converters), blocks ? { blocks } : {});
248
+ return /* @__PURE__ */ React2.createElement(RichText, { data, className, converters: baseConverters });
66
249
  }
67
250
 
68
251
  // src/components/FormRenderer/index.tsx
69
- import React2, { useState, useCallback, useEffect, useRef } from "react";
252
+ import React3, { useState, useCallback, useEffect, useRef } from "react";
70
253
 
71
254
  // src/components/FormRenderer/countries.ts
72
255
  var COUNTRIES = [
@@ -437,14 +620,14 @@ function FormRenderer({
437
620
  value: (_a2 = values[field.name]) != null ? _a2 : "",
438
621
  onChange: (v) => handleChange(field.name, v)
439
622
  };
440
- const el = /* @__PURE__ */ React2.createElement(
623
+ const el = /* @__PURE__ */ React3.createElement(
441
624
  "div",
442
625
  {
443
626
  key: (_b = field.id) != null ? _b : field.name,
444
627
  className: fieldClassName,
445
628
  style
446
629
  },
447
- field.label && /* @__PURE__ */ React2.createElement("label", { htmlFor: field.name }, field.label),
630
+ field.label && /* @__PURE__ */ React3.createElement("label", { htmlFor: field.name }, field.label),
448
631
  input
449
632
  );
450
633
  return renderField ? renderField(field, context, el) : el;
@@ -454,7 +637,7 @@ function FormRenderer({
454
637
  return wrapField(
455
638
  field,
456
639
  style,
457
- /* @__PURE__ */ React2.createElement(
640
+ /* @__PURE__ */ React3.createElement(
458
641
  "select",
459
642
  {
460
643
  id: field.name,
@@ -463,8 +646,8 @@ function FormRenderer({
463
646
  required: (_b = field.required) != null ? _b : false,
464
647
  onChange: (e) => handleChange(field.name, e.target.value)
465
648
  },
466
- /* @__PURE__ */ React2.createElement("option", { value: "" }, placeholder || "Select\u2026"),
467
- options.map((opt) => /* @__PURE__ */ React2.createElement("option", { key: opt.value, value: opt.value }, opt.label))
649
+ /* @__PURE__ */ React3.createElement("option", { value: "" }, placeholder || "Select\u2026"),
650
+ options.map((opt) => /* @__PURE__ */ React3.createElement("option", { key: opt.value, value: opt.value }, opt.label))
468
651
  )
469
652
  );
470
653
  };
@@ -476,7 +659,7 @@ function FormRenderer({
476
659
  return wrapField(
477
660
  field,
478
661
  style,
479
- /* @__PURE__ */ React2.createElement(
662
+ /* @__PURE__ */ React3.createElement(
480
663
  "input",
481
664
  {
482
665
  type: "text",
@@ -493,7 +676,7 @@ function FormRenderer({
493
676
  return wrapField(
494
677
  field,
495
678
  style,
496
- /* @__PURE__ */ React2.createElement(
679
+ /* @__PURE__ */ React3.createElement(
497
680
  "input",
498
681
  {
499
682
  type: "email",
@@ -509,7 +692,7 @@ function FormRenderer({
509
692
  return wrapField(
510
693
  field,
511
694
  style,
512
- /* @__PURE__ */ React2.createElement(
695
+ /* @__PURE__ */ React3.createElement(
513
696
  "input",
514
697
  {
515
698
  type: "number",
@@ -530,7 +713,7 @@ function FormRenderer({
530
713
  return wrapField(
531
714
  field,
532
715
  style,
533
- /* @__PURE__ */ React2.createElement(
716
+ /* @__PURE__ */ React3.createElement(
534
717
  "textarea",
535
718
  {
536
719
  id: field.name,
@@ -546,14 +729,14 @@ function FormRenderer({
546
729
  value: (_j = values[field.name]) != null ? _j : false,
547
730
  onChange: (v) => handleChange(field.name, v)
548
731
  };
549
- const el = /* @__PURE__ */ React2.createElement(
732
+ const el = /* @__PURE__ */ React3.createElement(
550
733
  "div",
551
734
  {
552
735
  key: (_k = field.id) != null ? _k : field.name,
553
736
  className: fieldClassName,
554
737
  style
555
738
  },
556
- /* @__PURE__ */ React2.createElement("label", { htmlFor: field.name }, /* @__PURE__ */ React2.createElement(
739
+ /* @__PURE__ */ React3.createElement("label", { htmlFor: field.name }, /* @__PURE__ */ React3.createElement(
557
740
  "input",
558
741
  {
559
742
  type: "checkbox",
@@ -563,7 +746,7 @@ function FormRenderer({
563
746
  required: (_l = field.required) != null ? _l : false,
564
747
  onChange: (e) => handleChange(field.name, e.target.checked)
565
748
  }
566
- ), field.label && /* @__PURE__ */ React2.createElement("span", null, field.label))
749
+ ), field.label && /* @__PURE__ */ React3.createElement("span", null, field.label))
567
750
  );
568
751
  return renderField ? renderField(field, context, el) : el;
569
752
  }
@@ -580,7 +763,7 @@ function FormRenderer({
580
763
  return renderSelectField(field, style, US_STATES);
581
764
  case "message":
582
765
  if (renderMessage && field.message) {
583
- return /* @__PURE__ */ React2.createElement(React2.Fragment, { key: (_p = (_o = field.id) != null ? _o : field.blockName) != null ? _p : "message" }, renderMessage(field.message));
766
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, { key: (_p = (_o = field.id) != null ? _o : field.blockName) != null ? _p : "message" }, renderMessage(field.message));
584
767
  }
585
768
  return null;
586
769
  default:
@@ -588,7 +771,7 @@ function FormRenderer({
588
771
  }
589
772
  };
590
773
  const buttonLabel = form.submitButtonLabel || "Submit";
591
- return /* @__PURE__ */ React2.createElement("form", { onSubmit: handleSubmit, className }, (_a = form.fields) == null ? void 0 : _a.map((field) => renderFieldElement(field)), renderButton ? renderButton({ isSubmitting, label: buttonLabel }) : /* @__PURE__ */ React2.createElement(
774
+ return /* @__PURE__ */ React3.createElement("form", { onSubmit: handleSubmit, className }, (_a = form.fields) == null ? void 0 : _a.map((field) => renderFieldElement(field)), renderButton ? renderButton({ isSubmitting, label: buttonLabel }) : /* @__PURE__ */ React3.createElement(
592
775
  "button",
593
776
  {
594
777
  type: "submit",
@@ -600,7 +783,7 @@ function FormRenderer({
600
783
  }
601
784
 
602
785
  // src/components/Image/index.tsx
603
- import React3, { useCallback as useCallback2, useRef as useRef2, useState as useState2 } from "react";
786
+ import React4, { useCallback as useCallback2, useRef as useRef2, useState as useState2 } from "react";
604
787
 
605
788
  // src/utils/image.ts
606
789
  var IMAGE_SIZES = [384, 768, 1536];
@@ -715,7 +898,7 @@ function Image({
715
898
  opacity: loaded ? 1 : 0,
716
899
  transition: "opacity 0.3s ease"
717
900
  }), imgStyle);
718
- return /* @__PURE__ */ React3.createElement("div", { className, style: containerStyle }, hasLqip && /* @__PURE__ */ React3.createElement(
901
+ return /* @__PURE__ */ React4.createElement("div", { className, style: containerStyle }, hasLqip && /* @__PURE__ */ React4.createElement(
719
902
  "img",
720
903
  {
721
904
  "aria-hidden": true,
@@ -728,7 +911,7 @@ function Image({
728
911
  transform: "scale(1.1)"
729
912
  })
730
913
  }
731
- ), placeholderColor && /* @__PURE__ */ React3.createElement(
914
+ ), placeholderColor && /* @__PURE__ */ React4.createElement(
732
915
  "div",
733
916
  {
734
917
  "aria-hidden": true,
@@ -736,7 +919,7 @@ function Image({
736
919
  backgroundColor: placeholderColor
737
920
  })
738
921
  }
739
- ), /* @__PURE__ */ React3.createElement(
922
+ ), /* @__PURE__ */ React4.createElement(
740
923
  "img",
741
924
  {
742
925
  ref: imgRef,
@@ -754,10 +937,139 @@ function Image({
754
937
  }
755
938
  ));
756
939
  }
940
+
941
+ // src/components/CodeBlock/index.tsx
942
+ import React5, { useEffect as useEffect2, useState as useState3 } from "react";
943
+
944
+ // src/components/CodeBlock/highlight.ts
945
+ import { Fragment } from "react";
946
+ import { jsx, jsxs } from "react/jsx-runtime";
947
+ import { toJsxRuntime } from "hast-util-to-jsx-runtime";
948
+ import { codeToHast } from "shiki";
949
+ var LANGUAGE_ALIASES = {
950
+ js: "javascript",
951
+ ts: "typescript",
952
+ sh: "bash",
953
+ shell: "bash",
954
+ yml: "yaml",
955
+ py: "python",
956
+ rb: "ruby",
957
+ plaintext: "text"
958
+ };
959
+ function normalizeLanguage(lang) {
960
+ return LANGUAGE_ALIASES[lang] || lang;
961
+ }
962
+ function highlight(code, lang, theme = "github-dark") {
963
+ return __async(this, null, function* () {
964
+ const normalized = normalizeLanguage(lang);
965
+ try {
966
+ const hast = yield codeToHast(code, {
967
+ lang: normalized,
968
+ theme
969
+ });
970
+ return toJsxRuntime(hast, { Fragment, jsx, jsxs });
971
+ } catch (e) {
972
+ const hast = yield codeToHast(code, { lang: "text", theme });
973
+ return toJsxRuntime(hast, { Fragment, jsx, jsxs });
974
+ }
975
+ });
976
+ }
977
+
978
+ // src/components/CodeBlock/index.tsx
979
+ function CodeBlock({
980
+ code,
981
+ language = "typescript",
982
+ theme = "github-dark",
983
+ className,
984
+ initial,
985
+ showLineNumbers = false,
986
+ showCopyButton = true
987
+ }) {
988
+ const [nodes, setNodes] = useState3(initial);
989
+ const [copied, setCopied] = useState3(false);
990
+ useEffect2(() => {
991
+ let cancelled = false;
992
+ void highlight(code, language, theme).then((el) => {
993
+ if (!cancelled) setNodes(el);
994
+ });
995
+ return () => {
996
+ cancelled = true;
997
+ };
998
+ }, [code, language, theme]);
999
+ const handleCopy = () => {
1000
+ void navigator.clipboard.writeText(code).then(() => {
1001
+ setCopied(true);
1002
+ setTimeout(() => setCopied(false), 2e3);
1003
+ }, () => {
1004
+ });
1005
+ };
1006
+ return /* @__PURE__ */ React5.createElement("div", { className, style: { position: "relative" } }, showCopyButton && /* @__PURE__ */ React5.createElement(
1007
+ "button",
1008
+ {
1009
+ type: "button",
1010
+ onClick: handleCopy,
1011
+ "aria-label": "Copy code",
1012
+ style: {
1013
+ position: "absolute",
1014
+ top: 8,
1015
+ right: 8,
1016
+ zIndex: 1,
1017
+ padding: "4px 8px",
1018
+ fontSize: 12,
1019
+ lineHeight: 1,
1020
+ border: "1px solid rgba(255,255,255,0.2)",
1021
+ borderRadius: 4,
1022
+ background: "rgba(0,0,0,0.3)",
1023
+ color: "#ccc",
1024
+ cursor: "pointer",
1025
+ opacity: 0.7,
1026
+ transition: "opacity 0.15s"
1027
+ },
1028
+ onMouseEnter: (e) => {
1029
+ e.currentTarget.style.opacity = "1";
1030
+ },
1031
+ onMouseLeave: (e) => {
1032
+ e.currentTarget.style.opacity = "0.7";
1033
+ }
1034
+ },
1035
+ copied ? "Copied!" : "Copy"
1036
+ ), showLineNumbers && nodes ? /* @__PURE__ */ React5.createElement("div", { style: { display: "flex" } }, /* @__PURE__ */ React5.createElement(
1037
+ "div",
1038
+ {
1039
+ "aria-hidden": true,
1040
+ style: {
1041
+ padding: "1em 0.5em 1em 1em",
1042
+ textAlign: "right",
1043
+ userSelect: "none",
1044
+ color: "rgba(255,255,255,0.3)",
1045
+ fontFamily: "monospace",
1046
+ fontSize: 13,
1047
+ lineHeight: 1.5
1048
+ }
1049
+ },
1050
+ code.split("\n").map((_, i) => /* @__PURE__ */ React5.createElement("div", { key: i }, i + 1))
1051
+ ), /* @__PURE__ */ React5.createElement("div", { style: { flex: 1, overflow: "auto" } }, nodes)) : nodes != null ? nodes : /* @__PURE__ */ React5.createElement(
1052
+ "pre",
1053
+ {
1054
+ style: {
1055
+ margin: 0,
1056
+ padding: "1em",
1057
+ overflow: "auto",
1058
+ fontFamily: "monospace",
1059
+ fontSize: 13,
1060
+ lineHeight: 1.5
1061
+ }
1062
+ },
1063
+ /* @__PURE__ */ React5.createElement("code", null, code)
1064
+ ));
1065
+ }
757
1066
  export {
1067
+ CodeBlock,
758
1068
  FormRenderer,
759
1069
  Image,
760
1070
  RichTextContent,
1071
+ StyledRichTextContent,
1072
+ highlight,
761
1073
  toSubmissionData
762
1074
  };
763
1075
  //# sourceMappingURL=components.js.map