@wp-typia/project-tools 0.17.0 → 0.19.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.
- package/dist/runtime/alternate-render-targets.d.ts +5 -0
- package/dist/runtime/alternate-render-targets.js +29 -0
- package/dist/runtime/block-generator-service-core.d.ts +2 -2
- package/dist/runtime/block-generator-service-core.js +13 -8
- package/dist/runtime/block-generator-service-spec.d.ts +10 -2
- package/dist/runtime/block-generator-service-spec.js +43 -1
- package/dist/runtime/built-in-block-artifacts.js +1 -0
- package/dist/runtime/built-in-block-code-templates/compound-child.d.ts +2 -2
- package/dist/runtime/built-in-block-code-templates/compound-child.js +35 -2
- package/dist/runtime/built-in-block-code-templates/compound-parent.d.ts +2 -2
- package/dist/runtime/built-in-block-code-templates/compound-parent.js +204 -27
- package/dist/runtime/built-in-block-code-templates/compound-persistence.d.ts +1 -1
- package/dist/runtime/built-in-block-code-templates/compound-persistence.js +11 -8
- package/dist/runtime/built-in-block-non-ts-artifacts.js +505 -2
- package/dist/runtime/cli-add-block.d.ts +6 -2
- package/dist/runtime/cli-add-block.js +71 -24
- package/dist/runtime/cli-add-shared.d.ts +58 -2
- package/dist/runtime/cli-add-shared.js +111 -12
- package/dist/runtime/cli-add-workspace-assets.d.ts +21 -1
- package/dist/runtime/cli-add-workspace-assets.js +417 -1
- package/dist/runtime/cli-add-workspace-rest.d.ts +14 -0
- package/dist/runtime/cli-add-workspace-rest.js +1060 -0
- package/dist/runtime/cli-add-workspace.d.ts +10 -1
- package/dist/runtime/cli-add-workspace.js +10 -1
- package/dist/runtime/cli-add.d.ts +3 -3
- package/dist/runtime/cli-add.js +2 -2
- package/dist/runtime/cli-core.d.ts +5 -1
- package/dist/runtime/cli-core.js +3 -1
- package/dist/runtime/cli-doctor-workspace.js +135 -1
- package/dist/runtime/cli-help.js +12 -7
- package/dist/runtime/cli-scaffold.d.ts +12 -2
- package/dist/runtime/cli-scaffold.js +222 -46
- package/dist/runtime/cli-templates.d.ts +4 -4
- package/dist/runtime/cli-templates.js +104 -39
- package/dist/runtime/cli-validation.d.ts +66 -0
- package/dist/runtime/cli-validation.js +92 -0
- package/dist/runtime/compound-inner-blocks.d.ts +78 -0
- package/dist/runtime/compound-inner-blocks.js +88 -0
- package/dist/runtime/index.d.ts +6 -3
- package/dist/runtime/index.js +4 -2
- package/dist/runtime/local-dev-presets.js +7 -2
- package/dist/runtime/migration-command-surface.js +2 -0
- package/dist/runtime/package-versions.d.ts +1 -0
- package/dist/runtime/package-versions.js +12 -0
- package/dist/runtime/rest-resource-artifacts.d.ts +35 -0
- package/dist/runtime/rest-resource-artifacts.js +158 -0
- package/dist/runtime/scaffold-answer-resolution.js +78 -8
- package/dist/runtime/scaffold-apply-utils.d.ts +4 -3
- package/dist/runtime/scaffold-apply-utils.js +34 -17
- package/dist/runtime/scaffold-bootstrap.d.ts +15 -0
- package/dist/runtime/scaffold-bootstrap.js +29 -7
- package/dist/runtime/scaffold-documents.js +24 -3
- package/dist/runtime/scaffold-identifiers.d.ts +17 -0
- package/dist/runtime/scaffold-identifiers.js +22 -0
- package/dist/runtime/scaffold-onboarding.js +25 -13
- package/dist/runtime/scaffold-package-manager-files.js +6 -1
- package/dist/runtime/scaffold-template-variables.js +22 -0
- package/dist/runtime/scaffold.d.ts +22 -1
- package/dist/runtime/scaffold.js +56 -11
- package/dist/runtime/template-render.d.ts +5 -2
- package/dist/runtime/template-render.js +9 -3
- package/dist/runtime/template-source-contracts.d.ts +11 -0
- package/dist/runtime/template-source-external.d.ts +1 -1
- package/dist/runtime/template-source-external.js +45 -13
- package/dist/runtime/template-source-normalization.d.ts +1 -1
- package/dist/runtime/template-source-normalization.js +5 -1
- package/dist/runtime/template-source-remote.d.ts +5 -0
- package/dist/runtime/template-source-remote.js +33 -0
- package/dist/runtime/template-source.js +35 -4
- package/dist/runtime/workspace-inventory.d.ts +43 -1
- package/dist/runtime/workspace-inventory.js +132 -1
- package/dist/runtime/workspace-project.d.ts +1 -1
- package/dist/runtime/workspace-project.js +3 -3
- package/package.json +9 -4
- package/templates/_shared/compound/core/scripts/add-compound-child.ts.mustache +728 -49
- package/templates/query-loop/src/validator-toolkit.ts.mustache +0 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const ALTERNATE_RENDER_TARGET_IDS: readonly ["email", "mjml", "plain-text"];
|
|
2
|
+
export type AlternateRenderTargetId = (typeof ALTERNATE_RENDER_TARGET_IDS)[number];
|
|
3
|
+
export declare function isAlternateRenderTargetId(value: string): value is AlternateRenderTargetId;
|
|
4
|
+
export declare function parseAlternateRenderTargets(value?: string): AlternateRenderTargetId[];
|
|
5
|
+
export declare function formatAlternateRenderTargets(targets: readonly AlternateRenderTargetId[]): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const ALTERNATE_RENDER_TARGET_IDS = [
|
|
2
|
+
"email",
|
|
3
|
+
"mjml",
|
|
4
|
+
"plain-text",
|
|
5
|
+
];
|
|
6
|
+
export function isAlternateRenderTargetId(value) {
|
|
7
|
+
return ALTERNATE_RENDER_TARGET_IDS.includes(value);
|
|
8
|
+
}
|
|
9
|
+
export function parseAlternateRenderTargets(value) {
|
|
10
|
+
if (typeof value !== "string") {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const normalized = value
|
|
14
|
+
.split(",")
|
|
15
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
16
|
+
.filter(Boolean);
|
|
17
|
+
if (normalized.length === 0) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const deduped = Array.from(new Set(normalized));
|
|
21
|
+
const invalid = deduped.filter((entry) => !isAlternateRenderTargetId(entry));
|
|
22
|
+
if (invalid.length > 0) {
|
|
23
|
+
throw new Error(`Unsupported alternate render target${invalid.length > 1 ? "s" : ""} "${invalid.join(", ")}". Expected one of: ${ALTERNATE_RENDER_TARGET_IDS.join(", ")}.`);
|
|
24
|
+
}
|
|
25
|
+
return deduped;
|
|
26
|
+
}
|
|
27
|
+
export function formatAlternateRenderTargets(targets) {
|
|
28
|
+
return targets.join(", ");
|
|
29
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ApplyBlockInput, type PlanBlockInput, type PlanBlockResult, type RenderBlockInput, type RenderBlockResult, type ValidateBlockInput, type ValidateBlockResult } from "./block-generator-service-spec.js";
|
|
2
2
|
import type { ScaffoldProjectResult } from "./scaffold.js";
|
|
3
3
|
export declare class BlockGeneratorService {
|
|
4
|
-
plan({ allowExistingDir, answers, cwd, dataStorageMode, externalLayerId, externalLayerSource, externalLayerSourceLabel, noInstall, packageManager, persistencePolicy, projectDir, repositoryReference, templateId, variant, withMigrationUi, withTestPreset, withWpEnv, }: PlanBlockInput): Promise<PlanBlockResult>;
|
|
4
|
+
plan({ allowExistingDir, alternateRenderTargets, answers, cwd, dataStorageMode, externalLayerId, externalLayerSource, externalLayerSourceLabel, noInstall, packageManager, persistencePolicy, projectDir, repositoryReference, templateId, variant, withMigrationUi, withTestPreset, withWpEnv, }: PlanBlockInput): Promise<PlanBlockResult>;
|
|
5
5
|
validate({ plan }: ValidateBlockInput): Promise<ValidateBlockResult>;
|
|
6
6
|
render({ validated }: RenderBlockInput): Promise<RenderBlockResult>;
|
|
7
|
-
apply({ rendered, installDependencies, }: ApplyBlockInput): Promise<ScaffoldProjectResult>;
|
|
7
|
+
apply({ rendered, installDependencies, onProgress, }: ApplyBlockInput): Promise<ScaffoldProjectResult>;
|
|
8
8
|
}
|
|
@@ -7,6 +7,7 @@ import { resolveTemplateSeed, parseTemplateLocator } from "./template-source.js"
|
|
|
7
7
|
import { assertExternalTemplateLayersDoNotWriteProtectedOutputs, resolveExternalTemplateLayers, } from "./template-layers.js";
|
|
8
8
|
import { getBuiltInTemplateOverlayDir, getBuiltInTemplateSharedLayerDirs, resolveBuiltInTemplateSource, resolveBuiltInTemplateSourceFromLayerDirs, } from "./template-builtins.js";
|
|
9
9
|
import { buildTemplateVariablesFromBlockSpec, createBuiltInBlockSpec, } from "./block-generator-service-spec.js";
|
|
10
|
+
import { assertBuiltInTemplateVariantAllowed, assertExternalLayerCompositionOptions, } from "./cli-validation.js";
|
|
10
11
|
const renderedArtifactCache = new WeakMap();
|
|
11
12
|
function createVariablesFingerprint(variables) {
|
|
12
13
|
return stableJsonStringify(variables);
|
|
@@ -82,9 +83,10 @@ async function runCleanupGroup(label, cleanups) {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
export class BlockGeneratorService {
|
|
85
|
-
async plan({ allowExistingDir = false, answers, cwd = process.cwd(), dataStorageMode, externalLayerId, externalLayerSource, externalLayerSourceLabel, noInstall = false, packageManager, persistencePolicy, projectDir, repositoryReference, templateId, variant, withMigrationUi = false, withTestPreset = false, withWpEnv = false, }) {
|
|
86
|
+
async plan({ allowExistingDir = false, alternateRenderTargets, answers, cwd = process.cwd(), dataStorageMode, externalLayerId, externalLayerSource, externalLayerSourceLabel, noInstall = false, packageManager, persistencePolicy, projectDir, repositoryReference, templateId, variant, withMigrationUi = false, withTestPreset = false, withWpEnv = false, }) {
|
|
86
87
|
return {
|
|
87
88
|
spec: createBuiltInBlockSpec({
|
|
89
|
+
alternateRenderTargets,
|
|
88
90
|
answers,
|
|
89
91
|
dataStorageMode,
|
|
90
92
|
persistencePolicy,
|
|
@@ -108,12 +110,14 @@ export class BlockGeneratorService {
|
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
112
|
async validate({ plan }) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
assertExternalLayerCompositionOptions({
|
|
114
|
+
externalLayerId: plan.target.externalLayerId,
|
|
115
|
+
externalLayerSource: plan.target.externalLayerSource,
|
|
116
|
+
});
|
|
117
|
+
assertBuiltInTemplateVariantAllowed({
|
|
118
|
+
templateId: plan.spec.template.family,
|
|
119
|
+
variant: plan.target.variant,
|
|
120
|
+
});
|
|
117
121
|
return plan;
|
|
118
122
|
}
|
|
119
123
|
async render({ validated }) {
|
|
@@ -222,7 +226,7 @@ export class BlockGeneratorService {
|
|
|
222
226
|
});
|
|
223
227
|
return rendered;
|
|
224
228
|
}
|
|
225
|
-
async apply({ rendered, installDependencies, }) {
|
|
229
|
+
async apply({ rendered, installDependencies, onProgress, }) {
|
|
226
230
|
const cachedArtifacts = renderedArtifactCache.get(rendered);
|
|
227
231
|
const currentVariablesFingerprint = createVariablesFingerprint(rendered.variables);
|
|
228
232
|
const artifacts = cachedArtifacts &&
|
|
@@ -246,6 +250,7 @@ export class BlockGeneratorService {
|
|
|
246
250
|
codeArtifacts,
|
|
247
251
|
installDependencies,
|
|
248
252
|
noInstall: rendered.target.noInstall,
|
|
253
|
+
onProgress,
|
|
249
254
|
packageManager: rendered.target.packageManager,
|
|
250
255
|
projectDir: rendered.target.projectDir,
|
|
251
256
|
repositoryReference: rendered.target.repositoryReference,
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import type { PackageManagerId } from "./package-managers.js";
|
|
2
|
+
import { type AlternateRenderTargetId } from "./alternate-render-targets.js";
|
|
3
|
+
import { type CompoundInnerBlocksPresetId } from "./compound-inner-blocks.js";
|
|
2
4
|
import { type BuiltInTemplateId } from "./template-registry.js";
|
|
3
5
|
import type { InstallDependenciesOptions } from "./scaffold-apply-utils.js";
|
|
4
|
-
import type { DataStorageMode, PersistencePolicy, ScaffoldAnswers, ScaffoldTemplateVariables } from "./scaffold.js";
|
|
6
|
+
import type { DataStorageMode, PersistencePolicy, ScaffoldAnswers, ScaffoldProgressEvent, ScaffoldTemplateVariables } from "./scaffold.js";
|
|
5
7
|
export interface BlockSpec {
|
|
8
|
+
alternateRenderTargets: readonly AlternateRenderTargetId[];
|
|
6
9
|
block: {
|
|
7
10
|
namespace: string;
|
|
8
11
|
phpPrefix: string;
|
|
9
12
|
slug: string;
|
|
10
13
|
textDomain: string;
|
|
11
14
|
};
|
|
15
|
+
compound: {
|
|
16
|
+
innerBlocksPreset: CompoundInnerBlocksPresetId;
|
|
17
|
+
};
|
|
12
18
|
metadata: {
|
|
13
19
|
category: string;
|
|
14
20
|
description: string;
|
|
@@ -57,6 +63,7 @@ export interface BlockGenerationTarget {
|
|
|
57
63
|
}
|
|
58
64
|
export interface PlanBlockInput {
|
|
59
65
|
allowExistingDir?: boolean;
|
|
66
|
+
alternateRenderTargets?: string;
|
|
60
67
|
answers: ScaffoldAnswers;
|
|
61
68
|
cwd?: string;
|
|
62
69
|
dataStorageMode?: DataStorageMode;
|
|
@@ -105,6 +112,7 @@ export interface RenderBlockResult extends ValidateBlockResult {
|
|
|
105
112
|
export interface ApplyBlockInput {
|
|
106
113
|
rendered: RenderBlockResult;
|
|
107
114
|
installDependencies?: ((options: InstallDependenciesOptions) => Promise<void>) | undefined;
|
|
115
|
+
onProgress?: ((event: ScaffoldProgressEvent) => void | Promise<void>) | undefined;
|
|
108
116
|
}
|
|
109
|
-
export declare function createBuiltInBlockSpec({ answers, dataStorageMode, persistencePolicy, templateId, withMigrationUi, withTestPreset, withWpEnv, }: Omit<PlanBlockInput, "allowExistingDir" | "cwd" | "noInstall" | "packageManager" | "projectDir" | "variant">): BlockSpec;
|
|
117
|
+
export declare function createBuiltInBlockSpec({ alternateRenderTargets, answers, dataStorageMode, persistencePolicy, templateId, withMigrationUi, withTestPreset, withWpEnv, }: Omit<PlanBlockInput, "allowExistingDir" | "cwd" | "noInstall" | "packageManager" | "projectDir" | "variant">): BlockSpec;
|
|
110
118
|
export declare function buildTemplateVariablesFromBlockSpec(spec: BlockSpec): ScaffoldTemplateVariables;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getPackageVersions } from "./package-versions.js";
|
|
2
2
|
import { BUILTIN_BLOCK_METADATA_VERSION, COMPOUND_CHILD_BLOCK_METADATA_DEFAULTS, getBuiltInTemplateMetadataDefaults, } from "./template-defaults.js";
|
|
3
|
+
import { formatAlternateRenderTargets, parseAlternateRenderTargets, } from "./alternate-render-targets.js";
|
|
4
|
+
import { DEFAULT_COMPOUND_INNER_BLOCKS_PRESET_ID, getCompoundInnerBlocksPresetDefinition, } from "./compound-inner-blocks.js";
|
|
3
5
|
import { getTemplateById, } from "./template-registry.js";
|
|
4
6
|
import { toPascalCase, toSnakeCase, } from "./string-case.js";
|
|
5
7
|
import { buildBlockCssClassName, buildFrontendCssClassName, resolveScaffoldIdentifiers, } from "./scaffold-identifiers.js";
|
|
@@ -33,7 +35,7 @@ const DEFAULT_QUERY_LOOP_ALLOWED_CONTROLS = [
|
|
|
33
35
|
"author",
|
|
34
36
|
"search",
|
|
35
37
|
];
|
|
36
|
-
export function createBuiltInBlockSpec({ answers, dataStorageMode, persistencePolicy, templateId, withMigrationUi = false, withTestPreset = false, withWpEnv = false, }) {
|
|
38
|
+
export function createBuiltInBlockSpec({ alternateRenderTargets, answers, dataStorageMode, persistencePolicy, templateId, withMigrationUi = false, withTestPreset = false, withWpEnv = false, }) {
|
|
37
39
|
const template = getTemplateById(templateId);
|
|
38
40
|
const metadataDefaults = getBuiltInTemplateMetadataDefaults(templateId);
|
|
39
41
|
const identifiers = resolveScaffoldIdentifiers({
|
|
@@ -44,8 +46,17 @@ export function createBuiltInBlockSpec({ answers, dataStorageMode, persistencePo
|
|
|
44
46
|
});
|
|
45
47
|
const resolvedDataStorageMode = dataStorageMode ?? answers.dataStorageMode;
|
|
46
48
|
const resolvedPersistencePolicy = persistencePolicy ?? answers.persistencePolicy;
|
|
49
|
+
const parsedAlternateRenderTargets = parseAlternateRenderTargets(alternateRenderTargets);
|
|
50
|
+
const innerBlocksPreset = templateId === "compound"
|
|
51
|
+
? (answers.compoundInnerBlocksPreset ??
|
|
52
|
+
DEFAULT_COMPOUND_INNER_BLOCKS_PRESET_ID)
|
|
53
|
+
: DEFAULT_COMPOUND_INNER_BLOCKS_PRESET_ID;
|
|
47
54
|
return {
|
|
55
|
+
alternateRenderTargets: parsedAlternateRenderTargets,
|
|
48
56
|
block: identifiers,
|
|
57
|
+
compound: {
|
|
58
|
+
innerBlocksPreset,
|
|
59
|
+
},
|
|
49
60
|
metadata: {
|
|
50
61
|
category: metadataDefaults.category,
|
|
51
62
|
description: answers.description.trim(),
|
|
@@ -94,9 +105,15 @@ export function buildTemplateVariablesFromBlockSpec(spec) {
|
|
|
94
105
|
const textDomain = spec.block.textDomain;
|
|
95
106
|
const phpPrefix = spec.block.phpPrefix;
|
|
96
107
|
const phpPrefixUpper = phpPrefix.toUpperCase();
|
|
108
|
+
const alternateRenderTargets = [...spec.alternateRenderTargets];
|
|
109
|
+
const hasAlternateEmailRenderTarget = alternateRenderTargets.includes("email");
|
|
110
|
+
const hasAlternateMjmlRenderTarget = alternateRenderTargets.includes("mjml");
|
|
111
|
+
const hasAlternatePlainTextRenderTarget = alternateRenderTargets.includes("plain-text");
|
|
97
112
|
const compoundChildTitle = `${title} Item`;
|
|
98
113
|
const cssClassName = buildBlockCssClassName(namespace, slug);
|
|
99
114
|
const compoundChildCssClassName = buildBlockCssClassName(namespace, `${slug}-item`);
|
|
115
|
+
const compoundInnerBlocksPreset = spec.compound.innerBlocksPreset;
|
|
116
|
+
const compoundInnerBlocksPresetDefinition = getCompoundInnerBlocksPresetDefinition(compoundInnerBlocksPreset);
|
|
100
117
|
const persistenceEnabled = spec.persistence.enabled;
|
|
101
118
|
const dataStorageMode = persistenceEnabled ? spec.persistence.dataStorageMode : "custom-table";
|
|
102
119
|
const persistencePolicy = persistenceEnabled
|
|
@@ -104,6 +121,8 @@ export function buildTemplateVariablesFromBlockSpec(spec) {
|
|
|
104
121
|
: "authenticated";
|
|
105
122
|
const queryVariationNamespace = `${namespace}/${slug}`;
|
|
106
123
|
return {
|
|
124
|
+
alternateRenderTargetsCsv: formatAlternateRenderTargets(alternateRenderTargets),
|
|
125
|
+
alternateRenderTargetsJson: JSON.stringify(alternateRenderTargets),
|
|
107
126
|
apiClientPackageVersion,
|
|
108
127
|
author: spec.project.author,
|
|
109
128
|
blockRuntimePackageVersion,
|
|
@@ -117,6 +136,29 @@ export function buildTemplateVariablesFromBlockSpec(spec) {
|
|
|
117
136
|
compoundChildIcon: COMPOUND_CHILD_BLOCK_METADATA_DEFAULTS.icon,
|
|
118
137
|
compoundChildTitleJson: JSON.stringify(compoundChildTitle),
|
|
119
138
|
compoundPersistenceEnabled: spec.template.family === "compound" && persistenceEnabled ? "true" : "false",
|
|
139
|
+
compoundInnerBlocksDirectInsert: compoundInnerBlocksPresetDefinition.directInsert ? "true" : "false",
|
|
140
|
+
compoundInnerBlocksOrientation: compoundInnerBlocksPresetDefinition.orientation ?? "",
|
|
141
|
+
compoundInnerBlocksOrientationExpression: compoundInnerBlocksPresetDefinition.orientation
|
|
142
|
+
? `'${compoundInnerBlocksPresetDefinition.orientation}'`
|
|
143
|
+
: "undefined",
|
|
144
|
+
compoundInnerBlocksPreset,
|
|
145
|
+
compoundInnerBlocksPresetDescription: compoundInnerBlocksPresetDefinition.description,
|
|
146
|
+
compoundInnerBlocksPresetLabel: compoundInnerBlocksPresetDefinition.label,
|
|
147
|
+
compoundInnerBlocksTemplateLockExpression: compoundInnerBlocksPresetDefinition.templateLock === false
|
|
148
|
+
? "false"
|
|
149
|
+
: `'${compoundInnerBlocksPresetDefinition.templateLock}'`,
|
|
150
|
+
hasAlternateEmailRenderTarget: hasAlternateEmailRenderTarget
|
|
151
|
+
? "true"
|
|
152
|
+
: "false",
|
|
153
|
+
hasAlternateMjmlRenderTarget: hasAlternateMjmlRenderTarget
|
|
154
|
+
? "true"
|
|
155
|
+
: "false",
|
|
156
|
+
hasAlternatePlainTextRenderTarget: hasAlternatePlainTextRenderTarget
|
|
157
|
+
? "true"
|
|
158
|
+
: "false",
|
|
159
|
+
hasAlternateRenderTargets: alternateRenderTargets.length > 0
|
|
160
|
+
? "true"
|
|
161
|
+
: "false",
|
|
120
162
|
projectToolsPackageVersion,
|
|
121
163
|
cssClassName,
|
|
122
164
|
dashCase: slug,
|
|
@@ -115,6 +115,7 @@ function buildCompoundParentArtifact(variables) {
|
|
|
115
115
|
icon: variables.icon,
|
|
116
116
|
description: variables.description,
|
|
117
117
|
example: {},
|
|
118
|
+
allowedBlocks: [`${variables.namespace}/${variables.slugKebabCase}-item`],
|
|
118
119
|
supports: persistenceEnabled
|
|
119
120
|
? {
|
|
120
121
|
html: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const COMPOUND_CHILD_EDIT_TEMPLATE = "import type { BlockEditProps } from '@wp-typia/block-types/blocks/registration';\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\nimport { Notice } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nimport { useTypiaValidation } from './hooks';\nimport type { {{pascalCase}}ItemAttributes } from './types';\nimport {\n\tcreateAttributeUpdater,\n\tvalidate{{pascalCase}}ItemAttributes,\n} from './validators';\n\ntype EditProps = BlockEditProps< {{pascalCase}}ItemAttributes >;\n\nexport default function Edit( {\n\tattributes,\n\tsetAttributes,\n}: EditProps ) {\n\tconst updateAttribute = createAttributeUpdater( attributes, setAttributes );\n\tconst { errorMessages, isValid } = useTypiaValidation(\n\t\tattributes,\n\t\tvalidate{{pascalCase}}ItemAttributes\n\t);\n\n\treturn (\n\t\t<div { ...useBlockProps( { className: '{{compoundChildCssClassName}}' } ) }>\n\t\t\t<RichText\n\t\t\t\ttagName=\"h4\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__title\"\n\t\t\t\tvalue={ attributes.title ?? '' }\n\t\t\t\tonChange={ ( title ) => updateAttribute( 'title', title ) }\n\t\t\t\tplaceholder={ __( {{compoundChildTitleJson}}, '{{textDomain}}' ) }\n\t\t\t/>\n\t\t\t<RichText\n\t\t\t\ttagName=\"p\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__body\"\n\t\t\t\tvalue={ attributes.body ?? '' }\n\t\t\t\tonChange={ ( body ) => updateAttribute( 'body', body ) }\n\t\t\t\tplaceholder={ __( 'Add supporting details for this internal item.', '{{textDomain}}' ) }\n\t\t\t/>\n\t\t\t{ ! isValid && (\n\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{ errorMessages.map( ( error, index ) => <li key={ index }>{ error }</li> ) }\n\t\t\t\t\t</ul>\n\t\t\t\t</Notice>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n";
|
|
2
|
-
export declare const COMPOUND_CHILD_SAVE_TEMPLATE = "import { RichText, useBlockProps } from '@wordpress/block-editor';\n\nimport type { {{pascalCase}}ItemAttributes } from './types';\n\nexport default function Save( {\n\tattributes,\n}: {\n\tattributes: {{pascalCase}}ItemAttributes;\n} ) {\n\treturn (\n\t\t<div { ...useBlockProps.save( { className: '{{compoundChildCssClassName}}' } ) }>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"h4\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__title\"\n\t\t\t\tvalue={ attributes.title }\n\t\t\t/>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"p\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__body\"\n\t\t\t\tvalue={ attributes.body }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n";
|
|
1
|
+
export declare const COMPOUND_CHILD_EDIT_TEMPLATE = "import type { BlockEditProps } from '@wp-typia/block-types/blocks/registration';\nimport { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { Notice } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nimport metadata from './block-metadata';\nimport {\n\tgetChildInnerBlocksPropsOptions,\n\thasNestedChildBlocks,\n} from '../{{slugKebabCase}}/children';\nimport { useTypiaValidation } from './hooks';\nimport type { {{pascalCase}}ItemAttributes } from './types';\nimport {\n\tcreateAttributeUpdater,\n\tvalidate{{pascalCase}}ItemAttributes,\n} from './validators';\n\ntype EditProps = BlockEditProps< {{pascalCase}}ItemAttributes >;\ntype CompoundInnerBlocksProps = Parameters< typeof InnerBlocks >[ 0 ] & {\n\tdefaultBlock?: [ string, Record< string, unknown > ];\n\tdirectInsert?: boolean;\n};\n\nconst TypedInnerBlocks = InnerBlocks as unknown as (\n\tprops: CompoundInnerBlocksProps\n) => ReturnType< typeof InnerBlocks >;\n\nexport default function Edit( {\n\tattributes,\n\tsetAttributes,\n}: EditProps ) {\n\tconst updateAttribute = createAttributeUpdater( attributes, setAttributes );\n\tconst { errorMessages, isValid } = useTypiaValidation(\n\t\tattributes,\n\t\tvalidate{{pascalCase}}ItemAttributes\n\t);\n\tconst nestedInnerBlocksPropsOptions = getChildInnerBlocksPropsOptions(\n\t\tmetadata.name\n\t);\n\tconst showsNestedChildren = hasNestedChildBlocks( metadata.name );\n\n\treturn (\n\t\t<div { ...useBlockProps( { className: '{{compoundChildCssClassName}}' } ) }>\n\t\t\t<RichText\n\t\t\t\ttagName=\"h4\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__title\"\n\t\t\t\tvalue={ attributes.title ?? '' }\n\t\t\t\tonChange={ ( title ) => updateAttribute( 'title', title ) }\n\t\t\t\tplaceholder={ __( {{compoundChildTitleJson}}, '{{textDomain}}' ) }\n\t\t\t/>\n\t\t\t<RichText\n\t\t\t\ttagName=\"p\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__body\"\n\t\t\t\tvalue={ attributes.body ?? '' }\n\t\t\t\tonChange={ ( body ) => updateAttribute( 'body', body ) }\n\t\t\t\tplaceholder={ __( 'Add supporting details for this internal item.', '{{textDomain}}' ) }\n\t\t\t/>\n\t\t\t{ ! isValid && (\n\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{ errorMessages.map( ( error, index ) => <li key={ index }>{ error }</li> ) }\n\t\t\t\t\t</ul>\n\t\t\t\t</Notice>\n\t\t\t) }\n\t\t\t{ showsNestedChildren && (\n\t\t\t\t<div className=\"{{compoundChildCssClassName}}__children\">\n\t\t\t\t\t<TypedInnerBlocks\n\t\t\t\t\t\t{ ...( nestedInnerBlocksPropsOptions ?? {} ) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n";
|
|
2
|
+
export declare const COMPOUND_CHILD_SAVE_TEMPLATE = "import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';\n\nimport metadata from './block-metadata';\nimport { hasNestedChildBlocks } from '../{{slugKebabCase}}/children';\nimport type { {{pascalCase}}ItemAttributes } from './types';\n\nexport default function Save( {\n\tattributes,\n}: {\n\tattributes: {{pascalCase}}ItemAttributes;\n} ) {\n\tconst showsNestedChildren = hasNestedChildBlocks( metadata.name );\n\n\treturn (\n\t\t<div { ...useBlockProps.save( { className: '{{compoundChildCssClassName}}' } ) }>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"h4\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__title\"\n\t\t\t\tvalue={ attributes.title }\n\t\t\t/>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"p\"\n\t\t\t\tclassName=\"{{compoundChildCssClassName}}__body\"\n\t\t\t\tvalue={ attributes.body }\n\t\t\t/>\n\t\t\t{ showsNestedChildren && (\n\t\t\t\t<div className=\"{{compoundChildCssClassName}}__children\">\n\t\t\t\t\t<InnerBlocks.Content />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n";
|
|
3
3
|
export declare const COMPOUND_CHILD_INDEX_TEMPLATE = "import {\n\tregisterScaffoldBlockType,\n\ttype BlockConfiguration,\n} from '@wp-typia/block-types/blocks/registration';\nimport {\n\tbuildScaffoldBlockRegistration,\n\tparseScaffoldBlockMetadata,\n} from '@wp-typia/block-runtime/blocks';\n\nimport Edit from './edit';\nimport Save from './save';\nimport metadata from './block-metadata';\nimport '../{{slugKebabCase}}/style.scss';\n\nimport type { {{pascalCase}}ItemAttributes } from './types';\n\nconst registration = buildScaffoldBlockRegistration(\n\tparseScaffoldBlockMetadata<BlockConfiguration< {{pascalCase}}ItemAttributes >>( metadata ),\n\t{\n\t\tedit: Edit,\n\t\tsave: Save,\n\t}\n);\n\nregisterScaffoldBlockType(registration.name, registration.settings);\n";
|
|
4
4
|
export declare const COMPOUND_CHILD_VALIDATORS_TEMPLATE = "import typia from 'typia';\nimport currentManifest from './manifest-defaults-document';\nimport type {\n\t{{pascalCase}}ItemAttributes,\n\t{{pascalCase}}ItemValidationResult,\n} from './types';\nimport { createTemplateValidatorToolkit } from '../../validator-toolkit';\n\nconst scaffoldValidators = createTemplateValidatorToolkit< {{pascalCase}}ItemAttributes >( {\n\tassert: typia.createAssert< {{pascalCase}}ItemAttributes >(),\n\tclone: typia.misc.createClone< {{pascalCase}}ItemAttributes >() as (\n\t\tvalue: {{pascalCase}}ItemAttributes,\n\t) => {{pascalCase}}ItemAttributes,\n\tis: typia.createIs< {{pascalCase}}ItemAttributes >(),\n\tmanifest: currentManifest,\n\tprune: typia.misc.createPrune< {{pascalCase}}ItemAttributes >(),\n\trandom: typia.createRandom< {{pascalCase}}ItemAttributes >() as (\n\t\t...args: unknown[]\n\t) => {{pascalCase}}ItemAttributes,\n\tvalidate: typia.createValidate< {{pascalCase}}ItemAttributes >(),\n} );\n\nexport const validate{{pascalCase}}ItemAttributes =\n\tscaffoldValidators.validateAttributes as (\n\t\tattributes: unknown\n\t) => {{pascalCase}}ItemValidationResult;\n\nexport const validators = scaffoldValidators.validators;\n\nexport const sanitize{{pascalCase}}ItemAttributes =\n\tscaffoldValidators.sanitizeAttributes as (\n\t\tattributes: Partial< {{pascalCase}}ItemAttributes >\n\t) => {{pascalCase}}ItemAttributes;\n\nexport const createAttributeUpdater = scaffoldValidators.createAttributeUpdater;\n";
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export const COMPOUND_CHILD_EDIT_TEMPLATE = `import type { BlockEditProps } from '@wp-typia/block-types/blocks/registration';
|
|
2
|
-
import { RichText, useBlockProps } from '@wordpress/block-editor';
|
|
2
|
+
import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';
|
|
3
3
|
import { Notice } from '@wordpress/components';
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
|
|
6
|
+
import metadata from './block-metadata';
|
|
7
|
+
import {
|
|
8
|
+
\tgetChildInnerBlocksPropsOptions,
|
|
9
|
+
\thasNestedChildBlocks,
|
|
10
|
+
} from '../{{slugKebabCase}}/children';
|
|
6
11
|
import { useTypiaValidation } from './hooks';
|
|
7
12
|
import type { {{pascalCase}}ItemAttributes } from './types';
|
|
8
13
|
import {
|
|
@@ -11,6 +16,14 @@ import {
|
|
|
11
16
|
} from './validators';
|
|
12
17
|
|
|
13
18
|
type EditProps = BlockEditProps< {{pascalCase}}ItemAttributes >;
|
|
19
|
+
type CompoundInnerBlocksProps = Parameters< typeof InnerBlocks >[ 0 ] & {
|
|
20
|
+
\tdefaultBlock?: [ string, Record< string, unknown > ];
|
|
21
|
+
\tdirectInsert?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const TypedInnerBlocks = InnerBlocks as unknown as (
|
|
25
|
+
\tprops: CompoundInnerBlocksProps
|
|
26
|
+
) => ReturnType< typeof InnerBlocks >;
|
|
14
27
|
|
|
15
28
|
export default function Edit( {
|
|
16
29
|
\tattributes,
|
|
@@ -21,6 +34,10 @@ export default function Edit( {
|
|
|
21
34
|
\t\tattributes,
|
|
22
35
|
\t\tvalidate{{pascalCase}}ItemAttributes
|
|
23
36
|
\t);
|
|
37
|
+
\tconst nestedInnerBlocksPropsOptions = getChildInnerBlocksPropsOptions(
|
|
38
|
+
\t\tmetadata.name
|
|
39
|
+
\t);
|
|
40
|
+
\tconst showsNestedChildren = hasNestedChildBlocks( metadata.name );
|
|
24
41
|
|
|
25
42
|
\treturn (
|
|
26
43
|
\t\t<div { ...useBlockProps( { className: '{{compoundChildCssClassName}}' } ) }>
|
|
@@ -45,12 +62,21 @@ export default function Edit( {
|
|
|
45
62
|
\t\t\t\t\t</ul>
|
|
46
63
|
\t\t\t\t</Notice>
|
|
47
64
|
\t\t\t) }
|
|
65
|
+
\t\t\t{ showsNestedChildren && (
|
|
66
|
+
\t\t\t\t<div className="{{compoundChildCssClassName}}__children">
|
|
67
|
+
\t\t\t\t\t<TypedInnerBlocks
|
|
68
|
+
\t\t\t\t\t\t{ ...( nestedInnerBlocksPropsOptions ?? {} ) }
|
|
69
|
+
\t\t\t\t\t/>
|
|
70
|
+
\t\t\t\t</div>
|
|
71
|
+
\t\t\t) }
|
|
48
72
|
\t\t</div>
|
|
49
73
|
\t);
|
|
50
74
|
}
|
|
51
75
|
`;
|
|
52
|
-
export const COMPOUND_CHILD_SAVE_TEMPLATE = `import { RichText, useBlockProps } from '@wordpress/block-editor';
|
|
76
|
+
export const COMPOUND_CHILD_SAVE_TEMPLATE = `import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';
|
|
53
77
|
|
|
78
|
+
import metadata from './block-metadata';
|
|
79
|
+
import { hasNestedChildBlocks } from '../{{slugKebabCase}}/children';
|
|
54
80
|
import type { {{pascalCase}}ItemAttributes } from './types';
|
|
55
81
|
|
|
56
82
|
export default function Save( {
|
|
@@ -58,6 +84,8 @@ export default function Save( {
|
|
|
58
84
|
}: {
|
|
59
85
|
\tattributes: {{pascalCase}}ItemAttributes;
|
|
60
86
|
} ) {
|
|
87
|
+
\tconst showsNestedChildren = hasNestedChildBlocks( metadata.name );
|
|
88
|
+
|
|
61
89
|
\treturn (
|
|
62
90
|
\t\t<div { ...useBlockProps.save( { className: '{{compoundChildCssClassName}}' } ) }>
|
|
63
91
|
\t\t\t<RichText.Content
|
|
@@ -70,6 +98,11 @@ export default function Save( {
|
|
|
70
98
|
\t\t\t\tclassName="{{compoundChildCssClassName}}__body"
|
|
71
99
|
\t\t\t\tvalue={ attributes.body }
|
|
72
100
|
\t\t\t/>
|
|
101
|
+
\t\t\t{ showsNestedChildren && (
|
|
102
|
+
\t\t\t\t<div className="{{compoundChildCssClassName}}__children">
|
|
103
|
+
\t\t\t\t\t<InnerBlocks.Content />
|
|
104
|
+
\t\t\t\t</div>
|
|
105
|
+
\t\t\t) }
|
|
73
106
|
\t\t</div>
|
|
74
107
|
\t);
|
|
75
108
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const COMPOUND_PARENT_EDIT_TEMPLATE = "import type { BlockEditProps } from '@wp-typia/block-types/blocks/registration';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tInspectorControls,\n\tInnerBlocks,\n\tRichText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { Notice, PanelBody, ToggleControl } from '@wordpress/components';\n\nimport {\n\
|
|
1
|
+
export declare const COMPOUND_PARENT_EDIT_TEMPLATE = "import type { BlockEditProps } from '@wp-typia/block-types/blocks/registration';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tInspectorControls,\n\tInnerBlocks,\n\tRichText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { Notice, PanelBody, ToggleControl } from '@wordpress/components';\n\nimport {\n\tgetRootInnerBlocksPropsOptions,\n} from './children';\nimport { useTypiaValidation } from './hooks';\nimport type { {{pascalCase}}Attributes } from './types';\nimport {\n\tcreateAttributeUpdater,\n\tvalidate{{pascalCase}}Attributes,\n} from './validators';\n\ntype EditProps = BlockEditProps< {{pascalCase}}Attributes >;\ntype CompoundInnerBlocksProps = Parameters< typeof InnerBlocks >[ 0 ] & {\n\tdefaultBlock?: [ string, Record< string, unknown > ];\n\tdirectInsert?: boolean;\n};\n\nconst TypedInnerBlocks = InnerBlocks as unknown as (\n\tprops: CompoundInnerBlocksProps\n) => ReturnType< typeof InnerBlocks >;\n\nexport default function Edit( {\n\tattributes,\n\tsetAttributes,\n}: EditProps ) {\n\tconst { errorMessages, isValid } = useTypiaValidation(\n\t\tattributes,\n\t\tvalidate{{pascalCase}}Attributes\n\t);\n\tconst updateAttribute = createAttributeUpdater( attributes, setAttributes );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: '{{cssClassName}}',\n\t} );\n\tconst rootInnerBlocksPropsOptions = getRootInnerBlocksPropsOptions();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Compound Settings', '{{textDomain}}' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show dividers between items', '{{textDomain}}' ) }\n\t\t\t\t\t\tchecked={ attributes.showDividers ?? true }\n\t\t\t\t\t\tonChange={ ( value ) => updateAttribute( 'showDividers', value ) }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t\t{ ! isValid && (\n\t\t\t\t\t<PanelBody title={ __( 'Validation Errors', '{{textDomain}}' ) } initialOpen>\n\t\t\t\t\t\t{ errorMessages.map( ( error, index ) => (\n\t\t\t\t\t\t\t<Notice key={ index } status=\"error\" isDismissible={ false }>\n\t\t\t\t\t\t\t\t{ error }\n\t\t\t\t\t\t\t</Notice>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<RichText\n\t\t\t\t\ttagName=\"h3\"\n\t\t\t\t\tclassName=\"{{cssClassName}}__heading\"\n\t\t\t\t\tvalue={ attributes.heading }\n\t\t\t\t\tonChange={ ( heading ) => updateAttribute( 'heading', heading ) }\n\t\t\t\t\tplaceholder={ __( {{titleJson}}, '{{textDomain}}' ) }\n\t\t\t\t/>\n\t\t\t\t<RichText\n\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\tclassName=\"{{cssClassName}}__intro\"\n\t\t\t\t\tvalue={ attributes.intro ?? '' }\n\t\t\t\t\tonChange={ ( intro ) => updateAttribute( 'intro', intro ) }\n\t\t\t\t\tplaceholder={ __(\n\t\t\t\t\t\t'Add and reorder internal items inside this compound block.',\n\t\t\t\t\t\t'{{textDomain}}'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t{ ! isValid && (\n\t\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t{ errorMessages.map( ( error, index ) => <li key={ index }>{ error }</li> ) }\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</Notice>\n\t\t\t\t) }\n\t\t\t\t<div className=\"{{cssClassName}}__items\">\n\t\t\t\t\t<TypedInnerBlocks { ...rootInnerBlocksPropsOptions } />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n";
|
|
2
2
|
export declare const COMPOUND_PARENT_SAVE_TEMPLATE = "import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';\n\nimport type { {{pascalCase}}Attributes } from './types';\n\nexport default function Save( {\n\tattributes,\n}: {\n\tattributes: {{pascalCase}}Attributes;\n} ) {\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: '{{cssClassName}}',\n\t\t\t\t'data-show-dividers': ( attributes.showDividers ?? true ) ? 'true' : 'false',\n\t\t\t} ) }\n\t\t>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"h3\"\n\t\t\t\tclassName=\"{{cssClassName}}__heading\"\n\t\t\t\tvalue={ attributes.heading }\n\t\t\t/>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"p\"\n\t\t\t\tclassName=\"{{cssClassName}}__intro\"\n\t\t\t\tvalue={ attributes.intro ?? '' }\n\t\t\t/>\n\t\t\t<div className=\"{{cssClassName}}__items\">\n\t\t\t\t<InnerBlocks.Content />\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n";
|
|
3
3
|
export declare const COMPOUND_PARENT_INDEX_TEMPLATE = "import {\n\tregisterScaffoldBlockType,\n\ttype BlockConfiguration,\n} from '@wp-typia/block-types/blocks/registration';\nimport {\n\tbuildScaffoldBlockRegistration,\n\tparseScaffoldBlockMetadata,\n} from '@wp-typia/block-runtime/blocks';\n\nimport Edit from './edit';\nimport Save from './save';\nimport metadata from './block-metadata';\nimport './style.scss';\n\nimport type { {{pascalCase}}Attributes } from './types';\n\nconst registration = buildScaffoldBlockRegistration(\n\tparseScaffoldBlockMetadata<BlockConfiguration< {{pascalCase}}Attributes >>( metadata ),\n\t{\n\t\tedit: Edit,\n\t\tsave: Save,\n\t}\n);\n\nregisterScaffoldBlockType(registration.name, registration.settings);\n";
|
|
4
4
|
export declare const COMPOUND_LOCAL_HOOKS_TEMPLATE = "export {\n\tformatValidationError,\n\tformatValidationErrors,\n\tuseTypiaValidation,\n} from '../../hooks';\n\nexport type {\n\tTypiaValidationError,\n\tValidationResult,\n\tValidationState,\n} from '../../hooks';\n";
|
|
5
5
|
export declare const COMPOUND_PARENT_VALIDATORS_TEMPLATE = "import typia from 'typia';\nimport currentManifest from './manifest-defaults-document';\nimport type {\n\t{{pascalCase}}Attributes,\n\t{{pascalCase}}ValidationResult,\n} from './types';\nimport { createTemplateValidatorToolkit } from '../../validator-toolkit';\n\nconst scaffoldValidators = createTemplateValidatorToolkit< {{pascalCase}}Attributes >( {\n\tassert: typia.createAssert< {{pascalCase}}Attributes >(),\n\tclone: typia.misc.createClone< {{pascalCase}}Attributes >() as (\n\t\tvalue: {{pascalCase}}Attributes,\n\t) => {{pascalCase}}Attributes,\n\tis: typia.createIs< {{pascalCase}}Attributes >(),\n\tmanifest: currentManifest,\n\tprune: typia.misc.createPrune< {{pascalCase}}Attributes >(),\n\trandom: typia.createRandom< {{pascalCase}}Attributes >() as (\n\t\t...args: unknown[]\n\t) => {{pascalCase}}Attributes,\n\tvalidate: typia.createValidate< {{pascalCase}}Attributes >(),\n} );\n\nexport const validate{{pascalCase}}Attributes =\n\tscaffoldValidators.validateAttributes as (\n\t\tattributes: unknown\n\t) => {{pascalCase}}ValidationResult;\n\nexport const validators = scaffoldValidators.validators;\n\nexport const sanitize{{pascalCase}}Attributes =\n\tscaffoldValidators.sanitizeAttributes as (\n\t\tattributes: Partial< {{pascalCase}}Attributes >\n\t) => {{pascalCase}}Attributes;\n\nexport const createAttributeUpdater = scaffoldValidators.createAttributeUpdater;\n";
|
|
6
|
-
export declare const COMPOUND_CHILDREN_TEMPLATE = "import type { BlockTemplate } from '@wp-typia/block-types/blocks/registration';\n\nexport const DEFAULT_CHILD_BLOCK_NAME = '{{namespace}}/{{slugKebabCase}}-item';\n\nexport
|
|
6
|
+
export declare const COMPOUND_CHILDREN_TEMPLATE = "import type { BlockTemplate } from '@wp-typia/block-types/blocks/registration';\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport const DEFAULT_CHILD_BLOCK_NAME = '{{namespace}}/{{slugKebabCase}}-item';\n\nexport interface CompoundChildSpec {\n\tancestorKeys: string[];\n\tblockName: string;\n\tbodyPlaceholder: string;\n\tcontainer: boolean;\n\tfolderSlug: string;\n\tkey: string;\n\tplacement: 'nested' | 'root';\n\tsupportsInserter: boolean;\n\ttemplateInstances: Array< Record< string, unknown > >;\n\ttitle: string;\n}\n\nexport interface CompoundInnerBlocksConfig {\n\tdefaultBlock?: [ string, Record< string, unknown > ];\n\tdirectInsert: boolean;\n\torientation?: 'horizontal' | 'vertical';\n\ttemplate?: BlockTemplate;\n\ttemplateLock: false | 'insert' | 'all';\n}\n\nexport type CompoundInnerBlocksPropsOptions = CompoundInnerBlocksConfig & {\n\trenderAppender?: typeof InnerBlocks.ButtonBlockAppender;\n};\n\nexport const ROOT_INNER_BLOCKS_PRESET_ID = '{{compoundInnerBlocksPreset}}';\nexport const ROOT_INNER_BLOCKS_PRESET_DESCRIPTION =\n\t'{{compoundInnerBlocksPresetDescription}}';\n\nconst BASE_INNER_BLOCKS_CONFIG: Omit<\n\tCompoundInnerBlocksConfig,\n\t'defaultBlock' | 'template'\n> = {\n\tdirectInsert: {{compoundInnerBlocksDirectInsert}},\n\torientation: {{compoundInnerBlocksOrientationExpression}},\n\ttemplateLock: {{compoundInnerBlocksTemplateLockExpression}},\n};\n\nconst ROOT_BLOCK_NAME = '{{namespace}}/{{slugKebabCase}}';\n\nexport const COMPOUND_CHILD_SPECS: CompoundChildSpec[] = [\n\t{\n\t\tancestorKeys: [],\n\t\tblockName: DEFAULT_CHILD_BLOCK_NAME,\n\t\tbodyPlaceholder: 'Add supporting details for this internal item.',\n\t\tcontainer: false,\n\t\tfolderSlug: '{{slugKebabCase}}-item',\n\t\tkey: 'item',\n\t\tplacement: 'root',\n\t\tsupportsInserter: false,\n\t\ttemplateInstances: [\n\t\t\t{\n\t\t\t\tbody: 'Add supporting details for the first internal item.',\n\t\t\t\ttitle: 'First Item',\n\t\t\t},\n\t\t\t{\n\t\t\t\tbody: 'Add supporting details for the second internal item.',\n\t\t\t\ttitle: 'Second Item',\n\t\t\t},\n\t\t],\n\t\ttitle: '{{compoundChildTitle}}',\n\t},\n\t// add-child: insert new child specs here\n];\n\nfunction buildTemplateEntriesForSpec( spec: CompoundChildSpec ): BlockTemplate {\n\tconst nestedTemplate = buildNestedTemplateForKey( spec.key );\n\n\treturn spec.templateInstances.map( ( attributes ) =>\n\t\tnestedTemplate.length > 0\n\t\t\t? [ spec.blockName, attributes, nestedTemplate ]\n\t\t\t: [ spec.blockName, attributes ]\n\t);\n}\n\nfunction buildNestedTemplateForKey( key: string ): BlockTemplate {\n\treturn COMPOUND_CHILD_SPECS.filter(\n\t\t( spec ) =>\n\t\t\tspec.placement === 'nested' &&\n\t\t\tspec.ancestorKeys[ spec.ancestorKeys.length - 1 ] === key\n\t).flatMap( ( spec ) => buildTemplateEntriesForSpec( spec ) );\n}\n\nexport const DEFAULT_CHILD_TEMPLATE: BlockTemplate =\n\tCOMPOUND_CHILD_SPECS.filter( ( spec ) => spec.placement === 'root' ).flatMap(\n\t\t( spec ) => buildTemplateEntriesForSpec( spec )\n\t);\n\nfunction buildDefaultBlockEntry(\n\ttemplate?: BlockTemplate\n): [ string, Record< string, unknown > ] | undefined {\n\tif (\n\t\t! BASE_INNER_BLOCKS_CONFIG.directInsert ||\n\t\t! Array.isArray( template ) ||\n\t\ttemplate.length === 0 ||\n\t\ttypeof template[ 0 ]?.[ 0 ] !== 'string'\n\t) {\n\t\treturn undefined;\n\t}\n\n\treturn [ template[ 0 ][ 0 ], {} ];\n}\n\nfunction buildInnerBlocksPropsOptions(\n\tconfig: CompoundInnerBlocksConfig\n): CompoundInnerBlocksPropsOptions {\n\treturn {\n\t\t...config,\n\t\trenderAppender:\n\t\t\tconfig.templateLock === 'all'\n\t\t\t\t? undefined\n\t\t\t\t: InnerBlocks.ButtonBlockAppender,\n\t};\n}\n\nexport function getRootInnerBlocksConfig(): CompoundInnerBlocksConfig {\n\treturn {\n\t\t...BASE_INNER_BLOCKS_CONFIG,\n\t\tdefaultBlock: buildDefaultBlockEntry( DEFAULT_CHILD_TEMPLATE ),\n\t\ttemplate: DEFAULT_CHILD_TEMPLATE,\n\t};\n}\n\nexport function getRootInnerBlocksPropsOptions(): CompoundInnerBlocksPropsOptions {\n\treturn buildInnerBlocksPropsOptions( getRootInnerBlocksConfig() );\n}\n\nexport function getChildSpec( blockName: string ): CompoundChildSpec | undefined {\n\treturn COMPOUND_CHILD_SPECS.find( ( spec ) => spec.blockName === blockName );\n}\n\nexport function getChildTemplate(\n\tblockName: string\n): BlockTemplate | undefined {\n\tconst childSpec = getChildSpec( blockName );\n\tif ( ! childSpec ) {\n\t\treturn undefined;\n\t}\n\n\tconst nestedTemplate = buildNestedTemplateForKey( childSpec.key );\n\tif ( nestedTemplate.length > 0 ) {\n\t\treturn nestedTemplate;\n\t}\n\n\treturn childSpec.container ? [] : undefined;\n}\n\nexport function getChildInnerBlocksConfig(\n\tblockName: string\n): CompoundInnerBlocksConfig | undefined {\n\tconst childSpec = getChildSpec( blockName );\n\tif ( ! childSpec ) {\n\t\treturn undefined;\n\t}\n\n\tconst template = getChildTemplate( blockName );\n\n\tif ( ! childSpec.container && ! template ) {\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\t...BASE_INNER_BLOCKS_CONFIG,\n\t\tdefaultBlock: buildDefaultBlockEntry( template ),\n\t\ttemplate,\n\t};\n}\n\nexport function getChildInnerBlocksPropsOptions(\n\tblockName: string\n): CompoundInnerBlocksPropsOptions | undefined {\n\tconst config = getChildInnerBlocksConfig( blockName );\n\tif ( ! config ) {\n\t\treturn undefined;\n\t}\n\n\treturn buildInnerBlocksPropsOptions( config );\n}\n\nexport function hasNestedChildBlocks( blockName: string ): boolean {\n\tconst childSpec = getChildSpec( blockName );\n\tif ( ! childSpec ) {\n\t\treturn false;\n\t}\n\n\treturn childSpec.container || buildNestedTemplateForKey( childSpec.key ).length > 0;\n}\n\nexport function isRootCompoundChildBlock( blockName: string ): boolean {\n\tconst childSpec = getChildSpec( blockName );\n\treturn childSpec?.placement === 'root';\n}\n\nexport { ROOT_BLOCK_NAME };\n";
|