@sdboyer/thema-ui 0.0.0-bootstrap.0 → 0.1.0

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.
Files changed (225) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -1
  3. package/dist/Diagnostics.d.ts +8 -0
  4. package/dist/Diagnostics.js +14 -0
  5. package/dist/Editor.d.ts +12 -0
  6. package/dist/Editor.js +95 -0
  7. package/dist/OpBar.d.ts +14 -0
  8. package/dist/OpBar.js +15 -0
  9. package/dist/Output.d.ts +20 -0
  10. package/dist/Output.js +56 -0
  11. package/dist/Tabs.d.ts +15 -0
  12. package/dist/Tabs.js +23 -0
  13. package/dist/cue-lang.d.ts +8 -0
  14. package/dist/cue-lang.js +82 -0
  15. package/dist/docs.d.ts +64 -0
  16. package/dist/docs.js +42 -0
  17. package/dist/index.d.ts +12 -0
  18. package/dist/index.js +18 -0
  19. package/dist/markers.d.ts +11 -0
  20. package/dist/markers.js +45 -0
  21. package/dist/ops.d.ts +13 -0
  22. package/dist/ops.js +22 -0
  23. package/dist/positions.d.ts +7 -0
  24. package/dist/positions.js +40 -0
  25. package/dist/theme.d.ts +16 -0
  26. package/dist/theme.js +55 -0
  27. package/dist/types.d.ts +580 -0
  28. package/dist/types.js +85 -0
  29. package/errors/E0101.md +43 -0
  30. package/errors/E0102.md +34 -0
  31. package/errors/E0103.md +41 -0
  32. package/errors/E0104.md +5 -0
  33. package/errors/E0105.md +62 -0
  34. package/errors/E0106.md +46 -0
  35. package/errors/E0107.md +48 -0
  36. package/errors/E0108.md +45 -0
  37. package/errors/E0109.md +37 -0
  38. package/errors/E0110.md +17 -0
  39. package/errors/E0111.md +55 -0
  40. package/errors/E0112.md +40 -0
  41. package/errors/E0120.md +34 -0
  42. package/errors/E0121.md +34 -0
  43. package/errors/E0122.md +26 -0
  44. package/errors/E0123.md +37 -0
  45. package/errors/E0124.md +36 -0
  46. package/errors/E0125.md +43 -0
  47. package/errors/E0126.md +38 -0
  48. package/errors/E0128.md +34 -0
  49. package/errors/E0129.md +42 -0
  50. package/errors/E0130.md +43 -0
  51. package/errors/E0131.md +42 -0
  52. package/errors/E0132.md +40 -0
  53. package/errors/E0133.md +46 -0
  54. package/errors/E0134.md +36 -0
  55. package/errors/E0135.md +109 -0
  56. package/errors/E0137.md +37 -0
  57. package/errors/E0140.md +46 -0
  58. package/errors/E0141.md +35 -0
  59. package/errors/E0142.md +38 -0
  60. package/errors/E0143.md +62 -0
  61. package/errors/E0144.md +49 -0
  62. package/errors/E0145.md +48 -0
  63. package/errors/E0146.md +38 -0
  64. package/errors/E0147.md +57 -0
  65. package/errors/E0148.md +42 -0
  66. package/errors/E0149.md +27 -0
  67. package/errors/E0150.md +77 -0
  68. package/errors/E0151.md +47 -0
  69. package/errors/E0152.md +35 -0
  70. package/errors/E0201.md +35 -0
  71. package/errors/E0202.md +42 -0
  72. package/errors/E0203.md +37 -0
  73. package/errors/E0204.md +46 -0
  74. package/errors/E0205.md +47 -0
  75. package/errors/E0206.md +47 -0
  76. package/errors/E0208.md +59 -0
  77. package/errors/E0210.md +44 -0
  78. package/errors/E0211.md +43 -0
  79. package/errors/E0212.md +41 -0
  80. package/errors/E0213.md +42 -0
  81. package/errors/E0214.md +42 -0
  82. package/errors/E0215.md +44 -0
  83. package/errors/E0216.md +41 -0
  84. package/errors/E0217.md +43 -0
  85. package/errors/E0218.md +44 -0
  86. package/errors/E0230.md +46 -0
  87. package/errors/E0232.md +42 -0
  88. package/errors/E0233.md +42 -0
  89. package/errors/E0234.md +43 -0
  90. package/errors/E0240.md +31 -0
  91. package/errors/E0242.md +5 -0
  92. package/errors/E0243.md +5 -0
  93. package/errors/E0250.md +39 -0
  94. package/errors/E0251.md +83 -0
  95. package/errors/E0252.md +42 -0
  96. package/errors/E0253.md +142 -0
  97. package/errors/E0254.md +38 -0
  98. package/errors/E0301.md +43 -0
  99. package/errors/E0302.md +58 -0
  100. package/errors/E0303.md +57 -0
  101. package/errors/E0304.md +9 -0
  102. package/errors/E0305.md +55 -0
  103. package/errors/E0307.md +9 -0
  104. package/errors/E0308.md +9 -0
  105. package/errors/E0310.md +46 -0
  106. package/errors/E0311.md +46 -0
  107. package/errors/E0330.md +67 -0
  108. package/errors/E0331.md +64 -0
  109. package/errors/E0332.md +52 -0
  110. package/errors/E0333.md +61 -0
  111. package/errors/E0334.md +61 -0
  112. package/errors/E0335.md +57 -0
  113. package/errors/E0336.md +50 -0
  114. package/errors/E0337.md +54 -0
  115. package/errors/E0338.md +62 -0
  116. package/errors/E0340.md +57 -0
  117. package/errors/E0341.md +51 -0
  118. package/errors/E0342.md +53 -0
  119. package/errors/E0343.md +56 -0
  120. package/errors/E0344.md +58 -0
  121. package/errors/E0345.md +51 -0
  122. package/errors/E0346.md +45 -0
  123. package/errors/E0347.md +53 -0
  124. package/errors/E0348.md +50 -0
  125. package/errors/E0349.md +52 -0
  126. package/errors/E0350.md +54 -0
  127. package/errors/E0351.md +54 -0
  128. package/errors/E0352.md +60 -0
  129. package/errors/E0353.md +53 -0
  130. package/errors/E0354.md +43 -0
  131. package/errors/E0355.md +55 -0
  132. package/errors/E0356.md +65 -0
  133. package/errors/E0357.md +68 -0
  134. package/errors/E0358.md +50 -0
  135. package/errors/E0359.md +53 -0
  136. package/errors/E0360.md +59 -0
  137. package/errors/E0361.md +59 -0
  138. package/errors/E0362.md +56 -0
  139. package/errors/E0364.md +58 -0
  140. package/errors/E0365.md +58 -0
  141. package/errors/E0366.md +56 -0
  142. package/errors/E0367.md +57 -0
  143. package/errors/E0368.md +58 -0
  144. package/errors/E0369.md +60 -0
  145. package/errors/E0370.md +59 -0
  146. package/errors/E0371.md +59 -0
  147. package/errors/E0372.md +57 -0
  148. package/errors/E0380.md +71 -0
  149. package/errors/E0381.md +61 -0
  150. package/errors/E0382.md +64 -0
  151. package/errors/E0383.md +61 -0
  152. package/errors/E0384.md +63 -0
  153. package/errors/E0385.md +61 -0
  154. package/errors/E0386.md +59 -0
  155. package/errors/E0387.md +59 -0
  156. package/errors/E0388.md +60 -0
  157. package/errors/E0389.md +59 -0
  158. package/errors/E0390.md +59 -0
  159. package/errors/E0401.md +56 -0
  160. package/errors/E0402.md +51 -0
  161. package/errors/E0403.md +51 -0
  162. package/errors/E0404.md +57 -0
  163. package/errors/E0405.md +56 -0
  164. package/errors/E0406.md +53 -0
  165. package/errors/E0407.md +54 -0
  166. package/errors/E0410.md +56 -0
  167. package/errors/E0411.md +59 -0
  168. package/errors/E0412.md +59 -0
  169. package/errors/E0413.md +74 -0
  170. package/errors/E0414.md +53 -0
  171. package/errors/E0415.md +72 -0
  172. package/errors/E0416.md +67 -0
  173. package/errors/E0418.md +59 -0
  174. package/errors/E0420.md +71 -0
  175. package/errors/E0421.md +82 -0
  176. package/errors/E0422.md +82 -0
  177. package/errors/E0423.md +83 -0
  178. package/errors/E0501.md +51 -0
  179. package/errors/E0502.md +50 -0
  180. package/errors/E0503.md +52 -0
  181. package/errors/E0504.md +64 -0
  182. package/errors/E0505.md +51 -0
  183. package/errors/E0506.md +48 -0
  184. package/errors/E0507.md +41 -0
  185. package/errors/E0508.md +39 -0
  186. package/errors/E0601.md +22 -0
  187. package/errors/E0602.md +28 -0
  188. package/errors/E0603.md +65 -0
  189. package/errors/E0604.md +37 -0
  190. package/errors/E0605.md +36 -0
  191. package/errors/E0606.md +44 -0
  192. package/errors/E0607.md +57 -0
  193. package/errors/E0608.md +37 -0
  194. package/errors/E0609.md +33 -0
  195. package/errors/E0611.md +37 -0
  196. package/errors/E0612.md +34 -0
  197. package/errors/E0613.md +30 -0
  198. package/errors/E0614.md +36 -0
  199. package/errors/E0616.md +33 -0
  200. package/errors/E0617.md +15 -0
  201. package/errors/E0618.md +16 -0
  202. package/errors/E0620.md +37 -0
  203. package/errors/E0621.md +45 -0
  204. package/errors/E0622.md +34 -0
  205. package/errors/E0623.md +33 -0
  206. package/errors/E0624.md +34 -0
  207. package/errors/E0625.md +28 -0
  208. package/errors/E0626.md +54 -0
  209. package/errors/E0627.md +27 -0
  210. package/errors/E0628.md +63 -0
  211. package/errors/E0701.md +25 -0
  212. package/errors/E0801.md +23 -0
  213. package/errors/E0802.md +22 -0
  214. package/errors/E0803.md +22 -0
  215. package/errors/E0804.md +25 -0
  216. package/errors/E0805.md +26 -0
  217. package/errors/E0901.md +27 -0
  218. package/errors/E0902.md +40 -0
  219. package/errors/E0903.md +23 -0
  220. package/errors/E1001.md +53 -0
  221. package/errors/E1002.md +43 -0
  222. package/errors/E1003.md +40 -0
  223. package/errors/E1004.md +44 -0
  224. package/errors/README.md +215 -0
  225. package/package.json +29 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
1
  # @sdboyer/thema-ui
2
2
 
3
- A placeholder reserving the name. thema publishes it from https://github.com/sdboyer/thema, starting at v0.1.0.
3
+ The pieces of the [thema playground](../ui)'s frontend that other browser tools build on. The playground imports everything it shares from this package, so the package's API is exactly what the playground uses.
4
+
5
+ - `cue`, `cueParser`: the CUE language mode for CodeMirror 6.
6
+ - `Editor`: a Preact CodeMirror editor for CUE, JSON and YAML, with markers.
7
+ - `Diagnostics`: thema's diagnostics as a list, each linking to its error page.
8
+ - `OpBar`: the operations bar: a button per operation, the arguments the chosen one takes, and Run. The host holds the operation and its arguments (`OpArgs`) and passes `ops` to offer only some.
9
+ - `Output`: what an operation returned (an `Outcome`): its result in its own terms, lacunas included, then its diagnostics.
10
+ - `Tabs`: tabs over named texts, with adding, renaming, removing and a frozen group.
11
+ - `dataOps`, `codegenOps`, `argsOf`, `isCodegen` and the `UserOp` types: the operations a user runs and the arguments each takes.
12
+ - `markersFor`, `filesOf`, `docsURL`: diagnostics as editor markers.
13
+ - `offsetOf`, `charIndexOfByte`, `spanAt`: CUE positions (1-based line, byte column) as editor offsets.
14
+ - `lightTheme`, `darkTheme`, `highlight`, `tokenColors`, `darkScheme`: the editor's theme.
15
+ - `docs`, `DocLink`, `themaDoc`, `lacunaTypeDoc`: links into thema's reference docs.
16
+ - The wire types of thema's diagnostics and the playground's session API (`Diagnostic`, `Pos`, `LineageInput`, …). They are generated from thema's Go types by `playground/tsapi` (`github.com/sdboyer/thema/playground/tsapi`), so they match the thema release they come from. A Go program whose own wire types embed thema's can generate them by running the `tsapi.Types` jenny on a `tsapi.Config` of its own. With the Config's `Import` set to `tsapi.UIModule`, the generated file imports thema's types from this package instead of declaring them again.
17
+
18
+ The components are Preact components. `preact` and the CodeMirror packages are peer dependencies, so the host application provides one copy of each, which CodeMirror requires.
19
+
20
+ The bar, tabs and output are styled by the host through their class names: `ops`, `bar`, `op-group`, `op`, `op-args`, `primary`; `tabs`, `tab`, `active`, `frozen`, `flag`, `add`, `close`, `tab-group`, `group-label`; `output`, `status`, `ok`, `failed`, `per-version`, `result`, `lacunas`. The playground's `ui/src/style.css` is a complete set.
21
+
22
+ The theme colors through CSS custom properties that the host page defines: `--bg`, `--panel`, `--text`, `--muted`, `--border`, `--selection`, `--active-line`, `--error`, `--mono`, `--code-size`, and the token colors `--syn-comment`, `--syn-keyword`, `--syn-property`, `--syn-string` and `--syn-type`. The playground's `ui/src/style.css` defines them for light and dark schemes.
23
+
24
+ ## Developing
25
+
26
+ The package lives in the npm workspace at `playground/`. Run `npm ci` there, then `npm test` and `npm run build --workspace components`. The playground resolves the package to its source (the `source` export condition), so there is no build step between editing a component and seeing it in the playground.
@@ -0,0 +1,8 @@
1
+ import type { Diagnostic } from "./types";
2
+ interface Props {
3
+ diagnostics: readonly Diagnostic[];
4
+ onOpen?: (file: string) => void;
5
+ empty?: string;
6
+ }
7
+ export declare function Diagnostics({ diagnostics, onOpen, empty }: Props): import("preact").JSX.Element;
8
+ export {};
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ import { docsURL } from "./markers";
3
+ export function Diagnostics({ diagnostics, onOpen, empty }) {
4
+ if (diagnostics.length === 0) {
5
+ return _jsx("p", { class: "muted", children: empty ?? "Nothing to report." });
6
+ }
7
+ return (_jsx("ul", { class: "diagnostics", children: diagnostics.map((d, i) => (_jsxs("li", { class: `diagnostic ${d.severity}`, children: [_jsxs("div", { class: "headline", children: [_jsxs("a", { class: "code", href: docsURL(d.code), target: "_blank", rel: "noreferrer", title: "What this code means", children: [d.severity, "[", d.code, "]"] }), " ", d.headline] }), d.primary && _jsx(Where, { pos: d.primary, onOpen: onOpen }), (d.notes ?? []).map((n, j) => (_jsxs("div", { class: "note", children: [_jsx("span", { class: "label", children: "note:" }), " ", n.label, " ", n.pos && _jsx(Where, { pos: n.pos, onOpen: onOpen, inline: true })] }, j))), (d.help ?? []).map((h, j) => (_jsxs("div", { class: "help", children: [_jsx("span", { class: "label", children: "help:" }), " ", h] }, j))), d.detail && (_jsxs("details", { class: "detail", children: [_jsx("summary", { children: "CUE says" }), _jsx("pre", { children: d.detail })] }))] }, i))) }));
8
+ }
9
+ function Where({ pos, onOpen, inline }) {
10
+ const text = `${pos.file}:${pos.line}:${pos.col}`;
11
+ const own = pos.origin === "thema";
12
+ const body = own || !onOpen ? (_jsx("span", { children: own ? `thema's own CUE, ${text}` : text })) : (_jsx("button", { class: "link", onClick: () => onOpen(pos.file), children: text }));
13
+ return inline ? _jsxs("span", { class: "where", children: ["(", body, ")"] }) : _jsxs("div", { class: "where", children: ["--> ", body] });
14
+ }
@@ -0,0 +1,12 @@
1
+ import type { Marker } from "./markers";
2
+ export type Language = "cue" | "json" | "yaml" | "text";
3
+ interface Props {
4
+ text: string;
5
+ language: Language;
6
+ onChange?: (text: string) => void;
7
+ markers?: Marker[];
8
+ readOnly?: boolean;
9
+ label: string;
10
+ }
11
+ export declare function Editor({ text, language, onChange, markers, readOnly, label }: Props): import("preact").JSX.Element;
12
+ export {};
package/dist/Editor.js ADDED
@@ -0,0 +1,95 @@
1
+ import { jsx as _jsx } from "preact/jsx-runtime";
2
+ // A CodeMirror editor for one text. The text is the parent's; the editor
3
+ // reports edits and shows markers.
4
+ import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
5
+ import { json } from "@codemirror/lang-json";
6
+ import { bracketMatching, indentOnInput, indentUnit, syntaxHighlighting } from "@codemirror/language";
7
+ import { lintGutter, setDiagnostics } from "@codemirror/lint";
8
+ import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
9
+ import { Compartment, EditorState } from "@codemirror/state";
10
+ import { EditorView, drawSelection, highlightActiveLine, keymap, lineNumbers } from "@codemirror/view";
11
+ import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
12
+ import { cue } from "./cue-lang";
13
+ import { darkScheme, darkTheme, highlight, lightTheme } from "./theme";
14
+ const languages = {
15
+ // CUE's formatter indents with tabs, and so does every file it formats.
16
+ cue: () => [cue, indentUnit.of("\t")],
17
+ json: () => [json()],
18
+ yaml: () => [],
19
+ text: () => [],
20
+ };
21
+ export function Editor({ text, language, onChange, markers, readOnly, label }) {
22
+ const host = useRef(null);
23
+ const view = useRef(null);
24
+ const onChangeRef = useRef(onChange);
25
+ onChangeRef.current = onChange;
26
+ const lang = useRef(new Compartment());
27
+ const ro = useRef(new Compartment());
28
+ const scheme = useRef(new Compartment());
29
+ useEffect(() => {
30
+ const v = new EditorView({
31
+ parent: host.current,
32
+ state: EditorState.create({
33
+ doc: text,
34
+ extensions: [
35
+ lineNumbers(),
36
+ history(),
37
+ drawSelection(),
38
+ indentOnInput(),
39
+ bracketMatching(),
40
+ highlightActiveLine(),
41
+ highlightSelectionMatches(),
42
+ syntaxHighlighting(highlight),
43
+ lintGutter(),
44
+ keymap.of([...defaultKeymap, ...historyKeymap, ...searchKeymap, indentWithTab]),
45
+ lang.current.of(languages[language]()),
46
+ ro.current.of(EditorState.readOnly.of(!!readOnly)),
47
+ EditorView.contentAttributes.of({ "aria-label": label }),
48
+ scheme.current.of(darkScheme()?.matches ? darkTheme : lightTheme),
49
+ EditorView.updateListener.of((u) => {
50
+ if (u.docChanged)
51
+ onChangeRef.current?.(u.state.doc.toString());
52
+ }),
53
+ ],
54
+ }),
55
+ });
56
+ view.current = v;
57
+ // Follow the system when it switches between light and dark.
58
+ const mq = darkScheme();
59
+ const follow = (e) => v.dispatch({ effects: scheme.current.reconfigure(e.matches ? darkTheme : lightTheme) });
60
+ mq?.addEventListener("change", follow);
61
+ return () => {
62
+ mq?.removeEventListener("change", follow);
63
+ v.destroy();
64
+ };
65
+ }, []);
66
+ // A new text from outside (another file opened, an example loaded)
67
+ // replaces the document; an edit from this editor is already in it. This
68
+ // must be a layout effect: a plain effect waits for a frame, and a keystroke
69
+ // arriving before it would leave text one edit behind the document, so the
70
+ // effect would put the old text back, report it as an edit, and the parent
71
+ // and the editor would trade the two texts forever.
72
+ useLayoutEffect(() => {
73
+ const v = view.current;
74
+ if (v && v.state.doc.toString() !== text) {
75
+ v.dispatch({ changes: { from: 0, to: v.state.doc.length, insert: text } });
76
+ }
77
+ }, [text]);
78
+ useEffect(() => {
79
+ view.current?.dispatch({ effects: lang.current.reconfigure(languages[language]()) });
80
+ }, [language]);
81
+ useEffect(() => {
82
+ view.current?.dispatch({ effects: ro.current.reconfigure(EditorState.readOnly.of(!!readOnly)) });
83
+ }, [readOnly]);
84
+ useEffect(() => {
85
+ const v = view.current;
86
+ if (!v)
87
+ return;
88
+ const len = v.state.doc.length;
89
+ const ds = (markers ?? [])
90
+ .filter((m) => m.from <= len)
91
+ .map((m) => ({ from: m.from, to: Math.min(m.to, len), severity: m.severity, message: m.message, source: m.code }));
92
+ v.dispatch(setDiagnostics(v.state, ds));
93
+ }, [markers, text]);
94
+ return _jsx("div", { class: "editor", ref: host });
95
+ }
@@ -0,0 +1,14 @@
1
+ import { type OpArgs, type UserOp } from "./ops";
2
+ export interface OpBarProps {
3
+ op: UserOp;
4
+ args: OpArgs;
5
+ versions: readonly string[];
6
+ label: (version: string) => string;
7
+ onOp: (op: UserOp) => void;
8
+ onArgs: (args: OpArgs) => void;
9
+ onRun: () => void;
10
+ running: boolean;
11
+ disabled?: string;
12
+ ops?: readonly UserOp[];
13
+ }
14
+ export declare function OpBar({ op, args, versions, label, onOp, onArgs, onRun, running, disabled, ops }: OpBarProps): import("preact").JSX.Element;
package/dist/OpBar.js ADDED
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ // The operations bar: a button per operation, the arguments the chosen one
3
+ // takes, and Run. The host holds the state; the bar only shows and changes it.
4
+ import { DocLink, hasDoc } from "./docs";
5
+ import { argsOf, codegenOps, dataOps } from "./ops";
6
+ export function OpBar({ op, args, versions, label, onOp, onArgs, onRun, running, disabled, ops }) {
7
+ const offered = (o) => !ops || ops.includes(o);
8
+ const setArg = (k, v) => onArgs({ ...args, [k]: v });
9
+ const versionSelect = (k, none) => (_jsxs("select", { value: args[k], onChange: (e) => setArg(k, e.target.value), "aria-label": k, children: [_jsx("option", { value: "", children: none }), versions.map((v) => (_jsx("option", { value: v, children: label(v) }, v)))] }));
10
+ const takes = argsOf(op);
11
+ const opButton = (o) => (_jsxs("span", { class: "op", children: [_jsx("button", { "aria-pressed": op === o, onClick: () => onOp(o), children: o }), hasDoc(o) && _jsx(DocLink, { topic: o })] }, o));
12
+ const onData = dataOps.filter(offered);
13
+ const codegen = codegenOps.filter(offered);
14
+ return (_jsxs("div", { class: "ops", children: [_jsxs("div", { class: "bar", role: "toolbar", "aria-label": "Operations", children: [onData.length > 0 && (_jsx("span", { class: "op-group", role: "group", "aria-label": "On data", children: onData.map(opButton) })), codegen.length > 0 && (_jsx("span", { class: "op-group", role: "group", "aria-label": "Code generation", children: codegen.map(opButton) }))] }), _jsxs("div", { class: "bar op-args", children: [takes.includes("version") && _jsxs("label", { children: ["schema ", versionSelect("version", "latest")] }), takes.includes("from") && _jsxs("label", { children: ["from ", versionSelect("from", "the data's")] }), takes.includes("to") && _jsxs("label", { children: ["to ", versionSelect("to", "choose")] }), takes.includes("format") && (_jsxs("label", { children: ["as", " ", _jsxs("select", { value: args.format, onChange: (e) => setArg("format", e.target.value), "aria-label": "format", children: [_jsx("option", { value: "", children: op === "openapi" ? "YAML" : "JSON" }), _jsx("option", { value: "json", children: "JSON" }), _jsx("option", { value: "yaml", children: "YAML" })] })] })), _jsx("button", { class: "primary", onClick: onRun, disabled: !!disabled || running, title: disabled || undefined, children: running ? "Running…" : "Run" })] })] }));
15
+ }
@@ -0,0 +1,20 @@
1
+ import type { CodegenResponse, TranslateResponse, ValidateAnyResponse, ValidateResponse } from "./types";
2
+ export type Outcome = {
3
+ op: "validate";
4
+ resp: ValidateResponse;
5
+ } | {
6
+ op: "validate-any";
7
+ resp: ValidateAnyResponse;
8
+ } | {
9
+ op: "translate";
10
+ resp: TranslateResponse;
11
+ } | {
12
+ op: "openapi" | "jsonschema" | "typescript";
13
+ resp: CodegenResponse;
14
+ };
15
+ export interface OutputProps {
16
+ outcome: Outcome;
17
+ onOpen: (file: string) => void;
18
+ label?: (version: string) => string;
19
+ }
20
+ export declare function Output({ outcome, onOpen, label }: OutputProps): import("preact").JSX.Element;
package/dist/Output.js ADDED
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
+ // What an operation returned: its result in its own terms, then its
3
+ // diagnostics.
4
+ import { Diagnostics } from "./Diagnostics";
5
+ import { DocLink, lacunaTypeDoc } from "./docs";
6
+ import { Editor } from "./Editor";
7
+ const plain = (v) => v;
8
+ export function Output({ outcome, onOpen, label = plain }) {
9
+ const { resp } = outcome;
10
+ return (_jsxs("div", { class: "output", children: [_jsx(Summary, { outcome: outcome, label: label }), _jsx(Body, { outcome: outcome, label: label }), (resp.diagnostics.length > 0 || outcome.op !== "validate-any") && (_jsx(Diagnostics, { diagnostics: resp.diagnostics, onOpen: onOpen, empty: "" }))] }));
11
+ }
12
+ function Summary({ outcome, label }) {
13
+ const { op, resp } = outcome;
14
+ if (!resp.ok)
15
+ return _jsxs("p", { class: "status failed", children: [op, " failed"] });
16
+ switch (op) {
17
+ case "validate":
18
+ return _jsxs("p", { class: "status ok", children: ["The data is an instance of schema ", label(outcome.resp.version ?? ""), "."] });
19
+ case "validate-any":
20
+ return _jsxs("p", { class: "status ok", children: ["The newest schema the data is an instance of is ", label(outcome.resp.version ?? ""), "."] });
21
+ case "translate":
22
+ return (_jsxs("p", { class: "status ok", children: ["Translated from ", label(outcome.resp.from ?? ""), " to ", label(outcome.resp.to ?? ""), lacunaCount(outcome.resp) === 0 ? ", with no lacunas" : lacunaCount(outcome.resp) === 1 ? ", with 1 lacuna" : `, with ${lacunaCount(outcome.resp)} lacunas`, "."] }));
23
+ default:
24
+ return _jsxs("p", { class: "status ok", children: ["Generated from schema ", label(outcome.resp.version ?? ""), "."] });
25
+ }
26
+ }
27
+ function Body({ outcome, label }) {
28
+ switch (outcome.op) {
29
+ case "validate-any":
30
+ return (_jsx("div", { class: "per-version", children: outcome.resp.perVersion.map((v) => (_jsxs("details", { open: !outcome.resp.ok, children: [_jsxs("summary", { children: ["schema ", label(v.version), ": ", v.diagnostics.length === 0 ? "accepts the data" : `${v.diagnostics.length} diagnostics`] }), _jsx(Diagnostics, { diagnostics: v.diagnostics, empty: "Accepts the data." })] }, v.version))) }));
31
+ case "translate": {
32
+ const r = outcome.resp;
33
+ if (!r.ok)
34
+ return null;
35
+ return (_jsxs(_Fragment, { children: [_jsx(Result, { text: JSON.stringify(r.output, null, 2), language: "json", label: "Translated instance" }), _jsx(Lacunas, { resp: r, label: label })] }));
36
+ }
37
+ case "openapi":
38
+ case "jsonschema":
39
+ case "typescript":
40
+ return outcome.resp.ok ? (_jsx(Result, { text: outcome.resp.output ?? "", language: outcome.op === "typescript" ? "text" : "json", label: "Generated code" })) : null;
41
+ default:
42
+ return null;
43
+ }
44
+ }
45
+ function Result({ text, language, label }) {
46
+ return (_jsx("div", { class: "result", children: _jsx(Editor, { text: text, language: language, readOnly: true, label: label }) }));
47
+ }
48
+ function Lacunas({ resp, label }) {
49
+ const steps = (resp.lacunas ?? []).filter((s) => s.lacunas.length > 0);
50
+ if (steps.length === 0)
51
+ return null;
52
+ return (_jsxs("table", { class: "lacunas", children: [_jsxs("caption", { children: ["Lacunas ", _jsx(DocLink, { topic: "lacunas" })] }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "step" }), _jsx("th", { children: "type" }), _jsx("th", { children: "fields" }), _jsx("th", { children: "message" })] }) }), _jsx("tbody", { children: steps.flatMap((s) => s.lacunas.map((l, i) => (_jsxs("tr", { children: [_jsxs("td", { children: [label(s.from.join(".")), " \u2192 ", label(s.to.join("."))] }), _jsxs("td", { children: [l.type, _jsx(DocLink, { doc: lacunaTypeDoc(l.type) })] }), _jsx("td", { children: [...(l.sourceFields ?? []), ...(l.targetFields ?? [])].map((f) => f.path).join(", ") }), _jsx("td", { children: l.message })] }, `${s.from}-${s.to}-${i}`)))) })] }));
53
+ }
54
+ function lacunaCount(r) {
55
+ return (r.lacunas ?? []).reduce((n, s) => n + s.lacunas.length, 0);
56
+ }
package/dist/Tabs.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type Topic } from "./docs";
2
+ export interface TabsProps {
3
+ names: readonly string[];
4
+ active: number;
5
+ flagged?: Set<string>;
6
+ onSelect: (i: number) => void;
7
+ onAdd?: () => void;
8
+ onRename?: (i: number, name: string) => void;
9
+ onRemove?: (i: number) => void;
10
+ label: string;
11
+ docs?: readonly (Topic | undefined)[];
12
+ frozen?: (name: string) => boolean;
13
+ frozenLabel?: string;
14
+ }
15
+ export declare function Tabs({ names, active, flagged, onSelect, onAdd, onRename, onRemove, label, docs, frozen, frozenLabel }: TabsProps): import("preact").JSX.Element;
package/dist/Tabs.js ADDED
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ // Tabs over a list of named texts, with adding, renaming and removing. Frozen
3
+ // tabs are grouped after the others and can be opened but never renamed or
4
+ // removed.
5
+ import { DocLink } from "./docs";
6
+ export function Tabs({ names, active, flagged, onSelect, onAdd, onRename, onRemove, label, docs, frozen, frozenLabel }) {
7
+ const isFrozen = (n) => !!frozen?.(n);
8
+ const tab = (n, i) => {
9
+ const fixed = isFrozen(n);
10
+ const rename = fixed ? undefined : onRename;
11
+ return (_jsxs("span", { class: `tab ${i === active ? "active" : ""} ${fixed ? "frozen" : ""}`, children: [_jsxs("button", { role: "tab", "aria-selected": i === active, onClick: () => onSelect(i), onDblClick: () => {
12
+ if (!rename)
13
+ return;
14
+ const name = prompt("Rename to", n);
15
+ if (name && name !== n)
16
+ rename(i, name);
17
+ }, title: fixed ? "Frozen: this version is cut and never changes" : rename ? "Double-click to rename" : undefined, children: [flagged?.has(n) && _jsx("span", { class: "flag", "aria-label": "has diagnostics", children: "\u25CF" }), n] }), docs?.[i] && _jsx(DocLink, { topic: docs[i] }), onRemove && !fixed && names.length > 1 && (_jsx("button", { class: "close", "aria-label": `Remove ${n}`, onClick: () => onRemove(i), children: "\u00D7" }))] }, i));
18
+ };
19
+ const indexed = names.map((n, i) => [n, i]);
20
+ const open = indexed.filter(([n]) => !isFrozen(n));
21
+ const fixed = indexed.filter(([n]) => isFrozen(n));
22
+ return (_jsxs("div", { class: "tabs", role: "tablist", "aria-label": label, children: [open.map(([n, i]) => tab(n, i)), onAdd && (_jsx("button", { class: "add", "aria-label": `Add to ${label}`, onClick: onAdd, children: "+" })), fixed.length > 0 && (_jsxs("span", { class: "tab-group frozen", role: "group", "aria-label": frozenLabel, children: [_jsx("span", { class: "group-label", "aria-hidden": "true", children: frozenLabel }), fixed.map(([n, i]) => tab(n, i))] }))] }));
23
+ }
@@ -0,0 +1,8 @@
1
+ import { StreamLanguage, type StreamParser } from "@codemirror/language";
2
+ interface State {
3
+ inString: string | null;
4
+ inComment: boolean;
5
+ }
6
+ export declare const cueParser: StreamParser<State>;
7
+ export declare const cue: StreamLanguage<State>;
8
+ export {};
@@ -0,0 +1,82 @@
1
+ // A small CUE highlighter for CodeMirror. CUE has no CodeMirror 6 language
2
+ // package; this tokenizes what an editor needs to colour: comments, strings,
3
+ // numbers, keywords, builtin types, definitions, attributes and punctuation.
4
+ // It does not parse.
5
+ import { StreamLanguage } from "@codemirror/language";
6
+ const keywords = new Set(["package", "import", "for", "in", "if", "let", "true", "false", "null"]);
7
+ const types = new Set(["bool", "string", "bytes", "number", "int", "float", "uint", "rune", "_", "_|_", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float32", "float64"]);
8
+ // The authoring form's own words.
9
+ const authoring = new Set(["Schema", "ForwardLens", "BackwardLens", "lacunas", "_drop", "_coalesce", "_match", "_each", "_item", "when"]);
10
+ export const cueParser = {
11
+ name: "cue",
12
+ startState: () => ({ inString: null, inComment: false }),
13
+ token(stream, state) {
14
+ if (state.inString) {
15
+ const close = state.inString;
16
+ while (!stream.eol()) {
17
+ if (stream.match(close)) {
18
+ state.inString = null;
19
+ return "string";
20
+ }
21
+ if (stream.next() === "\\")
22
+ stream.next();
23
+ }
24
+ return "string";
25
+ }
26
+ if (stream.eatSpace())
27
+ return null;
28
+ if (stream.match("//")) {
29
+ stream.skipToEnd();
30
+ return "comment";
31
+ }
32
+ if (stream.match('"""') || stream.match("'''")) {
33
+ state.inString = stream.current();
34
+ return "string";
35
+ }
36
+ const ch = stream.peek();
37
+ if (ch === '"' || ch === "'") {
38
+ stream.next();
39
+ while (!stream.eol()) {
40
+ const c = stream.next();
41
+ if (c === "\\") {
42
+ stream.next();
43
+ }
44
+ else if (c === ch) {
45
+ break;
46
+ }
47
+ }
48
+ return "string";
49
+ }
50
+ if (ch === "@") {
51
+ stream.next();
52
+ stream.match(/^[A-Za-z_][\w]*/);
53
+ return "meta";
54
+ }
55
+ if (stream.match(/^-?(0x[0-9a-fA-F_]+|0o[0-7_]+|0b[01_]+|\d[\d_]*(\.\d+)?([eE][+-]?\d+)?[KMGTP]?i?)/)) {
56
+ return "number";
57
+ }
58
+ if (stream.match("_|_"))
59
+ return "typeName";
60
+ if (stream.match(/^#?[A-Za-z_$][\w$]*/)) {
61
+ const w = stream.current();
62
+ if (w.startsWith("#"))
63
+ return "className";
64
+ if (keywords.has(w))
65
+ return "keyword";
66
+ if (types.has(w))
67
+ return "typeName";
68
+ if (authoring.has(w))
69
+ return "keyword";
70
+ return stream.peek() === ":" || stream.match(/^\s*[?!]?\s*:/, false) ? "propertyName" : "variableName";
71
+ }
72
+ if (stream.match(/^(\.\.\.|=~|!~|[=!<>]=?|&&|\|\||[&|*+\-/])/))
73
+ return "operator";
74
+ stream.next();
75
+ return "punctuation";
76
+ },
77
+ languageData: {
78
+ commentTokens: { line: "//" },
79
+ closeBrackets: { brackets: ["(", "[", "{", '"'] },
80
+ },
81
+ };
82
+ export const cue = StreamLanguage.define(cueParser);