@sealcode/jdd-editor 0.2.5 → 0.2.7

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 (46) hide show
  1. package/@types/inputs/component-input-enum.d.ts +3 -2
  2. package/assets/styles/atom-one-light.css +72 -0
  3. package/assets/styles/components.jdd-page.css +13 -6
  4. package/dist/src/component-preview-actions.js +1 -3
  5. package/dist/src/component-preview-actions.js.map +2 -2
  6. package/dist/src/components.sreact.js +5 -5
  7. package/dist/src/components.sreact.js.map +2 -2
  8. package/dist/src/inputs/component-input-code.js.map +1 -1
  9. package/dist/src/inputs/component-input-color.js.map +1 -1
  10. package/dist/src/inputs/component-input-enum.js +8 -7
  11. package/dist/src/inputs/component-input-enum.js.map +2 -2
  12. package/dist/src/inputs/component-input-image.js.map +1 -1
  13. package/dist/src/inputs/component-input-list.js.map +1 -1
  14. package/dist/src/inputs/component-input-single-reference.js +5 -5
  15. package/dist/src/inputs/component-input-single-reference.js.map +2 -2
  16. package/dist/src/inputs/component-input-structured.js.map +2 -2
  17. package/dist/src/inputs/component-input-table.js +44 -44
  18. package/dist/src/inputs/component-input-table.js.map +2 -2
  19. package/dist/src/inputs/component-input.js +3 -2
  20. package/dist/src/inputs/component-input.js.map +2 -2
  21. package/dist/src/jdd-creator.js.map +1 -1
  22. package/dist/src/jdd-page.js +14 -8
  23. package/dist/src/jdd-page.js.map +2 -2
  24. package/package.json +5 -4
  25. package/src/component-preview-actions.ts +2 -3
  26. package/src/components.sreact.ts +9 -8
  27. package/src/inputs/component-input-code.ts +1 -1
  28. package/src/inputs/component-input-color.ts +1 -1
  29. package/src/inputs/component-input-enum.ts +12 -8
  30. package/src/inputs/component-input-image.ts +1 -1
  31. package/src/inputs/component-input-list.ts +2 -2
  32. package/src/inputs/component-input-single-reference.ts +8 -7
  33. package/src/inputs/component-input-structured.ts +2 -2
  34. package/src/inputs/component-input-table.ts +127 -127
  35. package/src/inputs/component-input.ts +5 -4
  36. package/src/jdd-creator.ts +1 -1
  37. package/src/jdd-page.ts +22 -13
  38. package/.nyc_output/2100f533-71ff-4c0e-81c5-53e05dcac20f.json +0 -1
  39. package/.nyc_output/ac9c9615-9aa2-4e42-8685-90e92855ba11.json +0 -1
  40. package/.nyc_output/d0ae4bd5-5f2e-4e32-9403-fb824c49a5f8.json +0 -1
  41. package/.nyc_output/processinfo/2100f533-71ff-4c0e-81c5-53e05dcac20f.json +0 -1
  42. package/.nyc_output/processinfo/ac9c9615-9aa2-4e42-8685-90e92855ba11.json +0 -1
  43. package/.nyc_output/processinfo/d0ae4bd5-5f2e-4e32-9403-fb824c49a5f8.json +0 -1
  44. package/.nyc_output/processinfo/index.json +0 -1
  45. package/.xunit +0 -2
  46. package/coverage/clover.xml +0 -877
@@ -1,4 +1,4 @@
1
- import type { Enum } from "@sealcode/jdd";
1
+ import type { Enum, JDDContext } from "@sealcode/jdd";
2
2
  import { printArgPath } from "./print-arg-path.js";
3
3
 
4
4
  export function ComponentInputEnum<State, S extends string, T extends Enum<S>>({
@@ -6,12 +6,14 @@ export function ComponentInputEnum<State, S extends string, T extends Enum<S>>({
6
6
  arg,
7
7
  value,
8
8
  onchange,
9
+ jdd_context,
9
10
  }: {
10
11
  state: State;
11
12
  arg_path: string[];
12
13
  arg: T;
13
14
  value: string;
14
15
  onchange?: string;
16
+ jdd_context: JDDContext;
15
17
  }) {
16
18
  return /* HTML */ `<div id=${`component-input-enum-${arg_path.join("-")}`}>
17
19
  <label>
@@ -20,14 +22,16 @@ export function ComponentInputEnum<State, S extends string, T extends Enum<S>>({
20
22
  name="${`$${printArgPath(arg_path)}`}"
21
23
  onchange="${onchange || ""}"
22
24
  >
23
- ${arg.values
25
+ ${arg
26
+ .getValues(jdd_context)
24
27
  .map(
25
- (v: S) => /* HTML */ `<option
26
- value="${v}"
27
- ${value == v ? "selected" : ""}
28
- >
29
- ${v}
30
- </option>`
28
+ (v: S) =>
29
+ /* HTML */ `<option
30
+ value="${v}"
31
+ ${value == v ? "selected" : ""}
32
+ >
33
+ ${v}
34
+ </option>`
31
35
  )
32
36
  .join("")}
33
37
  </select>
@@ -26,7 +26,7 @@ export function ComponentInputImage<State extends JDDPageState>({
26
26
  makeJDDContext: (ctx: Context) => JDDContext;
27
27
  }): JSX.Element {
28
28
  const jdd_context = makeJDDContext(ctx);
29
- return tempstream/* HTML */ `<div style="margin-bottom: 10px">
29
+ return tempstream /* HTML */ `<div style="margin-bottom: 10px">
30
30
  <label
31
31
  style="display: flex; align-items: center; column-gap: 10px;"
32
32
  data-controller="input-image-preview"
@@ -9,7 +9,7 @@ import { tempstream } from "tempstream";
9
9
 
10
10
  export async function ComponentInputList<
11
11
  State extends JDDPageState,
12
- T extends ComponentArgument<unknown>
12
+ T extends ComponentArgument<unknown>,
13
13
  >({
14
14
  state,
15
15
  ctx,
@@ -33,7 +33,7 @@ export async function ComponentInputList<
33
33
  if (!value) {
34
34
  value = [];
35
35
  }
36
- return tempstream/* HTML */ `<fieldset
36
+ return tempstream /* HTML */ `<fieldset
37
37
  id="${`component-input-list-${arg_path.join("-")}`}"
38
38
  >
39
39
  <legend>${arg_path.at(-1)!}</legend>
@@ -5,7 +5,7 @@ import { printArgPath } from "./print-arg-path.js";
5
5
  export async function ComponentInputSingleReference<
6
6
  State,
7
7
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- T extends SingleReference<any>
8
+ T extends SingleReference<any>,
9
9
  >({
10
10
  ctx,
11
11
  arg_path,
@@ -30,12 +30,13 @@ export async function ComponentInputSingleReference<
30
30
  ${values
31
31
  .sort((v1, v2) => (v1.label > v2.label ? 1 : -1))
32
32
  .map(
33
- (v) => /* HTML */ `<option
34
- value="${v.value}"
35
- ${value == v.value ? "selected" : ""}
36
- >
37
- ${v.label}
38
- </option>`
33
+ (v) =>
34
+ /* HTML */ `<option
35
+ value="${v.value}"
36
+ ${value == v.value ? "selected" : ""}
37
+ >
38
+ ${v.label}
39
+ </option>`
39
40
  )
40
41
  .join("")}
41
42
  </select>
@@ -13,7 +13,7 @@ import type { ComponentPreviewActions } from "../component-preview-actions.js";
13
13
  export async function ComponentInputStructured<
14
14
  T extends
15
15
  | Structured<Record<string, ComponentArgument<unknown>>>
16
- | NestedComponent
16
+ | NestedComponent,
17
17
  >({
18
18
  state,
19
19
  ctx,
@@ -42,7 +42,7 @@ export async function ComponentInputStructured<
42
42
  (Object.keys(
43
43
  makeJDDContext(ctx).registry.getAll()
44
44
  )[0] as string)
45
- );
45
+ );
46
46
 
47
47
  return /* HTML */ `<fieldset
48
48
  id="${`component-input-structured-${arg_path.join("-")}`}"
@@ -12,7 +12,7 @@ import type { JDDPageState } from "../jdd-page.js";
12
12
  export async function ComponentInputTable<
13
13
  State extends JDDPageState,
14
14
  CellType,
15
- HeaderType
15
+ HeaderType,
16
16
  >({
17
17
  state,
18
18
  arg_path,
@@ -40,7 +40,7 @@ export async function ComponentInputTable<
40
40
  arg.cell_type instanceof Markdown &&
41
41
  arg.header_type instanceof Markdown;
42
42
 
43
- return tempstream/* HTML */ `<fieldset>
43
+ return tempstream /* HTML */ `<fieldset>
44
44
  <legend>${arg_path.at(-1)!}</legend>
45
45
  <div>
46
46
  ${show_paste
@@ -52,7 +52,7 @@ export async function ComponentInputTable<
52
52
  "."
53
53
  )}"
54
54
  data-controller="jdd-table-paste"
55
- />`
55
+ />`
56
56
  : ""}
57
57
  <table
58
58
  class="jdd-component-input--table"
@@ -63,90 +63,92 @@ export async function ComponentInputTable<
63
63
  <td></td>
64
64
  ${[...Array(arg.getColumnsCount(value)).keys()]
65
65
  .map(
66
- (column_index) => /* HTML */ `<th
67
- class="sticky sticky--top subdued"
68
- >
69
- ${page.makeActionButton(
70
- state,
71
- {
72
- action: "remove_table_column",
73
- label: "Remove column",
74
- content: /* HTML */ `<img
75
- width="20"
76
- height="20"
77
- src="${makeAssetURL(
78
- "icons/table-delete-column.svg"
79
- )}"
80
- />`,
81
- },
82
- arg_path,
83
- column_index
84
- )}
85
- ${column_index >=
86
- arg.getColumnsCount(value) - 1
87
- ? ""
88
- : page.makeActionButton(
89
- state,
90
- {
91
- action: "move_table_column_right",
92
- label: "Move column to the right",
93
- content: /* HTML */ `<img
94
- width="20"
95
- height="20"
96
- src="${makeAssetURL(
97
- "icons/table-move-column-right.svg"
98
- )}"
99
- />`,
100
- },
101
- arg_path,
102
- column_index
103
- )}
104
- </th>`
66
+ (column_index) =>
67
+ /* HTML */ `<th
68
+ class="sticky sticky--top subdued"
69
+ >
70
+ ${page.makeActionButton(
71
+ state,
72
+ {
73
+ action: "remove_table_column",
74
+ label: "Remove column",
75
+ content: /* HTML */ `<img
76
+ width="20"
77
+ height="20"
78
+ src="${makeAssetURL(
79
+ "icons/table-delete-column.svg"
80
+ )}"
81
+ />`,
82
+ },
83
+ arg_path,
84
+ column_index
85
+ )}
86
+ ${column_index >=
87
+ arg.getColumnsCount(value) - 1
88
+ ? ""
89
+ : page.makeActionButton(
90
+ state,
91
+ {
92
+ action: "move_table_column_right",
93
+ label: "Move column to the right",
94
+ content: /* HTML */ `<img
95
+ width="20"
96
+ height="20"
97
+ src="${makeAssetURL(
98
+ "icons/table-move-column-right.svg"
99
+ )}"
100
+ />`,
101
+ },
102
+ arg_path,
103
+ column_index
104
+ )}
105
+ </th>`
105
106
  )
106
107
  .join("")}
107
108
  </tr>
108
109
  ${value.rows.map(
109
- (row, row_index) => tempstream/* HTML */ `<tr>
110
- <td class="sticky sticky--left subdued">
111
- <div
112
- style="display: flex; flex-flow: column; row-gap: 5px;"
113
- >
114
- ${page.makeActionButton(
115
- state,
116
- {
117
- action: "remove_table_row",
118
- label: "Remove row",
119
- content: /* HTML */ `<img
120
- width="20"
121
- height="20"
122
- src="${makeAssetURL(
123
- "icons/table-delete-row.svg"
124
- )}"
125
- />`,
126
- },
127
- arg_path,
128
- row_index
129
- )}
130
- ${page.makeActionButton(
131
- state,
132
- {
133
- action: "move_table_row_down",
134
- label: "Move this row down",
135
- content: /* HTML */ `<img
136
- width="20"
137
- height="20"
138
- src="${makeAssetURL(
139
- "icons/table-move-row-down.svg"
140
- )}"
141
- />`,
142
- },
143
- arg_path,
144
- row_index
145
- )}
146
- </div>
147
- </td>
148
- ${isTableHeader(row)
149
- ? /* HTML */ tempstream`<th
110
+ (row, row_index) =>
111
+ tempstream /* HTML */ `<tr>
112
+ <td class="sticky sticky--left subdued">
113
+ <div
114
+ style="display: flex; flex-flow: column; row-gap: 5px;"
115
+ >
116
+ ${page.makeActionButton(
117
+ state,
118
+ {
119
+ action: "remove_table_row",
120
+ label: "Remove row",
121
+ content: /* HTML */ `<img
122
+ width="20"
123
+ height="20"
124
+ src="${makeAssetURL(
125
+ "icons/table-delete-row.svg"
126
+ )}"
127
+ />`,
128
+ },
129
+ arg_path,
130
+ row_index
131
+ )}
132
+ ${page.makeActionButton(
133
+ state,
134
+ {
135
+ action: "move_table_row_down",
136
+ label: "Move this row down",
137
+ content: /* HTML */ `<img
138
+ width="20"
139
+ height="20"
140
+ src="${makeAssetURL(
141
+ "icons/table-move-row-down.svg"
142
+ )}"
143
+ />`,
144
+ },
145
+ arg_path,
146
+ row_index
147
+ )}
148
+ </div>
149
+ </td>
150
+ ${isTableHeader(row)
151
+ ? /* HTML */ tempstream`<th
150
152
  colspan="${arg.getColumnsCount(value).toString()}"
151
153
  >
152
154
  ${ComponentInput({
@@ -165,52 +167,50 @@ export async function ComponentInputTable<
165
167
  makeAssetURL,
166
168
  })}
167
169
  </th>`
168
- : row.cells.map(
169
- (
170
- cell,
171
- cell_index
172
- ) => tempstream/* HTML */ `<td>
173
- ${ComponentInput({
174
- ctx,
170
+ : row.cells.map(
171
+ (cell, cell_index) =>
172
+ tempstream /* HTML */ `<td>
173
+ ${ComponentInput({
174
+ ctx,
175
+ state,
176
+ arg_path: [
177
+ ...arg_path,
178
+ "rows",
179
+ row_index.toString(),
180
+ "cells",
181
+ cell_index.toString(),
182
+ ],
183
+ arg: arg.cell_type,
184
+ value: cell,
185
+ page,
186
+ makeJDDContext,
187
+ makeAssetURL,
188
+ })}
189
+ </td>`
190
+ )}
191
+ ${row_index == 0
192
+ ? /* HTML */ `<td
193
+ class="subdued"
194
+ rowspan="${value.rows.length.toString()}"
195
+ >
196
+ ${page.makeActionButton(
175
197
  state,
176
- arg_path: [
177
- ...arg_path,
178
- "rows",
179
- row_index.toString(),
180
- "cells",
181
- cell_index.toString(),
182
- ],
183
- arg: arg.cell_type,
184
- value: cell,
185
- page,
186
- makeJDDContext,
187
- makeAssetURL,
188
- })}
198
+ {
199
+ action: "add_table_column",
200
+ label: "Add column",
201
+ content: /* HTML */ `<img
202
+ width="20"
203
+ height="20"
204
+ src="${makeAssetURL(
205
+ "icons/table-add-column-right.svg"
206
+ )}"
207
+ />`,
208
+ },
209
+ arg_path
210
+ )}
189
211
  </td>`
190
- )}
191
- ${row_index == 0
192
- ? /* HTML */ `<td
193
- class="subdued"
194
- rowspan="${value.rows.length.toString()}"
195
- >
196
- ${page.makeActionButton(
197
- state,
198
- {
199
- action: "add_table_column",
200
- label: "Add column",
201
- content: /* HTML */ `<img
202
- width="20"
203
- height="20"
204
- src="${makeAssetURL(
205
- "icons/table-add-column-right.svg"
206
- )}"
207
- />`,
208
- },
209
- arg_path
210
- )}
211
- </td>`
212
- : ""}
213
- </tr>`
212
+ : ""}
213
+ </tr>`
214
214
  )}
215
215
  <tr>
216
216
  <td
@@ -118,6 +118,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
118
118
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
119
119
  value: value as string,
120
120
  onchange: page.rerender(),
121
+ jdd_context: makeJDDContext(ctx),
121
122
  });
122
123
  }
123
124
 
@@ -158,7 +159,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
158
159
 
159
160
  const inputElement = () => {
160
161
  if (arg instanceof ComponentArguments.Number) {
161
- return tempstream/* HTML */ ` <input
162
+ return tempstream /* HTML */ ` <input
162
163
  type="number"
163
164
  name="${`$${printArgPath(arg_path)}`}"
164
165
  value="${(value || "").toString()}"
@@ -167,7 +168,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
167
168
  step="${arg.step || ""}"
168
169
  />`;
169
170
  } else if (arg instanceof ComponentArguments.URL) {
170
- return tempstream/* HTML */ ` <input
171
+ return tempstream /* HTML */ ` <input
171
172
  type="${isUrlAbsolute ? "url" : "text"}"
172
173
  name="${`$${printArgPath(arg_path)}`}"
173
174
  value="${(value || "").toString()}"
@@ -175,7 +176,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
175
176
  ${isUrlAbsolute ? `pattern="${absoluteUrlPattern}"` : ""}
176
177
  />`;
177
178
  } else {
178
- return tempstream/* HTML */ ` <input
179
+ return tempstream /* HTML */ ` <input
179
180
  type="${inputType}"
180
181
  name="${`$${printArgPath(arg_path)}`}"
181
182
  value="${is(value, predicates.string) ? value : ""}"
@@ -200,7 +201,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
200
201
  >
201
202
  ${is(value, predicates.string) ? value : ""}</textarea
202
203
  >
203
- </div>`
204
+ </div>`
204
205
  : await inputElement()}
205
206
  </label>
206
207
  </div>`;
@@ -64,7 +64,7 @@ export default abstract class JDDCreator extends JDDPage {
64
64
  const component =
65
65
  this.getRegistryComponents()[component_data.component_name];
66
66
  const checkbox_id = `component_${component_index}_open`;
67
- return tempstream/* HTML */ `<div
67
+ return tempstream /* HTML */ `<div
68
68
  class="jdd-editor__component-block jdd-editor__component-block--number-${component_index}"
69
69
  id="${`jdd-editor__component-block--${component_data.component_name}-${component_index}`}"
70
70
  data-component-debugger-target="componentBlock"
package/src/jdd-page.ts CHANGED
@@ -10,7 +10,8 @@ import type { FlatTemplatable, Templatable } from "tempstream";
10
10
  import { tempstream } from "tempstream";
11
11
  import { ComponentInput } from "./inputs/component-input.js";
12
12
  import { ComponentPreviewActions } from "./component-preview-actions.js";
13
- import { htmlEscape } from "escape-goat";
13
+ import prettier from "prettier";
14
+ import hljs from "highlight.js";
14
15
 
15
16
  export const actionName = "Components";
16
17
 
@@ -102,7 +103,7 @@ export default abstract class JDDPage extends StatefulPage<
102
103
  loadSearchModal: false,
103
104
  },
104
105
  makeHead: (...args: unknown[]) =>
105
- tempstream/* HTML */ `${this.defaultHead(...args)}
106
+ tempstream /* HTML */ `${this.defaultHead(...args)}
106
107
  <link
107
108
  href="/dist/jdd-page.entrypoint.css"
108
109
  rel="stylesheet"
@@ -171,7 +172,7 @@ export default abstract class JDDPage extends StatefulPage<
171
172
  index: number
172
173
  ): Promise<FlatTemplatable> {
173
174
  const jdd_context = this.makeJDDContext(ctx);
174
- return tempstream/* HTML */ `<div
175
+ return tempstream /* HTML */ `<div
175
176
  class="component-preview-parameters"
176
177
  id="${`component-preview-parameters--${index}`}"
177
178
  >
@@ -238,7 +239,7 @@ export default abstract class JDDPage extends StatefulPage<
238
239
  ? await component.convertParsedToStorage(
239
240
  this.makeJDDContext(ctx),
240
241
  args
241
- )
242
+ )
242
243
  : {},
243
244
  };
244
245
  return single_result;
@@ -318,7 +319,7 @@ export default abstract class JDDPage extends StatefulPage<
318
319
  }
319
320
 
320
321
  async render(ctx: Context, state: JDDPageState): Promise<string> {
321
- return tempstream/* HTML */ `<div
322
+ return tempstream /* HTML */ `<div
322
323
  class="${["two-column", "component-debugger", ...this.classes].join(" ")}"
323
324
  id="component-debugger"
324
325
  style="${`--resizable-column-width: ${
@@ -400,15 +401,16 @@ export default abstract class JDDPage extends StatefulPage<
400
401
  class="dynamic"
401
402
  value="${state.preview_size}"
402
403
  selected
403
- >
404
+ >
404
405
  ${state.preview_size} px
405
- </option>`
406
+ </option>`
406
407
  : ""
407
408
  }
408
409
  ${this.previewSizes.map(
409
- (size) => /* HTML */ `<option value="${size}">
410
- ${`${size} px`}
411
- </option>`
410
+ (size) =>
411
+ /* HTML */ `<option value="${size}">
412
+ ${`${size} px`}
413
+ </option>`
412
414
  )}
413
415
  </select>
414
416
  <noscript>
@@ -454,6 +456,15 @@ export default abstract class JDDPage extends StatefulPage<
454
456
  documentContainerFromParsed(state.components),
455
457
  this.makeJDDContext(ctx)
456
458
  );
459
+
460
+ const currentComponentPrettified =
461
+ await prettier.format(currentComponent, {
462
+ parser: "html",
463
+ });
464
+ const highlightedHTML = hljs.highlight(
465
+ currentComponentPrettified,
466
+ { language: "html" }
467
+ ).value;
457
468
  return /* HTML */ ` <div
458
469
  class="jdd-outer-container"
459
470
  >
@@ -462,9 +473,7 @@ export default abstract class JDDPage extends StatefulPage<
462
473
  </div>
463
474
  </div>
464
475
  <div class="component-raw-view">
465
- <pre><code>${htmlEscape(
466
- currentComponent
467
- )}</code></pre>
476
+ <pre><code>${highlightedHTML}</code></pre>
468
477
  </div>`;
469
478
  })()}
470
479
  </div>