@sealcode/jdd-editor 0.2.1 → 0.2.5

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 (37) hide show
  1. package/.nyc_output/2100f533-71ff-4c0e-81c5-53e05dcac20f.json +1 -0
  2. package/.nyc_output/processinfo/2100f533-71ff-4c0e-81c5-53e05dcac20f.json +1 -0
  3. package/.nyc_output/processinfo/ac9c9615-9aa2-4e42-8685-90e92855ba11.json +1 -0
  4. package/.nyc_output/processinfo/d0ae4bd5-5f2e-4e32-9403-fb824c49a5f8.json +1 -0
  5. package/.nyc_output/processinfo/index.json +1 -1
  6. package/.xunit +1 -1
  7. package/@types/components.sreact.d.ts +1 -5
  8. package/@types/controllers/json-editor.stimulus.d.ts +2 -0
  9. package/@types/inputs/component-input-code.d.ts +5 -0
  10. package/@types/inputs/component-input-color.d.ts +15 -0
  11. package/@types/jdd-page.d.ts +1 -6
  12. package/coverage/clover.xml +310 -299
  13. package/dist/src/components.sreact.js +1 -14
  14. package/dist/src/components.sreact.js.map +2 -2
  15. package/dist/src/controllers/json-editor.stimulus.js +33 -23
  16. package/dist/src/controllers/json-editor.stimulus.js.map +2 -2
  17. package/dist/src/inputs/component-input-code.js +23 -0
  18. package/dist/src/inputs/component-input-code.js.map +7 -0
  19. package/dist/src/inputs/component-input-color.js +27 -0
  20. package/dist/src/inputs/component-input-color.js.map +7 -0
  21. package/dist/src/inputs/component-input.js +24 -2
  22. package/dist/src/inputs/component-input.js.map +2 -2
  23. package/dist/src/jdd-page.js +1 -14
  24. package/dist/src/jdd-page.js.map +2 -2
  25. package/package.json +4 -3
  26. package/src/components.sreact.ts +1 -14
  27. package/src/controllers/json-editor.stimulus.ts +33 -20
  28. package/src/inputs/component-input-code.ts +24 -0
  29. package/src/inputs/component-input-color.ts +38 -0
  30. package/src/inputs/component-input.ts +25 -2
  31. package/src/jdd-page.ts +2 -15
  32. package/.nyc_output/cfebf13d-f940-426b-a4d3-af28d17bb6b8.json +0 -1
  33. package/.nyc_output/processinfo/2ad4e34c-cebb-4299-9698-08eccbbe71f7.json +0 -1
  34. package/.nyc_output/processinfo/71f2685b-e2c9-4db2-9f31-0dbdcacfcea1.json +0 -1
  35. package/.nyc_output/processinfo/cfebf13d-f940-426b-a4d3-af28d17bb6b8.json +0 -1
  36. /package/.nyc_output/{2ad4e34c-cebb-4299-9698-08eccbbe71f7.json → ac9c9615-9aa2-4e42-8685-90e92855ba11.json} +0 -0
  37. /package/.nyc_output/{71f2685b-e2c9-4db2-9f31-0dbdcacfcea1.json → d0ae4bd5-5f2e-4e32-9403-fb824c49a5f8.json} +0 -0
@@ -0,0 +1,24 @@
1
+ import { tempstream } from "tempstream";
2
+ import { printArgPath } from "./print-arg-path.js";
3
+
4
+ export function ComponentInputCode({
5
+ language,
6
+ value,
7
+ arg_path,
8
+ }: {
9
+ value: string;
10
+ language: string;
11
+ arg_path: string[];
12
+ }): JSX.Element {
13
+ return tempstream/* HTML */ `<div class="monaco-wrapper">
14
+ <div data-controller="monaco" data-language="${language}">
15
+ <textarea
16
+ data-monaco-target="textarea"
17
+ name="$${printArgPath(arg_path)}"
18
+ style="display: none"
19
+ >
20
+ ${value}
21
+ </textarea>
22
+ </div>
23
+ </div>`;
24
+ }
@@ -0,0 +1,38 @@
1
+ import type { Context } from "koa";
2
+ import type { Color, JDDContext } from "@sealcode/jdd";
3
+ import type { StatefulPage } from "@sealcode/sealgen";
4
+ import type { ComponentPreviewActions } from "../component-preview-actions.js";
5
+ import type { JDDPageState } from "../jdd-page.js";
6
+ import { tempstream } from "tempstream";
7
+ import { printArgPath } from "./print-arg-path.js";
8
+ import { htmlEscape } from "escape-goat";
9
+
10
+ export function ComponentInputColor<State extends JDDPageState>({
11
+ arg_path,
12
+ value,
13
+ onchange,
14
+ }: {
15
+ state: State;
16
+ arg_path: string[];
17
+ arg: Color;
18
+ value: string | null;
19
+ page: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;
20
+ ctx: Context;
21
+ onchange?: string;
22
+ makeJDDContext: (ctx: Context) => JDDContext;
23
+ }): JSX.Element {
24
+ return tempstream/* HTML */ `<div style="margin-bottom: 10px">
25
+ <div>
26
+ <label>
27
+ ${arg_path.at(-1) || ""}
28
+ <input
29
+ type="color"
30
+ name="${`$${printArgPath(arg_path)}`}"
31
+ value="${htmlEscape(value || "#000000")}"
32
+ autocomplete="off"
33
+ onchange="${onchange || ""}"
34
+ />
35
+ </label>
36
+ </div>
37
+ </div>`;
38
+ }
@@ -1,7 +1,7 @@
1
1
  import { printArgPath } from "./print-arg-path.js";
2
2
  import type { Context } from "koa";
3
3
  import type { ComponentArgument, JDDContext, TableData } from "@sealcode/jdd";
4
- import { NestedComponent, SingleReference } from "@sealcode/jdd";
4
+ import { NestedComponent, Color, SingleReference } from "@sealcode/jdd";
5
5
  import {
6
6
  ComponentArguments,
7
7
  Enum,
@@ -9,6 +9,7 @@ import {
9
9
  List,
10
10
  Structured,
11
11
  Table,
12
+ Code,
12
13
  } from "@sealcode/jdd";
13
14
  import { ComponentInputStructured } from "./component-input-structured.js";
14
15
  import type { StatefulPage } from "@sealcode/sealgen";
@@ -22,7 +23,8 @@ import type { FilePointer } from "@sealcode/file-manager";
22
23
  import { ComponentInputSingleReference } from "./component-input-single-reference.js";
23
24
  import { is, predicates } from "@sealcode/ts-predicates";
24
25
  import { tempstream } from "tempstream";
25
-
26
+ import { ComponentInputCode } from "./component-input-code.js";
27
+ import { ComponentInputColor } from "./component-input-color.js";
26
28
  export const actionName = "Components";
27
29
  const absoluteUrlPattern = "http(s?)(://)((www.)?)(([^.]+).)?([a-zA-z0-9-_]+)";
28
30
 
@@ -48,6 +50,19 @@ export async function ComponentInput<State extends JDDPageState, T>({
48
50
  if (value === undefined) {
49
51
  value = await arg.getEmptyValue(makeJDDContext(ctx));
50
52
  }
53
+ if (arg instanceof Color) {
54
+ return ComponentInputColor({
55
+ ctx,
56
+ state,
57
+ arg_path,
58
+ arg,
59
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
60
+ value: value as string,
61
+ page,
62
+ onchange: page.rerender(),
63
+ makeJDDContext,
64
+ });
65
+ }
51
66
  if (arg instanceof List) {
52
67
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
53
68
  return ComponentInputList({
@@ -133,6 +148,14 @@ export async function ComponentInput<State extends JDDPageState, T>({
133
148
  });
134
149
  }
135
150
 
151
+ if (arg instanceof Code) {
152
+ return ComponentInputCode({
153
+ language: arg.language,
154
+ value: is(value, predicates.string) ? value : "",
155
+ arg_path,
156
+ });
157
+ }
158
+
136
159
  const inputElement = () => {
137
160
  if (arg instanceof ComponentArguments.Number) {
138
161
  return tempstream/* HTML */ ` <input
package/src/jdd-page.ts CHANGED
@@ -65,22 +65,9 @@ export default abstract class JDDPage extends StatefulPage<
65
65
  return this.registry.getAll();
66
66
  }
67
67
 
68
- async getInitialState(ctx: Context) {
69
- const all_components = Object.entries(this.getRegistryComponents());
70
- const first_component = all_components[0];
71
- if (!first_component) {
72
- throw new Error("No defined components!");
73
- }
74
- const [component_name, component] = first_component;
68
+ async getInitialState(ctx: Context): Promise<JDDPageState> {
75
69
  const initial_state = {
76
- components: [
77
- {
78
- component_name: component_name,
79
- args: await component.getExampleValues(
80
- this.makeJDDContext(ctx)
81
- ),
82
- },
83
- ],
70
+ components: [],
84
71
  };
85
72
  return initial_state;
86
73
  }