@sealcode/jdd-editor 0.2.14 → 0.2.16
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/.nyc_output/51efb67f-ce86-4cce-8246-d293600e6ff2.json +1 -0
- package/.nyc_output/processinfo/0553c492-d66d-4588-be20-d4a284e17ff7.json +1 -0
- package/.nyc_output/processinfo/15c7e9a9-1ea9-4c86-8310-45fa6fc6e38b.json +1 -0
- package/.nyc_output/processinfo/51efb67f-ce86-4cce-8246-d293600e6ff2.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/.xunit +1 -1
- package/@types/components.sreact.d.ts +1 -1
- package/@types/controllers/code-snippet.stimulus.d.ts +6 -0
- package/@types/controllers/json-editor.stimulus.d.ts +0 -1
- package/@types/inputs/component-input-code-with-custom-language.d.ts +7 -0
- package/@types/inputs/component-input-code.d.ts +3 -1
- package/@types/inputs/component-input-list.d.ts +3 -2
- package/@types/inputs/component-input-structured.d.ts +3 -2
- package/@types/inputs/component-input-table.d.ts +3 -2
- package/@types/inputs/component-input.d.ts +3 -2
- package/@types/jdd-creator.d.ts +2 -2
- package/@types/jdd-page.d.ts +4 -2
- package/assets/styles/components.jdd-page.css +5 -2
- package/coverage/clover.xml +173 -170
- package/dist/src/controllers/code-snippet.stimulus.js +12 -0
- package/dist/src/controllers/code-snippet.stimulus.js.map +7 -0
- package/dist/src/controllers/exportable-textarea.stimulus.js +0 -1
- package/dist/src/controllers/exportable-textarea.stimulus.js.map +2 -2
- package/dist/src/controllers/json-editor.stimulus.js +0 -3
- package/dist/src/controllers/json-editor.stimulus.js.map +2 -2
- package/dist/src/edit-jdd-field.js +3 -5
- package/dist/src/edit-jdd-field.js.map +2 -2
- package/dist/src/inputs/component-input-code-with-custom-language.js +41 -0
- package/dist/src/inputs/component-input-code-with-custom-language.js.map +7 -0
- package/dist/src/inputs/component-input-code.js +22 -11
- package/dist/src/inputs/component-input-code.js.map +2 -2
- package/dist/src/inputs/component-input-list.js +3 -1
- package/dist/src/inputs/component-input-list.js.map +2 -2
- package/dist/src/inputs/component-input-structured.js +2 -0
- package/dist/src/inputs/component-input-structured.js.map +2 -2
- package/dist/src/inputs/component-input-table.js +6 -3
- package/dist/src/inputs/component-input-table.js.map +2 -2
- package/dist/src/inputs/component-input.js +22 -6
- package/dist/src/inputs/component-input.js.map +2 -2
- package/dist/src/jdd-page.js +24 -12
- package/dist/src/jdd-page.js.map +2 -2
- package/package.json +2 -2
- package/src/controllers/code-snippet.stimulus.ts +12 -0
- package/src/controllers/exportable-textarea.stimulus.ts +0 -1
- package/src/controllers/json-editor.stimulus.ts +0 -4
- package/src/edit-jdd-field.ts +3 -5
- package/src/inputs/component-input-code-with-custom-language.ts +44 -0
- package/src/inputs/component-input-code.ts +23 -10
- package/src/inputs/component-input-list.ts +9 -1
- package/src/inputs/component-input-structured.ts +4 -0
- package/src/inputs/component-input-table.ts +5 -1
- package/src/inputs/component-input.ts +31 -1
- package/src/jdd-page.ts +31 -13
- package/.nyc_output/b318e449-cc0d-49b3-8647-15d9173f5905.json +0 -1
- package/.nyc_output/processinfo/65a49023-1c6a-4217-ab3e-89a09cde8bfc.json +0 -1
- package/.nyc_output/processinfo/b318e449-cc0d-49b3-8647-15d9173f5905.json +0 -1
- package/.nyc_output/processinfo/be222db4-3db9-4c08-a4b5-58673c1c7c29.json +0 -1
- /package/.nyc_output/{65a49023-1c6a-4217-ab3e-89a09cde8bfc.json → 0553c492-d66d-4588-be20-d4a284e17ff7.json} +0 -0
- /package/.nyc_output/{be222db4-3db9-4c08-a4b5-58673c1c7c29.json → 15c7e9a9-1ea9-4c86-8310-45fa6fc6e38b.json} +0 -0
package/dist/src/jdd-page.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/jdd-page.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport type { Readable } from \"node:stream\";\nimport type { Component, JDDContext, RawJDDocument } from \"@sealcode/jdd\";\nimport { documentContainerFromParsed, Registry } from \"@sealcode/jdd\";\nimport { JDD } from \"@sealcode/jdd\";\nimport { StatefulPage } from \"@sealcode/sealgen\";\nimport { hasFieldOfType, hasShape, predicates } from \"@sealcode/ts-predicates\";\nimport type { Context } from \"koa\";\nimport type { FlatTemplatable, Templatable } from \"tempstream\";\nimport { tempstream } from \"tempstream\";\nimport { ComponentInput } from \"./inputs/component-input.js\";\nimport { ComponentPreviewActions } from \"./component-preview-actions.js\";\nimport prettier from \"prettier\";\nimport hljs from \"highlight.js\";\n\nexport const actionName = \"Components\";\n\nexport type JDDPageState = {\n\tcomponents: RawJDDocument;\n\tpreview_size?: string;\n\tmessages?: string[];\n};\n\nexport default abstract class JDDPage extends StatefulPage<\n\tJDDPageState,\n\ttypeof ComponentPreviewActions\n> {\n\tactions = ComponentPreviewActions;\n\n\tpreviewSizes = [\"320\", \"600\", \"800\", \"1024\", \"1300\", \"1920\"];\n\tclasses: string[] = [];\n\n\tpublic registry: Registry;\n\tpublic makeJDDContext: (ctx: Context) => JDDContext;\n\tpublic html: (\n\t\targs: unknown\n\t) => string | Promise<string> | Readable | Promise<Readable>;\n\tpublic defaultHead: (\n\t\t...args: unknown[]\n\t) => string | Promise<string> | Readable | Promise<Readable>;\n\tpublic makeAssetURL: (asset: string) => string;\n\n\tconstructor(args: {\n\t\tregistry: Registry;\n\t\tmakeJDDContext: (ctx: Context) => JDDContext;\n\t\thtml: (\n\t\t\targs: unknown\n\t\t) => string | Promise<string> | Readable | Promise<Readable>;\n\t\tdefaultHead: (\n\t\t\t...args: unknown[]\n\t\t) => string | Promise<string> | Readable | Promise<Readable>;\n\t\tmakeAssetURL?: (asset: string) => string;\n\t}) {\n\t\tsuper();\n\t\tthis.registry = args.registry;\n\t\tthis.makeJDDContext = args.makeJDDContext;\n\t\tthis.defaultHead = args.defaultHead;\n\t\tthis.html = args.html;\n\t\tthis.makeAssetURL =\n\t\t\targs.makeAssetURL ||\n\t\t\t((str) =>\n\t\t\t\t`/dist/jdd-page/${str.startsWith(\"/\") ? str.slice(1) : str}`);\n\t}\n\n\tgetRegistryComponents() {\n\t\treturn this.registry.getAll();\n\t}\n\n\tasync getInitialState(ctx: Context): Promise<JDDPageState> {\n\t\tconst initial_state = {\n\t\t\tcomponents: [],\n\t\t};\n\t\treturn initial_state;\n\t}\n\n\twrapInLayout(\n\t\tctx: Context,\n\t\tcontent: Templatable,\n\t\tstate: JDDPageState\n\t): Templatable {\n\t\tconst jdd_context = this.makeJDDContext(ctx);\n\t\tconst jdd = new JDD(\n\t\t\tthis.registry,\n\t\t\tjdd_context,\n\t\t\tdocumentContainerFromParsed(state.components)\n\t\t);\n\t\treturn this.html({\n\t\t\tctx,\n\t\t\ttitle: \"Components\",\n\t\t\tbody: content,\n\t\t\tdescription: \"\",\n\t\t\tcss_clumps: [\"jdd-page\", ...jdd.getAllCSSClumps()],\n\t\t\thtmlOptions: {\n\t\t\t\tmorphing: true,\n\t\t\t\tpreserveScroll: true,\n\t\t\t\tautoRefreshCSS: false,\n\t\t\t\tnavbar: () => ``,\n\t\t\t\tbodyClasses: [\"jdd-editor\"],\n\t\t\t\tshowBottomNavbar: false,\n\t\t\t\tshowBanner: false,\n\t\t\t\tshowFooter: false,\n\t\t\t\tloadHamburgerMenu: false,\n\t\t\t\tloadSearchModal: false,\n\t\t\t},\n\t\t\tmakeHead: (...args: unknown[]) =>\n\t\t\t\ttempstream /* HTML */ `${this.defaultHead(...args)}\n\t\t\t\t\t<link\n\t\t\t\t\t\thref=\"/dist/jdd-page.entrypoint.css\"\n\t\t\t\t\t\trel=\"stylesheet\"\n\t\t\t\t\t\ttype=\"text/css\"\n\t\t\t\t\t/>\n\t\t\t\t\t${jdd.renderEarlyAssets()}`,\n\t\t});\n\t}\n\n\tasync preprocessOverrides(\n\t\t_ctx: Context,\n\t\tstate: JDDPageState,\n\t\toverrides: Record<string, unknown>\n\t) {\n\t\tconst jdd_context = this.makeJDDContext(_ctx);\n\t\tif (\n\t\t\t!hasFieldOfType(\n\t\t\t\t\"components\",\n\t\t\t\toverrides,\n\t\t\t\tpredicates.array(\n\t\t\t\t\tpredicates.shape({\n\t\t\t\t\t\targs: predicates.object,\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t)\n\t\t) {\n\t\t\treturn {};\n\t\t}\n\t\tfor (const [component_index, { component_name }] of Object.entries(\n\t\t\tstate.components\n\t\t)) {\n\t\t\tconst component = this.registry.get(component_name);\n\t\t\tif (!component) {\n\t\t\t\tthrow new Error(`Unknown component: ${component_name}`);\n\t\t\t}\n\t\t\tconst overrides_for_component = overrides.components[\n\t\t\t\tparseInt(component_index)\n\t\t\t] || { args: {} };\n\t\t\tconst promises = Object.entries(component.getArguments()).map(\n\t\t\t\tasync ([arg_name, arg]) => {\n\t\t\t\t\tconst value = overrides_for_component.args[arg_name];\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tconst new_value = await arg.receivedToParsed(\n\t\t\t\t\t\t\tjdd_context,\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\toverrides_for_component.args[arg_name] = new_value;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\tawait Promise.all(promises);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn overrides;\n\t}\n\n\t// eslint-disable-next-line no-unused-vars\n\tabstract renderParameterButtons(_state: JDDPageState): FlatTemplatable;\n\n\tasync renderComponentArgs<C extends Component>(\n\t\tctx: Context,\n\t\tstate: JDDPageState,\n\t\tcomponent: C,\n\t\targs: Record<string, unknown>,\n\t\tindex: number\n\t): Promise<FlatTemplatable> {\n\t\tconst jdd_context = this.makeJDDContext(ctx);\n\t\treturn tempstream /* HTML */ `<div\n\t\t\tclass=\"component-preview-parameters\"\n\t\t\tid=\"${`component-preview-parameters--${index}`}\"\n\t\t>\n\t\t\t${Object.entries(component.getArguments()).map(\n\t\t\t\tasync ([arg_name, arg]) =>\n\t\t\t\t\tComponentInput({\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\targ_path: [\n\t\t\t\t\t\t\t\"components\",\n\t\t\t\t\t\t\tindex.toString(),\n\t\t\t\t\t\t\t\"args\",\n\t\t\t\t\t\t\targ_name,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\targ,\n\t\t\t\t\t\tvalue:\n\t\t\t\t\t\t\targs[arg_name] === undefined ||\n\t\t\t\t\t\t\tcomponent\n\t\t\t\t\t\t\t\t.getArguments()\n\t\t\t\t\t\t\t\t[arg_name]?.isEmpty(args[arg_name])\n\t\t\t\t\t\t\t\t? await arg.getExampleValue(jdd_context)\n\t\t\t\t\t\t\t\t: args[arg_name],\n\t\t\t\t\t\tpage: this,\n\t\t\t\t\t\tmakeJDDContext: this.makeJDDContext,\n\t\t\t\t\t\tmakeAssetURL: this.makeAssetURL,\n\t\t\t\t\t})\n\t\t\t)}\n\t\t</div>`;\n\t}\n\n\trenderComponentBlock(\n\t\tctx: Context,\n\t\tstate: JDDPageState,\n\t\t{\n\t\t\tcomponent_name,\n\t\t\targs: component_args,\n\t\t}: {\n\t\t\tcomponent_name: string;\n\t\t\targs: Record<string, unknown>;\n\t\t},\n\t\tcomponent_index: number\n\t) {\n\t\tconst component = this.registry.get(component_name);\n\t\tif (!component) {\n\t\t\treturn null;\n\t\t}\n\t\treturn this.renderComponentArgs(\n\t\t\tctx,\n\t\t\tstate,\n\t\t\tcomponent,\n\t\t\tcomponent_args,\n\t\t\tcomponent_index\n\t\t);\n\t}\n\n\tasync serializeState(ctx: Context, state: JDDPageState, pretty = false) {\n\t\tconst serialized_components = await Promise.all(\n\t\t\tstate.components.map(async ({ component_name, args }) => {\n\t\t\t\tconst component = this.registry.get(component_name);\n\t\t\t\tconst single_result = {\n\t\t\t\t\tcomponent_name,\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\t\t\t\targs: component\n\t\t\t\t\t\t? await component.convertParsedToStorage(\n\t\t\t\t\t\t\t\tthis.makeJDDContext(ctx),\n\t\t\t\t\t\t\t\targs\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: {},\n\t\t\t\t};\n\t\t\t\treturn single_result;\n\t\t\t})\n\t\t);\n\t\tconst serialized_state = JSON.stringify(\n\t\t\t{ ...state, components: serialized_components },\n\t\t\tnull,\n\t\t\tpretty ? 4 : \"\"\n\t\t);\n\t\treturn serialized_state;\n\t}\n\n\tasync deserializeState(ctx: Context, state_string: string) {\n\t\tconst jdd_context = this.makeJDDContext(ctx);\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\tconst raw = JSON.parse(state_string) as Record<string, unknown>;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\tconst components_storage = raw.components;\n\t\tif (!Array.isArray(components_storage)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"'components' key is not an array, got ${components_storage}\"\n\t\t\t);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\tconst components_parsed = await Promise.all(\n\t\t\tcomponents_storage.map(async (entry) => {\n\t\t\t\tif (\n\t\t\t\t\t!hasShape(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcomponent_name: predicates.string,\n\t\t\t\t\t\t\targs: predicates.object,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tentry\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Expected components[] items to be objects with 'component_name' and 'args' keys, got ${entry}`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst { component_name, args } = entry;\n\t\t\t\tconst component = this.registry.get(component_name);\n\t\t\t\tif (!component) {\n\t\t\t\t\tthrow new Error(\"Unknown component: ${component_name}\");\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcomponent_name,\n\t\t\t\t\targs: await component.convertStorageToParsed(\n\t\t\t\t\t\tjdd_context,\n\t\t\t\t\t\targs\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t})\n\t\t);\n\t\tconst result = { ...raw, components: components_parsed };\n\t\treturn result;\n\t}\n\n\trenderPreParameterButtons(\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t_ctx: Context,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t_state: JDDPageState\n\t): FlatTemplatable | Promise<FlatTemplatable> {\n\t\treturn \"\";\n\t}\n\n\trenderMessages(_ctx: Context, state: JDDPageState) {\n\t\treturn /* HTML */ `<ul\n\t\t\tclass=\"jdd-editor__messages\"\n\t\t\tdata-controller=\"toast\"\n\t\t>\n\t\t\t${(state.messages || []).map(\n\t\t\t\t(e) => `<li class=\"jdd-editor__message\">${e}</li>`\n\t\t\t)}\n\t\t</ul>`;\n\t}\n\n\tasync render(ctx: Context, state: JDDPageState): Promise<string> {\n\t\treturn tempstream /* HTML */ `<div\n\t\t\tclass=\"${[\"two-column\", \"component-debugger\", ...this.classes].join(\" \")}\"\n\t\t\tid=\"component-debugger\"\n\t\t\tstyle=\"${`--resizable-column-width: ${\n\t\t\t\tstate.preview_size ? state.preview_size + \"px\" : \"50vw\"\n\t\t\t}`}\"\n\t\t\tdata-controller=\"component-debugger\"\n\t\t>\n\t\t\t<div class=\"component-arguments\" id=\"component-arguments\">\n\t\t\t\t${this.renderPreParameterButtons(ctx, state)}\n\t\t\t\t${this.renderParameterButtons(state)}\n\t\t\t\t${this.renderMessages(ctx, state)}\n\t\t\t\t${state.components.map((component, component_index) =>\n\t\t\t\t\tthis.renderComponentBlock(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\tcomponent_index\n\t\t\t\t\t)\n\t\t\t\t)}\n\t\t\t\t<details\n\t\t\t\t\tclass=\"component-debugger__json\"\n\t\t\t\t\tdata-controller=\"exportable-textarea\"\n\t\t\t\t\tid=\"exportable-textarea\"\n\t\t\t\t\topen\n\t\t\t\t>\n\t\t\t\t\t<summary>Edit/Export raw JSON</summary>\n\t\t\t\t\t<textarea\n\t\t\t\t\t\tname=\"state_override\"\n\t\t\t\t\t\trows=\"40\"\n\t\t\t\t\t\tcols=\"40\"\n\t\t\t\t\t\tdata-controller=\"json-editor\"\n\t\t\t\t\t\tid=\"component-debugger-json-textarea\"\n\t\t\t\t\t\tautocomplete=\"off\"\n\t\t\t\t\t>\n\t\t\t\t\t\t${(await this.serializeState(ctx, state, true)).replaceAll(\"<\", \"<\")}\n\t\t\t\t\t</textarea\n\t\t\t\t\t>\n\t\t\t\t\t${this.makeActionButton(state, {\n\t\t\t\t\t\taction: \"replace_state\",\n\t\t\t\t\t\tlabel: \"Apply\",\n\t\t\t\t\t})}\n\t\t\t\t\t<button data-action=\"exportable-textarea#copy\">Copy</button>\n\t\t\t\t\t<button data-action=\"exportable-textarea#download\">\n\t\t\t\t\t\tDownload\n\t\t\t\t\t</button>\n\t\t\t\t\t<input type=\"file\" />${\" \"}\n\t\t\t\t\t<button data-action=\"exportable-textarea#import\">\n\t\t\t\t\t\tImport\n\t\t\t\t\t</button>\n\t\t\t\t</details>\n\t\t\t</div>\n\t\t\t<div\n\t\t\t\tid=\"resize-gutter\"\n\t\t\t\tclass=\"resize-gutter\"\n\t\t\t\tdata-component-debugger-target=\"gutter\"\n\t\t\t></div>\n\t\t\t<div\n\t\t\t\tid=\"component-preview\"\n\t\t\t\tclass=\"component-preview\"\n\t\t\t\tdata-component-debugger-target=\"preview\"\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tid=\"component-preview__header\"\n\t\t\t\t\tclass=\"component-preview__header\"\n\t\t\t\t>\n\t\t\t\t\t<div class=\"component-preview__item\">\n\t\t\t\t\t\t<span>Window size</span>\n\t\t\t\t\t\t<select\n\t\t\t\t\t\t\tname=\"$[preview_size]\"\n\t\t\t\t\t\t\tautocomplete=\"off\"\n\t\t\t\t\t\t\tclass=\"component-preview-size-select\"\n\t\t\t\t\t\t\tdata-component-debugger-target=\"sizeSelect\"\n\t\t\t\t\t\t\tdata-action=\"change->component-debugger#handleWidthDropdown\"\n\t\t\t\t\t\t\tdata-turbo-permanent\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t${\n\t\t\t\t\t\t\t\tstate.preview_size\n\t\t\t\t\t\t\t\t\t? /* HTML */ `<option\n\t\t\t\t\t\t\t\t\t\t\tclass=\"dynamic\"\n\t\t\t\t\t\t\t\t\t\t\tvalue=\"${state.preview_size}\"\n\t\t\t\t\t\t\t\t\t\t\tselected\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t${state.preview_size} px\n\t\t\t\t\t\t\t\t\t\t</option>`\n\t\t\t\t\t\t\t\t\t: \"\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t${this.previewSizes.map(\n\t\t\t\t\t\t\t\t(size) =>\n\t\t\t\t\t\t\t\t\t/* HTML */ `<option value=\"${size}\">\n\t\t\t\t\t\t\t\t\t\t${`${size} px`}\n\t\t\t\t\t\t\t\t\t</option>`\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</select>\n\t\t\t\t\t\t<noscript>\n\t\t\t\t\t\t\t${this.makeActionButton(state, \"change_size\")}\n\t\t\t\t\t\t</noscript>\n\t\t\t\t\t</div>\n\t\t\t\t\t<style>\n\t\t\t\t\t\t.component-preview .component-raw-view {\n\t\t\t\t\t\t\tdisplay: none;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t.component-preview .jdd-outer-container {\n\t\t\t\t\t\t\tdisplay: block;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t.component-preview:has(\n\t\t\t\t\t\t\t\t.component-preview-checkbox:checked\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.component-raw-view {\n\t\t\t\t\t\t\tdisplay: block;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t.component-preview:has(\n\t\t\t\t\t\t\t\t.component-preview-checkbox:checked\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.jdd-outer-container {\n\t\t\t\t\t\t\tdisplay: none;\n\t\t\t\t\t\t}\n\t\t\t\t\t</style>\n\t\t\t\t\t<label class=\"component-preview__item\" for=\"show-html\">\n\t\t\t\t\t\tShow HTML\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\t\t\tid=\"show-html\"\n\t\t\t\t\t\t\tclass=\"component-preview-checkbox\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</label>\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t\t\t${(async () => {\n\t\t\t\t\t\t\tconst currentComponent = await JDD.render(\n\t\t\t\t\t\t\t\tthis.registry,\n\t\t\t\t\t\t\t\tdocumentContainerFromParsed(state.components),\n\t\t\t\t\t\t\t\tthis.makeJDDContext(ctx)\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tlet currentComponentPrettified = currentComponent;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tcurrentComponentPrettified =\n\t\t\t\t\t\t\t\t\tawait prettier.format(currentComponent, {\n\t\t\t\t\t\t\t\t\t\tparser: \"html\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t\t\"JDD editor: couldn't format the html\"\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst highlightedHTML = hljs.highlight(\n\t\t\t\t\t\t\t\tcurrentComponentPrettified,\n\t\t\t\t\t\t\t\t{ language: \"html\" }\n\t\t\t\t\t\t\t).value;\n\t\t\t\t\t\t\treturn /* HTML */ ` <div\n\t\t\t\t\t\t\t\t\tclass=\"jdd-outer-container\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<div class=\"jdd-container\">\n\t\t\t\t\t\t\t\t\t\t${currentComponent}\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<div class=\"component-raw-view\">\n\t\t\t\t\t\t\t\t\t<pre><code>${highlightedHTML}</code></pre>\n\t\t\t\t\t\t\t\t</div>`;\n\t\t\t\t\t\t})()}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>`;\n\t}\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,mCAA6C;AACtD,SAAS,WAAW;AACpB,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB,UAAU,kBAAkB;AAGrD,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,+BAA+B;AACxC,OAAO,cAAc;AACrB,OAAO,UAAU;AAEV,MAAM,aAAa;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport type { Readable } from \"node:stream\";\nimport type { Component, JDDContext, RawJDDocument } from \"@sealcode/jdd\";\nimport { documentContainerFromParsed, Registry } from \"@sealcode/jdd\";\nimport { JDD } from \"@sealcode/jdd\";\nimport { StatefulPage } from \"@sealcode/sealgen\";\nimport { hasFieldOfType, hasShape, predicates } from \"@sealcode/ts-predicates\";\nimport type { Context } from \"koa\";\nimport type { FlatTemplatable, Templatable } from \"tempstream\";\nimport { tempstream } from \"tempstream\";\nimport { ComponentInput } from \"./inputs/component-input.js\";\nimport { ComponentPreviewActions } from \"./component-preview-actions.js\";\nimport prettier from \"prettier\";\nimport hljs from \"highlight.js\";\n\nexport const actionName = \"Components\";\n\nexport type JDDPageState = {\n\tcomponents: RawJDDocument;\n\tpreview_size?: string;\n};\n\nexport default abstract class JDDPage extends StatefulPage<\n\tJDDPageState,\n\ttypeof ComponentPreviewActions\n> {\n\tactions = ComponentPreviewActions;\n\n\tpreviewSizes = [\"320\", \"600\", \"800\", \"1024\", \"1300\", \"1920\"];\n\tclasses: string[] = [];\n\n\tpublic registry: Registry;\n\tpublic makeJDDContext: (ctx: Context) => JDDContext;\n\tpublic html: (\n\t\targs: unknown\n\t) => string | Promise<string> | Readable | Promise<Readable>;\n\tpublic defaultHead: (\n\t\t...args: unknown[]\n\t) => string | Promise<string> | Readable | Promise<Readable>;\n\tpublic makeAssetURL: (asset: string) => string;\n\n\tconstructor(args: {\n\t\tregistry: Registry;\n\t\tmakeJDDContext: (ctx: Context) => JDDContext;\n\t\thtml: (\n\t\t\targs: unknown\n\t\t) => string | Promise<string> | Readable | Promise<Readable>;\n\t\tdefaultHead: (\n\t\t\t...args: unknown[]\n\t\t) => string | Promise<string> | Readable | Promise<Readable>;\n\t\tmakeAssetURL?: (asset: string) => string;\n\t}) {\n\t\tsuper();\n\t\tthis.registry = args.registry;\n\t\tthis.makeJDDContext = args.makeJDDContext;\n\t\tthis.defaultHead = args.defaultHead;\n\t\tthis.html = args.html;\n\t\tthis.makeAssetURL =\n\t\t\targs.makeAssetURL ||\n\t\t\t((str) =>\n\t\t\t\t`/dist/jdd-page/${str.startsWith(\"/\") ? str.slice(1) : str}`);\n\t}\n\n\tgetRegistryComponents() {\n\t\treturn this.registry.getAll();\n\t}\n\n\tasync getInitialState(ctx: Context): Promise<JDDPageState> {\n\t\tconst initial_state = {\n\t\t\tcomponents: [],\n\t\t};\n\t\treturn initial_state;\n\t}\n\n\twrapInLayout(\n\t\tctx: Context,\n\t\tcontent: Templatable,\n\t\tstate: JDDPageState\n\t): Templatable {\n\t\tconst jdd_context = this.makeJDDContext(ctx);\n\t\tconst jdd = new JDD(\n\t\t\tthis.registry,\n\t\t\tjdd_context,\n\t\t\tdocumentContainerFromParsed(state.components)\n\t\t);\n\t\treturn this.html({\n\t\t\tctx,\n\t\t\ttitle: \"Components\",\n\t\t\tbody: content,\n\t\t\tdescription: \"\",\n\t\t\tcss_clumps: [\"jdd-page\", ...jdd.getAllCSSClumps()],\n\t\t\thtmlOptions: {\n\t\t\t\tmorphing: true,\n\t\t\t\tpreserveScroll: true,\n\t\t\t\tautoRefreshCSS: false,\n\t\t\t\tnavbar: () => ``,\n\t\t\t\tbodyClasses: [\"jdd-editor\"],\n\t\t\t\tshowBottomNavbar: false,\n\t\t\t\tshowBanner: false,\n\t\t\t\tshowFooter: false,\n\t\t\t\tloadHamburgerMenu: false,\n\t\t\t\tloadSearchModal: false,\n\t\t\t},\n\t\t\tmakeHead: (...args: unknown[]) =>\n\t\t\t\ttempstream /* HTML */ `${this.defaultHead(...args)}\n\t\t\t\t\t<link\n\t\t\t\t\t\thref=\"/dist/jdd-page.entrypoint.css\"\n\t\t\t\t\t\trel=\"stylesheet\"\n\t\t\t\t\t\ttype=\"text/css\"\n\t\t\t\t\t/>\n\t\t\t\t\t${jdd.renderEarlyAssets()}`,\n\t\t});\n\t}\n\n\tasync preprocessOverrides(\n\t\t_ctx: Context,\n\t\tstate: JDDPageState,\n\t\toverrides: Record<string, unknown>\n\t) {\n\t\tconst jdd_context = this.makeJDDContext(_ctx);\n\t\tif (\n\t\t\t!hasFieldOfType(\n\t\t\t\t\"components\",\n\t\t\t\toverrides,\n\t\t\t\tpredicates.array(\n\t\t\t\t\tpredicates.shape({\n\t\t\t\t\t\targs: predicates.object,\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t)\n\t\t) {\n\t\t\treturn {};\n\t\t}\n\t\tfor (const [component_index, { component_name }] of Object.entries(\n\t\t\tstate.components\n\t\t)) {\n\t\t\tconst component = this.registry.get(component_name);\n\t\t\tif (!component) {\n\t\t\t\tthrow new Error(`Unknown component: ${component_name}`);\n\t\t\t}\n\t\t\tconst overrides_for_component = overrides.components[\n\t\t\t\tparseInt(component_index)\n\t\t\t] || { args: {} };\n\t\t\tconst promises = Object.entries(component.getArguments()).map(\n\t\t\t\tasync ([arg_name, arg]) => {\n\t\t\t\t\tconst value = overrides_for_component.args[arg_name];\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tconst new_value = await arg.receivedToParsed(\n\t\t\t\t\t\t\tjdd_context,\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\toverrides_for_component.args[arg_name] = new_value;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\tawait Promise.all(promises);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn overrides;\n\t}\n\n\t// eslint-disable-next-line no-unused-vars\n\tabstract renderParameterButtons(_state: JDDPageState): FlatTemplatable;\n\n\tasync renderComponentArgs<C extends Component>(\n\t\tctx: Context,\n\t\tstate: JDDPageState,\n\t\tcomponent: C,\n\t\targs: Record<string, unknown>,\n\t\tindex: number\n\t): Promise<FlatTemplatable> {\n\t\tconst jdd_context = this.makeJDDContext(ctx);\n\t\treturn tempstream /* HTML */ `<div\n\t\t\tclass=\"component-preview-parameters\"\n\t\t\tid=\"${`component-preview-parameters--${index}`}\"\n\t\t>\n\t\t\t${Object.entries(component.getArguments()).map(\n\t\t\t\tasync ([arg_name, arg]) =>\n\t\t\t\t\tComponentInput({\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\targ_path: [\n\t\t\t\t\t\t\t\"components\",\n\t\t\t\t\t\t\tindex.toString(),\n\t\t\t\t\t\t\t\"args\",\n\t\t\t\t\t\t\targ_name,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\targ,\n\t\t\t\t\t\tvalue:\n\t\t\t\t\t\t\targs[arg_name] === undefined ||\n\t\t\t\t\t\t\tcomponent\n\t\t\t\t\t\t\t\t.getArguments()\n\t\t\t\t\t\t\t\t[arg_name]?.isEmpty(args[arg_name])\n\t\t\t\t\t\t\t\t? await arg.getExampleValue(jdd_context)\n\t\t\t\t\t\t\t\t: args[arg_name],\n\t\t\t\t\t\tpage: this,\n\t\t\t\t\t\tmakeJDDContext: this.makeJDDContext,\n\t\t\t\t\t\tmakeAssetURL: this.makeAssetURL,\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t})\n\t\t\t)}\n\t\t</div>`;\n\t}\n\n\trenderComponentBlock(\n\t\tctx: Context,\n\t\tstate: JDDPageState,\n\t\t{\n\t\t\tcomponent_name,\n\t\t\targs: component_args,\n\t\t}: {\n\t\t\tcomponent_name: string;\n\t\t\targs: Record<string, unknown>;\n\t\t},\n\t\tcomponent_index: number\n\t) {\n\t\tconst component = this.registry.get(component_name);\n\t\tif (!component) {\n\t\t\treturn null;\n\t\t}\n\t\treturn this.renderComponentArgs(\n\t\t\tctx,\n\t\t\tstate,\n\t\t\tcomponent,\n\t\t\tcomponent_args,\n\t\t\tcomponent_index\n\t\t);\n\t}\n\n\tasync serializeState(ctx: Context, state: JDDPageState, pretty = false) {\n\t\tconst serialized_components = await Promise.all(\n\t\t\tstate.components.map(async ({ component_name, args }) => {\n\t\t\t\tconst component = this.registry.get(component_name);\n\t\t\t\tconst single_result = {\n\t\t\t\t\tcomponent_name,\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\t\t\t\targs: component\n\t\t\t\t\t\t? await component.convertParsedToStorage(\n\t\t\t\t\t\t\t\tthis.makeJDDContext(ctx),\n\t\t\t\t\t\t\t\targs\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: {},\n\t\t\t\t};\n\t\t\t\treturn single_result;\n\t\t\t})\n\t\t);\n\t\tconst serialized_state = JSON.stringify(\n\t\t\t{ ...state, components: serialized_components },\n\t\t\tnull,\n\t\t\tpretty ? 4 : \"\"\n\t\t);\n\t\treturn serialized_state;\n\t}\n\n\tasync deserializeState(ctx: Context, state_string: string) {\n\t\tconst jdd_context = this.makeJDDContext(ctx);\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\tconst raw = JSON.parse(state_string) as Record<string, unknown>;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\tconst components_storage = raw.components;\n\t\tif (!Array.isArray(components_storage)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"'components' key is not an array, got ${components_storage}\"\n\t\t\t);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\tconst components_parsed = await Promise.all(\n\t\t\tcomponents_storage.map(async (entry) => {\n\t\t\t\tif (\n\t\t\t\t\t!hasShape(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcomponent_name: predicates.string,\n\t\t\t\t\t\t\targs: predicates.object,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tentry\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Expected components[] items to be objects with 'component_name' and 'args' keys, got ${entry}`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst { component_name, args } = entry;\n\t\t\t\tconst component = this.registry.get(component_name);\n\t\t\t\tif (!component) {\n\t\t\t\t\tthrow new Error(\"Unknown component: ${component_name}\");\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcomponent_name,\n\t\t\t\t\targs: await component.convertStorageToParsed(\n\t\t\t\t\t\tjdd_context,\n\t\t\t\t\t\targs\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t})\n\t\t);\n\t\tconst result = { ...raw, components: components_parsed };\n\t\treturn result;\n\t}\n\n\trenderPreParameterButtons(\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t_ctx: Context,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t_state: JDDPageState\n\t): FlatTemplatable | Promise<FlatTemplatable> {\n\t\treturn \"\";\n\t}\n\n\tasync render(ctx: Context, state: JDDPageState): Promise<string> {\n\t\treturn tempstream /* HTML */ `<div\n\t\t\tclass=\"${[\"two-column\", \"component-debugger\", ...this.classes].join(\" \")}\"\n\t\t\tid=\"component-debugger\"\n\t\t\tstyle=\"${`--resizable-column-width: ${\n\t\t\t\tstate.preview_size ? state.preview_size + \"px\" : \"50vw\"\n\t\t\t}`}\"\n\t\t\tdata-controller=\"component-debugger\"\n\t\t>\n\t\t\t<div class=\"component-arguments\" id=\"component-arguments\">\n\t\t\t\t${this.renderPreParameterButtons(ctx, state)}\n\t\t\t\t${this.renderParameterButtons(state)}\n\t\t\t\t<ul\n\t\t\t\t\tid=\"jdd-editor-messages\"\n\t\t\t\t\tclass=\"jdd-editor__messages\"\n\t\t\t\t\tdata-controller=\"toast\"\n\t\t\t\t></ul>\n\t\t\t\t${state.components.map((component, component_index) =>\n\t\t\t\t\tthis.renderComponentBlock(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\tcomponent_index\n\t\t\t\t\t)\n\t\t\t\t)}\n\t\t\t\t<details\n\t\t\t\t\tclass=\"component-debugger__json\"\n\t\t\t\t\tdata-controller=\"exportable-textarea\"\n\t\t\t\t\tid=\"exportable-textarea\"\n\t\t\t\t\topen\n\t\t\t\t>\n\t\t\t\t\t<summary>Edit/Export raw JSON</summary>\n\t\t\t\t\t<textarea\n\t\t\t\t\t\tname=\"state_override\"\n\t\t\t\t\t\trows=\"40\"\n\t\t\t\t\t\tcols=\"40\"\n\t\t\t\t\t\tdata-controller=\"json-editor\"\n\t\t\t\t\t\tid=\"component-debugger-json-textarea\"\n\t\t\t\t\t\tautocomplete=\"off\"\n\t\t\t\t\t>\n\t\t\t\t\t\t${(await this.serializeState(ctx, state, true)).replaceAll(\"<\", \"<\")}\n\t\t\t\t\t</textarea\n\t\t\t\t\t>\n\t\t\t\t\t${this.makeActionButton(state, {\n\t\t\t\t\t\taction: \"replace_state\",\n\t\t\t\t\t\tlabel: \"Apply\",\n\t\t\t\t\t})}\n\t\t\t\t\t<button data-action=\"exportable-textarea#copy\">Copy</button>\n\t\t\t\t\t<button data-action=\"exportable-textarea#download\">\n\t\t\t\t\t\tDownload\n\t\t\t\t\t</button>\n\t\t\t\t\t<input type=\"file\" />${\" \"}\n\t\t\t\t\t<button data-action=\"exportable-textarea#import\">\n\t\t\t\t\t\tImport\n\t\t\t\t\t</button>\n\t\t\t\t</details>\n\t\t\t</div>\n\t\t\t<div\n\t\t\t\tid=\"resize-gutter\"\n\t\t\t\tclass=\"resize-gutter\"\n\t\t\t\tdata-component-debugger-target=\"gutter\"\n\t\t\t></div>\n\t\t\t<div\n\t\t\t\tid=\"component-preview\"\n\t\t\t\tclass=\"component-preview\"\n\t\t\t\tdata-component-debugger-target=\"preview\"\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tid=\"component-preview__header\"\n\t\t\t\t\tclass=\"component-preview__header\"\n\t\t\t\t>\n\t\t\t\t\t<div class=\"component-preview__item\">\n\t\t\t\t\t\t<span>Window size</span>\n\t\t\t\t\t\t<select\n\t\t\t\t\t\t\tname=\"$[preview_size]\"\n\t\t\t\t\t\t\tautocomplete=\"off\"\n\t\t\t\t\t\t\tclass=\"component-preview-size-select\"\n\t\t\t\t\t\t\tdata-component-debugger-target=\"sizeSelect\"\n\t\t\t\t\t\t\tdata-action=\"change->component-debugger#handleWidthDropdown\"\n\t\t\t\t\t\t\tdata-turbo-permanent\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t${\n\t\t\t\t\t\t\t\tstate.preview_size\n\t\t\t\t\t\t\t\t\t? /* HTML */ `<option\n\t\t\t\t\t\t\t\t\t\t\tclass=\"dynamic\"\n\t\t\t\t\t\t\t\t\t\t\tvalue=\"${state.preview_size}\"\n\t\t\t\t\t\t\t\t\t\t\tselected\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t${state.preview_size} px\n\t\t\t\t\t\t\t\t\t\t</option>`\n\t\t\t\t\t\t\t\t\t: \"\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t${this.previewSizes.map(\n\t\t\t\t\t\t\t\t(size) =>\n\t\t\t\t\t\t\t\t\t/* HTML */ `<option value=\"${size}\">\n\t\t\t\t\t\t\t\t\t\t${`${size} px`}\n\t\t\t\t\t\t\t\t\t</option>`\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</select>\n\t\t\t\t\t\t<noscript>\n\t\t\t\t\t\t\t${this.makeActionButton(state, \"change_size\")}\n\t\t\t\t\t\t</noscript>\n\t\t\t\t\t</div>\n\t\t\t\t\t<style>\n\t\t\t\t\t\t.component-preview .component-raw-view {\n\t\t\t\t\t\t\tdisplay: none;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t.component-preview .jdd-outer-container {\n\t\t\t\t\t\t\tdisplay: block;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t.component-preview:has(\n\t\t\t\t\t\t\t\t.component-preview-checkbox:checked\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.component-raw-view {\n\t\t\t\t\t\t\tdisplay: block;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t.component-preview:has(\n\t\t\t\t\t\t\t\t.component-preview-checkbox:checked\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.jdd-outer-container {\n\t\t\t\t\t\t\tdisplay: none;\n\t\t\t\t\t\t}\n\t\t\t\t\t</style>\n\t\t\t\t\t<label class=\"component-preview__item\" for=\"show-html\">\n\t\t\t\t\t\tShow HTML\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\t\t\tid=\"show-html\"\n\t\t\t\t\t\t\tclass=\"component-preview-checkbox\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</label>\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t\t\t${(async () => {\n\t\t\t\t\t\t\tconst currentComponent = await JDD.render(\n\t\t\t\t\t\t\t\tthis.registry,\n\t\t\t\t\t\t\t\tdocumentContainerFromParsed(state.components),\n\t\t\t\t\t\t\t\tthis.makeJDDContext(ctx)\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tlet currentComponentPrettified = currentComponent;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tcurrentComponentPrettified =\n\t\t\t\t\t\t\t\t\tawait prettier.format(currentComponent, {\n\t\t\t\t\t\t\t\t\t\tparser: \"html\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t\t\"JDD editor: couldn't format the html\"\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst highlightedHTML = hljs.highlight(\n\t\t\t\t\t\t\t\tcurrentComponentPrettified,\n\t\t\t\t\t\t\t\t{ language: \"html\" }\n\t\t\t\t\t\t\t).value;\n\t\t\t\t\t\t\treturn /* HTML */ ` <div\n\t\t\t\t\t\t\t\t\tclass=\"jdd-outer-container\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<div class=\"jdd-container\">\n\t\t\t\t\t\t\t\t\t\t${currentComponent}\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<div class=\"component-raw-view\">\n\t\t\t\t\t\t\t\t\t<pre><code>${highlightedHTML}</code></pre>\n\t\t\t\t\t\t\t\t</div>`;\n\t\t\t\t\t\t})()}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>`;\n\t}\n\n\tasync renderWithMessages(\n\t\tctx: Context,\n\t\tstate: JDDPageState,\n\t\tmessages: { type: \"error\" | \"success\"; content: string }[]\n\t): Promise<string> {\n\t\treturn tempstream /* HTML */ `${this.render(ctx, state)}\n\t\t${messages\n\t\t\t.map(\n\t\t\t\t({ type, content }) =>\n\t\t\t\t\t/* HTML */ `<turbo-stream\n\t\t\t\t\t\taction=\"append\"\n\t\t\t\t\t\ttarget=\"jdd-editor-messages\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<template>\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclass=\"jdd-editor__message jdd-editor__message--${type}\"\n\t\t\t\t\t\t\t>\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A,QAClC,KAAK;AAAA,QACL,4BAA4B,MAAM,UAAU;AAAA,QAC5C,KAAK,eAAe,GAAG;AAAA,MACxB;AAEA,UAAI,6BAA6B;AACjC,UAAI;AACH,qCACC,MAAM,SAAS,OAAO,kBAAkB;AAAA,UACvC,QAAQ;AAAA,QACT,CAAC;AAAA,MACH,SAAS,GAAP;AACD,gBAAQ;AAAA,UACP;AAAA,QACD;AAAA,MACD;AACA,YAAM,kBAAkB,KAAK;AAAA,QAC5B;AAAA,QACA,EAAE,UAAU,OAAO;AAAA,MACpB,EAAE;AACF,aAAkB;AAAA;AAAA;AAAA;AAAA,YAIb;AAAA;AAAA;AAAA;AAAA,sBAIU;AAAA;AAAA,IAEhB,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR;AAAA,EAEA,MAAM,mBACL,KACA,OACA,UACkB;AAClB,WAAO,aAAyB,KAAK,OAAO,KAAK,KAAK;AAAA,IACpD,SACA;AAAA,MACA,CAAC,EAAE,MAAM,QAAQ,MACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0DAM0C;AAAA;AAAA,UAEhD;AAAA;AAAA;AAAA;AAAA,IAIP,EACC,KAAK,EAAE;AAAA,EACV;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/jdd-editor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf dist && node ./esbuild.cjs",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"types": "./@types/index.d.ts",
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@koa/router": "^13.1.0",
|
|
50
|
-
"@sealcode/jdd": "^0.8.
|
|
50
|
+
"@sealcode/jdd": "^0.8.6",
|
|
51
51
|
"@sealcode/monaco-wrapper": "^0.0.3",
|
|
52
52
|
"@sealcode/sealcodemirror": "^5.70.0-beta5",
|
|
53
53
|
"@sealcode/sealgen": "^0.19.6",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Controller } from "stimulus";
|
|
2
|
+
|
|
3
|
+
export default class CodeSnippet extends Controller {
|
|
4
|
+
declare codeTarget: HTMLElement;
|
|
5
|
+
|
|
6
|
+
static targets = ["code"];
|
|
7
|
+
|
|
8
|
+
copyCode() {
|
|
9
|
+
const value = this.codeTarget.textContent || "";
|
|
10
|
+
void navigator.clipboard.writeText(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -17,7 +17,6 @@ function download(data: string, filename: string, type: string) {
|
|
|
17
17
|
|
|
18
18
|
export default class ExportableTextarea extends Controller<HTMLDetailsElement> {
|
|
19
19
|
connect() {
|
|
20
|
-
console.log("exportable", this.element);
|
|
21
20
|
this.element.removeAttribute("open");
|
|
22
21
|
this.element.addEventListener(
|
|
23
22
|
"turbo:before-morph-attribute",
|
package/src/edit-jdd-field.ts
CHANGED
|
@@ -66,11 +66,9 @@ export abstract class EditJDDField<C extends Collection> extends JDDCreator {
|
|
|
66
66
|
await item.save(ctx.$context);
|
|
67
67
|
ctx.type = "html";
|
|
68
68
|
ctx.status = 422;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
state.messages.push("Saved!");
|
|
73
|
-
ctx.body = this.render(ctx, state);
|
|
69
|
+
ctx.body = this.renderWithMessages(ctx, state, [
|
|
70
|
+
{ type: "success", content: "Saved!" },
|
|
71
|
+
]);
|
|
74
72
|
});
|
|
75
73
|
}
|
|
76
74
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { tempstream } from "tempstream";
|
|
2
|
+
import { printArgPath } from "./print-arg-path.js";
|
|
3
|
+
import { is, predicates } from "@sealcode/ts-predicates";
|
|
4
|
+
import { Component } from "@sealcode/jdd";
|
|
5
|
+
|
|
6
|
+
export function ComponentInputCodeWithCustomLanguage({
|
|
7
|
+
language,
|
|
8
|
+
code,
|
|
9
|
+
arg_path,
|
|
10
|
+
component,
|
|
11
|
+
}: {
|
|
12
|
+
code: string;
|
|
13
|
+
language: string;
|
|
14
|
+
arg_path: string[];
|
|
15
|
+
component: Component;
|
|
16
|
+
}): JSX.Element {
|
|
17
|
+
return tempstream /* HTML */ `<div
|
|
18
|
+
id="monaco__${arg_path.join("_")}__for__${component.name}"
|
|
19
|
+
>
|
|
20
|
+
<div data-controller="monaco" data-turbo-permanent="true">
|
|
21
|
+
<input
|
|
22
|
+
data-monaco-target="languageInput"
|
|
23
|
+
data-action="monaco#languageChange"
|
|
24
|
+
type="text"
|
|
25
|
+
name="${`$${printArgPath(arg_path)}`}[language]"
|
|
26
|
+
value="${is(language, predicates.string) ? language : ""}"
|
|
27
|
+
size="40"
|
|
28
|
+
/>
|
|
29
|
+
<div class="monaco-wrapper">
|
|
30
|
+
<textarea
|
|
31
|
+
data-monaco-target="textarea"
|
|
32
|
+
name="$${printArgPath(arg_path)}[code]"
|
|
33
|
+
style="display: none"
|
|
34
|
+
>
|
|
35
|
+
${code}</textarea
|
|
36
|
+
>
|
|
37
|
+
<div
|
|
38
|
+
data-monaco-target="wrapper"
|
|
39
|
+
data-language="${language}"
|
|
40
|
+
></div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</div>`;
|
|
44
|
+
}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
import { tempstream } from "tempstream";
|
|
2
2
|
import { printArgPath } from "./print-arg-path.js";
|
|
3
|
+
import { Component } from "@sealcode/jdd";
|
|
3
4
|
|
|
4
5
|
export function ComponentInputCode({
|
|
5
6
|
language,
|
|
6
7
|
value,
|
|
7
8
|
arg_path,
|
|
9
|
+
component,
|
|
8
10
|
}: {
|
|
9
11
|
value: string;
|
|
10
12
|
language: string;
|
|
11
13
|
arg_path: string[];
|
|
14
|
+
component: Component;
|
|
12
15
|
}): JSX.Element {
|
|
13
|
-
return tempstream /* HTML */ `<div
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
return tempstream /* HTML */ `<div
|
|
17
|
+
id="monaco__${arg_path.join("_")}__for__${component.name}"
|
|
18
|
+
>
|
|
19
|
+
<div data-controller="monaco">
|
|
20
|
+
<div class="monaco-wrapper">
|
|
21
|
+
<textarea
|
|
22
|
+
data-monaco-target="textarea"
|
|
23
|
+
name="$${printArgPath(arg_path)}"
|
|
24
|
+
style="display: none"
|
|
25
|
+
>
|
|
26
|
+
${value}</textarea
|
|
27
|
+
>
|
|
28
|
+
<div
|
|
29
|
+
data-monaco-target="wrapper"
|
|
30
|
+
data-language="${language}"
|
|
31
|
+
data-turbo-permanent="true"
|
|
32
|
+
id="${arg_path.join("_")}"
|
|
33
|
+
></div>
|
|
34
|
+
</div>
|
|
22
35
|
</div>
|
|
23
|
-
</div
|
|
36
|
+
</div> `;
|
|
24
37
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import type { Context } from "koa";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
Component,
|
|
5
|
+
ComponentArgument,
|
|
6
|
+
JDDContext,
|
|
7
|
+
List,
|
|
8
|
+
} from "@sealcode/jdd";
|
|
4
9
|
import type { JDDPageState } from "../jdd-page.js";
|
|
5
10
|
import type { StatefulPage } from "@sealcode/sealgen";
|
|
6
11
|
import { ComponentInput } from "./component-input.js";
|
|
@@ -18,6 +23,7 @@ export async function ComponentInputList<
|
|
|
18
23
|
value,
|
|
19
24
|
page,
|
|
20
25
|
makeJDDContext,
|
|
26
|
+
component,
|
|
21
27
|
...rest
|
|
22
28
|
}: {
|
|
23
29
|
state: State;
|
|
@@ -29,6 +35,7 @@ export async function ComponentInputList<
|
|
|
29
35
|
page: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;
|
|
30
36
|
makeJDDContext: (ctx: Context) => JDDContext;
|
|
31
37
|
makeAssetURL: (asset: string) => string;
|
|
38
|
+
component: Component;
|
|
32
39
|
}): Promise<string> {
|
|
33
40
|
if (!value) {
|
|
34
41
|
value = [];
|
|
@@ -49,6 +56,7 @@ export async function ComponentInputList<
|
|
|
49
56
|
value,
|
|
50
57
|
page,
|
|
51
58
|
makeJDDContext,
|
|
59
|
+
component,
|
|
52
60
|
})}
|
|
53
61
|
${page.makeActionButton(
|
|
54
62
|
state,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Context } from "koa";
|
|
2
2
|
import {
|
|
3
|
+
Component,
|
|
3
4
|
Structured,
|
|
4
5
|
type ComponentArgument,
|
|
5
6
|
type JDDContext,
|
|
@@ -22,6 +23,7 @@ export async function ComponentInputStructured<
|
|
|
22
23
|
value,
|
|
23
24
|
page,
|
|
24
25
|
makeJDDContext,
|
|
26
|
+
component,
|
|
25
27
|
...rest
|
|
26
28
|
}: {
|
|
27
29
|
state: JDDPageState;
|
|
@@ -32,6 +34,7 @@ export async function ComponentInputStructured<
|
|
|
32
34
|
page: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;
|
|
33
35
|
makeJDDContext: (ctx: Context) => JDDContext;
|
|
34
36
|
makeAssetURL: (asset: string) => string;
|
|
37
|
+
component: Component;
|
|
35
38
|
}) {
|
|
36
39
|
const structure =
|
|
37
40
|
arg instanceof Structured
|
|
@@ -61,6 +64,7 @@ export async function ComponentInputStructured<
|
|
|
61
64
|
value: value[inner_arg_name],
|
|
62
65
|
page,
|
|
63
66
|
makeJDDContext,
|
|
67
|
+
component,
|
|
64
68
|
...rest,
|
|
65
69
|
})}
|
|
66
70
|
</div>`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
-
import type { JDDContext, Table, TableData } from "@sealcode/jdd";
|
|
2
|
+
import type { Component, JDDContext, Table, TableData } from "@sealcode/jdd";
|
|
3
3
|
import { Markdown } from "@sealcode/jdd";
|
|
4
4
|
import { isTableHeader } from "@sealcode/jdd";
|
|
5
5
|
import type { StatefulPage } from "@sealcode/sealgen";
|
|
@@ -22,6 +22,7 @@ export async function ComponentInputTable<
|
|
|
22
22
|
page,
|
|
23
23
|
makeJDDContext,
|
|
24
24
|
makeAssetURL,
|
|
25
|
+
component,
|
|
25
26
|
}: {
|
|
26
27
|
state: State;
|
|
27
28
|
ctx: Context;
|
|
@@ -31,6 +32,7 @@ export async function ComponentInputTable<
|
|
|
31
32
|
page: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;
|
|
32
33
|
makeJDDContext: (ctx: Context) => JDDContext;
|
|
33
34
|
makeAssetURL: (asset: string) => string;
|
|
35
|
+
component: Component;
|
|
34
36
|
}): Promise<string> {
|
|
35
37
|
if (!value) {
|
|
36
38
|
value = await arg.getEmptyValue(makeJDDContext(ctx));
|
|
@@ -165,6 +167,7 @@ export async function ComponentInputTable<
|
|
|
165
167
|
page,
|
|
166
168
|
makeJDDContext,
|
|
167
169
|
makeAssetURL,
|
|
170
|
+
component,
|
|
168
171
|
})}
|
|
169
172
|
</th>`
|
|
170
173
|
: row.cells.map(
|
|
@@ -185,6 +188,7 @@ export async function ComponentInputTable<
|
|
|
185
188
|
page,
|
|
186
189
|
makeJDDContext,
|
|
187
190
|
makeAssetURL,
|
|
191
|
+
component,
|
|
188
192
|
})}
|
|
189
193
|
</td>`
|
|
190
194
|
)}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { FilePointer } from "@sealcode/file-manager";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Component,
|
|
4
|
+
ComponentArgument,
|
|
5
|
+
JDDContext,
|
|
6
|
+
TableData,
|
|
7
|
+
} from "@sealcode/jdd";
|
|
3
8
|
import {
|
|
4
9
|
Code,
|
|
5
10
|
Color,
|
|
@@ -11,6 +16,7 @@ import {
|
|
|
11
16
|
SingleReference,
|
|
12
17
|
Structured,
|
|
13
18
|
Table,
|
|
19
|
+
CodeWithCustomLanguage,
|
|
14
20
|
} from "@sealcode/jdd";
|
|
15
21
|
import type { StatefulPage } from "@sealcode/sealgen";
|
|
16
22
|
import { is, predicates } from "@sealcode/ts-predicates";
|
|
@@ -30,6 +36,8 @@ import { ComponentInputStructured } from "./component-input-structured.js";
|
|
|
30
36
|
import { ComponentInputTable } from "./component-input-table.js";
|
|
31
37
|
import { printArgPath } from "./print-arg-path.js";
|
|
32
38
|
|
|
39
|
+
import { ComponentInputCodeWithCustomLanguage } from "./component-input-code-with-custom-language.js";
|
|
40
|
+
|
|
33
41
|
export const actionName = "Components";
|
|
34
42
|
const absoluteUrlPattern = "http(s?)(://)((www.)?)(([^.]+).)?([a-zA-z0-9-_]+)";
|
|
35
43
|
|
|
@@ -42,6 +50,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
|
|
|
42
50
|
page,
|
|
43
51
|
makeJDDContext,
|
|
44
52
|
makeAssetURL,
|
|
53
|
+
component,
|
|
45
54
|
}: {
|
|
46
55
|
state: State;
|
|
47
56
|
ctx: Context;
|
|
@@ -51,6 +60,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
|
|
|
51
60
|
page: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;
|
|
52
61
|
makeJDDContext: (ctx: Context) => JDDContext;
|
|
53
62
|
makeAssetURL: (asset: string) => string;
|
|
63
|
+
component: Component;
|
|
54
64
|
}): Promise<string> {
|
|
55
65
|
if (value === undefined) {
|
|
56
66
|
value = await arg.getEmptyValue(makeJDDContext(ctx));
|
|
@@ -80,6 +90,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
|
|
|
80
90
|
page,
|
|
81
91
|
makeJDDContext,
|
|
82
92
|
makeAssetURL,
|
|
93
|
+
component,
|
|
83
94
|
});
|
|
84
95
|
}
|
|
85
96
|
|
|
@@ -92,6 +103,22 @@ export async function ComponentInput<State extends JDDPageState, T>({
|
|
|
92
103
|
arg instanceof ComponentArguments.URL && arg.urlType === "absolute";
|
|
93
104
|
const inputType = isUrlAbsolute ? "url" : "text";
|
|
94
105
|
|
|
106
|
+
if (arg instanceof CodeWithCustomLanguage) {
|
|
107
|
+
const valueCasted = value as {
|
|
108
|
+
language: string;
|
|
109
|
+
code: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return ComponentInputCodeWithCustomLanguage({
|
|
113
|
+
language: valueCasted.language,
|
|
114
|
+
code: is(valueCasted.code, predicates.string)
|
|
115
|
+
? valueCasted.code
|
|
116
|
+
: "",
|
|
117
|
+
arg_path,
|
|
118
|
+
component,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
95
122
|
if (arg instanceof Structured || arg instanceof NestedComponent) {
|
|
96
123
|
return ComponentInputStructured({
|
|
97
124
|
ctx,
|
|
@@ -103,6 +130,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
|
|
|
103
130
|
page,
|
|
104
131
|
makeJDDContext,
|
|
105
132
|
makeAssetURL,
|
|
133
|
+
component,
|
|
106
134
|
});
|
|
107
135
|
}
|
|
108
136
|
|
|
@@ -155,6 +183,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
|
|
|
155
183
|
page,
|
|
156
184
|
makeJDDContext,
|
|
157
185
|
makeAssetURL,
|
|
186
|
+
component,
|
|
158
187
|
});
|
|
159
188
|
}
|
|
160
189
|
|
|
@@ -163,6 +192,7 @@ export async function ComponentInput<State extends JDDPageState, T>({
|
|
|
163
192
|
language: arg.language,
|
|
164
193
|
value: is(value, predicates.string) ? value : "",
|
|
165
194
|
arg_path,
|
|
195
|
+
component,
|
|
166
196
|
});
|
|
167
197
|
}
|
|
168
198
|
|
package/src/jdd-page.ts
CHANGED
|
@@ -18,7 +18,6 @@ export const actionName = "Components";
|
|
|
18
18
|
export type JDDPageState = {
|
|
19
19
|
components: RawJDDocument;
|
|
20
20
|
preview_size?: string;
|
|
21
|
-
messages?: string[];
|
|
22
21
|
};
|
|
23
22
|
|
|
24
23
|
export default abstract class JDDPage extends StatefulPage<
|
|
@@ -198,6 +197,7 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
198
197
|
page: this,
|
|
199
198
|
makeJDDContext: this.makeJDDContext,
|
|
200
199
|
makeAssetURL: this.makeAssetURL,
|
|
200
|
+
component,
|
|
201
201
|
})
|
|
202
202
|
)}
|
|
203
203
|
</div>`;
|
|
@@ -307,17 +307,6 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
307
307
|
return "";
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
renderMessages(_ctx: Context, state: JDDPageState) {
|
|
311
|
-
return /* HTML */ `<ul
|
|
312
|
-
class="jdd-editor__messages"
|
|
313
|
-
data-controller="toast"
|
|
314
|
-
>
|
|
315
|
-
${(state.messages || []).map(
|
|
316
|
-
(e) => `<li class="jdd-editor__message">${e}</li>`
|
|
317
|
-
)}
|
|
318
|
-
</ul>`;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
310
|
async render(ctx: Context, state: JDDPageState): Promise<string> {
|
|
322
311
|
return tempstream /* HTML */ `<div
|
|
323
312
|
class="${["two-column", "component-debugger", ...this.classes].join(" ")}"
|
|
@@ -330,7 +319,11 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
330
319
|
<div class="component-arguments" id="component-arguments">
|
|
331
320
|
${this.renderPreParameterButtons(ctx, state)}
|
|
332
321
|
${this.renderParameterButtons(state)}
|
|
333
|
-
|
|
322
|
+
<ul
|
|
323
|
+
id="jdd-editor-messages"
|
|
324
|
+
class="jdd-editor__messages"
|
|
325
|
+
data-controller="toast"
|
|
326
|
+
></ul>
|
|
334
327
|
${state.components.map((component, component_index) =>
|
|
335
328
|
this.renderComponentBlock(
|
|
336
329
|
ctx,
|
|
@@ -488,4 +481,29 @@ export default abstract class JDDPage extends StatefulPage<
|
|
|
488
481
|
</div>
|
|
489
482
|
</div>`;
|
|
490
483
|
}
|
|
484
|
+
|
|
485
|
+
async renderWithMessages(
|
|
486
|
+
ctx: Context,
|
|
487
|
+
state: JDDPageState,
|
|
488
|
+
messages: { type: "error" | "success"; content: string }[]
|
|
489
|
+
): Promise<string> {
|
|
490
|
+
return tempstream /* HTML */ `${this.render(ctx, state)}
|
|
491
|
+
${messages
|
|
492
|
+
.map(
|
|
493
|
+
({ type, content }) =>
|
|
494
|
+
/* HTML */ `<turbo-stream
|
|
495
|
+
action="append"
|
|
496
|
+
target="jdd-editor-messages"
|
|
497
|
+
>
|
|
498
|
+
<template>
|
|
499
|
+
<div
|
|
500
|
+
class="jdd-editor__message jdd-editor__message--${type}"
|
|
501
|
+
>
|
|
502
|
+
${content}
|
|
503
|
+
</div>
|
|
504
|
+
</template>
|
|
505
|
+
</turbo-stream>`
|
|
506
|
+
)
|
|
507
|
+
.join("")}`;
|
|
508
|
+
}
|
|
491
509
|
}
|