@sealcode/jdd-editor 0.2.0 → 0.2.4
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.
- package/.husky/pre-commit +1 -0
- package/@types/component-preview-actions.d.ts +2 -26
- package/@types/components.sreact.d.ts +2 -30
- package/@types/controllers/json-editor.stimulus.d.ts +2 -0
- package/@types/inputs/component-input-color.d.ts +15 -0
- package/@types/jdd-creator.d.ts +1 -25
- package/@types/jdd-page.d.ts +8 -32
- package/dist/src/component-preview-actions.js.map +2 -2
- package/dist/src/components.sreact.js +1 -14
- package/dist/src/components.sreact.js.map +2 -2
- package/dist/src/controllers/json-editor.stimulus.js +33 -23
- package/dist/src/controllers/json-editor.stimulus.js.map +2 -2
- package/dist/src/controllers/refresh-styles.stimulus.js +5 -5
- package/dist/src/controllers/refresh-styles.stimulus.js.map +2 -2
- package/dist/src/inputs/component-input-color.js +27 -0
- package/dist/src/inputs/component-input-color.js.map +7 -0
- package/dist/src/inputs/component-input.js +14 -1
- package/dist/src/inputs/component-input.js.map +2 -2
- package/dist/src/jdd-page.js +81 -49
- package/dist/src/jdd-page.js.map +2 -2
- package/package.json +6 -5
- package/src/component-preview-actions.ts +9 -6
- package/src/components.sreact.ts +1 -14
- package/src/controllers/json-editor.stimulus.ts +33 -20
- package/src/controllers/refresh-styles.stimulus.ts +5 -5
- package/src/inputs/component-input-color.ts +38 -0
- package/src/inputs/component-input.ts +15 -2
- package/src/jdd-page.ts +89 -55
- package/.nyc_output/2ad4e34c-cebb-4299-9698-08eccbbe71f7.json +0 -1
- package/.nyc_output/71f2685b-e2c9-4db2-9f31-0dbdcacfcea1.json +0 -1
- package/.nyc_output/cfebf13d-f940-426b-a4d3-af28d17bb6b8.json +0 -1
- package/.nyc_output/processinfo/2ad4e34c-cebb-4299-9698-08eccbbe71f7.json +0 -1
- package/.nyc_output/processinfo/71f2685b-e2c9-4db2-9f31-0dbdcacfcea1.json +0 -1
- package/.nyc_output/processinfo/cfebf13d-f940-426b-a4d3-af28d17bb6b8.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/.xunit +0 -2
- package/coverage/clover.xml +0 -866
package/src/jdd-page.ts
CHANGED
|
@@ -10,6 +10,7 @@ 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
14
|
|
|
14
15
|
export const actionName = "Components";
|
|
15
16
|
|
|
@@ -64,22 +65,9 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
64
65
|
return this.registry.getAll();
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
async getInitialState(ctx: Context) {
|
|
68
|
-
const all_components = Object.entries(this.getRegistryComponents());
|
|
69
|
-
const first_component = all_components[0];
|
|
70
|
-
if (!first_component) {
|
|
71
|
-
throw new Error("No defined components!");
|
|
72
|
-
}
|
|
73
|
-
const [component_name, component] = first_component;
|
|
68
|
+
async getInitialState(ctx: Context): Promise<JDDPageState> {
|
|
74
69
|
const initial_state = {
|
|
75
|
-
components: [
|
|
76
|
-
{
|
|
77
|
-
component_name: component_name,
|
|
78
|
-
args: await component.getExampleValues(
|
|
79
|
-
this.makeJDDContext(ctx)
|
|
80
|
-
),
|
|
81
|
-
},
|
|
82
|
-
],
|
|
70
|
+
components: [],
|
|
83
71
|
};
|
|
84
72
|
return initial_state;
|
|
85
73
|
}
|
|
@@ -267,7 +255,7 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
267
255
|
async deserializeState(ctx: Context, state_string: string) {
|
|
268
256
|
const jdd_context = this.makeJDDContext(ctx);
|
|
269
257
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
270
|
-
const raw = JSON.parse(state_string)
|
|
258
|
+
const raw = JSON.parse(state_string) as Record<string, unknown>;
|
|
271
259
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
272
260
|
const components_storage = raw.components;
|
|
273
261
|
if (!Array.isArray(components_storage)) {
|
|
@@ -331,9 +319,7 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
331
319
|
|
|
332
320
|
async render(ctx: Context, state: JDDPageState): Promise<string> {
|
|
333
321
|
return tempstream/* HTML */ `<div
|
|
334
|
-
class="${["two-column", "component-debugger", ...this.classes].join(
|
|
335
|
-
" "
|
|
336
|
-
)}"
|
|
322
|
+
class="${["two-column", "component-debugger", ...this.classes].join(" ")}"
|
|
337
323
|
id="component-debugger"
|
|
338
324
|
style="${`--resizable-column-width: ${
|
|
339
325
|
state.preview_size ? state.preview_size + "px" : "50vw"
|
|
@@ -367,8 +353,8 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
367
353
|
id="component-debugger-json-textarea"
|
|
368
354
|
autocomplete="off"
|
|
369
355
|
>
|
|
370
|
-
|
|
371
|
-
|
|
356
|
+
${(await this.serializeState(ctx, state, true)).replaceAll("<", "<")}
|
|
357
|
+
</textarea
|
|
372
358
|
>
|
|
373
359
|
${this.makeActionButton(state, {
|
|
374
360
|
action: "replace_state",
|
|
@@ -398,41 +384,89 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
398
384
|
id="component-preview__header"
|
|
399
385
|
class="component-preview__header"
|
|
400
386
|
>
|
|
401
|
-
<
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
387
|
+
<div class="component-preview__item">
|
|
388
|
+
<span>Window size</span>
|
|
389
|
+
<select
|
|
390
|
+
name="$[preview_size]"
|
|
391
|
+
autocomplete="off"
|
|
392
|
+
class="component-preview-size-select"
|
|
393
|
+
data-component-debugger-target="sizeSelect"
|
|
394
|
+
data-action="change->component-debugger#handleWidthDropdown"
|
|
395
|
+
data-turbo-data-turbo-permanent
|
|
396
|
+
>
|
|
397
|
+
${
|
|
398
|
+
state.preview_size
|
|
399
|
+
? /* HTML */ `<option
|
|
400
|
+
class="dynamic"
|
|
401
|
+
value="${state.preview_size}"
|
|
402
|
+
selected
|
|
403
|
+
>
|
|
404
|
+
${state.preview_size} px
|
|
405
|
+
</option>`
|
|
406
|
+
: ""
|
|
407
|
+
}
|
|
408
|
+
${this.previewSizes.map(
|
|
409
|
+
(size) => /* HTML */ `<option value="${size}">
|
|
410
|
+
${`${size} px`}
|
|
411
|
+
</option>`
|
|
412
|
+
)}
|
|
413
|
+
</select>
|
|
414
|
+
<noscript>
|
|
415
|
+
${this.makeActionButton(state, "change_size")}
|
|
416
|
+
</noscript>
|
|
417
|
+
</div>
|
|
418
|
+
<style>
|
|
419
|
+
.component-preview .component-raw-view {
|
|
420
|
+
display: none;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.component-preview .jdd-outer-container {
|
|
424
|
+
display: block;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.component-preview:has(
|
|
428
|
+
.component-preview-checkbox:checked
|
|
429
|
+
)
|
|
430
|
+
.component-raw-view {
|
|
431
|
+
display: block;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.component-preview:has(
|
|
435
|
+
.component-preview-checkbox:checked
|
|
436
|
+
)
|
|
437
|
+
.jdd-outer-container {
|
|
438
|
+
display: none;
|
|
439
|
+
}
|
|
440
|
+
</style>
|
|
441
|
+
<label class="component-preview__item" for="show-html">
|
|
442
|
+
Show HTML
|
|
443
|
+
<input
|
|
444
|
+
type="checkbox"
|
|
445
|
+
id="show-html"
|
|
446
|
+
class="component-preview-checkbox"
|
|
447
|
+
/>
|
|
448
|
+
</label>
|
|
428
449
|
</div>
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
450
|
+
|
|
451
|
+
${(async () => {
|
|
452
|
+
const currentComponent = await JDD.render(
|
|
453
|
+
this.registry,
|
|
454
|
+
documentContainerFromParsed(state.components),
|
|
455
|
+
this.makeJDDContext(ctx)
|
|
456
|
+
);
|
|
457
|
+
return /* HTML */ ` <div
|
|
458
|
+
class="jdd-outer-container"
|
|
459
|
+
>
|
|
460
|
+
<div class="jdd-container">
|
|
461
|
+
${currentComponent}
|
|
462
|
+
</div>
|
|
463
|
+
</div>
|
|
464
|
+
<div class="component-raw-view">
|
|
465
|
+
<pre><code>${htmlEscape(
|
|
466
|
+
currentComponent
|
|
467
|
+
)}</code></pre>
|
|
468
|
+
</div>`;
|
|
469
|
+
})()}
|
|
436
470
|
</div>
|
|
437
471
|
</div>
|
|
438
472
|
</div>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|