@diviops/mcp-server 1.5.29 → 1.5.30

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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `diviops-preset nav` block-markup emitter.
3
+ *
4
+ * Emits a small, Free-safe Divi 5 navigation drawer skeleton from a compact
5
+ * JSON spec. This MVP is dry-run only: it writes no WordPress content and
6
+ * does not add MCP/plugin routes. The output is serialized Divi block markup
7
+ * with the high-signal nav reliability contracts encoded up front:
8
+ *
9
+ * - one leaf `divi/text` button trigger with `aria-controls`;
10
+ * - one `divi/dropdown` panel with the matching custom `id`;
11
+ * - `forceVisible:"whileInBuilder"` for Visual Builder editability;
12
+ * - semantic submenu list shape: dropdown as `ul`, links wrapped with
13
+ * `htmlBefore:"<li>"` / `htmlAfter:"</li>"`;
14
+ * - non-empty boolean-style custom attrs;
15
+ * - wrapper-level tap-highlight suppression and a floating-width CSS guard.
16
+ */
17
+ export interface NavLinkSpec {
18
+ label: string;
19
+ url: string;
20
+ target?: "off" | "on" | "_self" | "_blank";
21
+ }
22
+ interface ParsedNavLinkSpec {
23
+ label: string;
24
+ url: string;
25
+ target: "off" | "on";
26
+ }
27
+ interface ParsedNavSectionSpec {
28
+ label: string;
29
+ links: ParsedNavLinkSpec[];
30
+ }
31
+ interface ParsedNavSpec {
32
+ label?: string;
33
+ idPrefix?: string;
34
+ items: Array<ParsedNavLinkSpec | ParsedNavSectionSpec>;
35
+ }
36
+ export interface NavItemSpec {
37
+ label: string;
38
+ url?: string;
39
+ target?: NavLinkSpec["target"];
40
+ links?: NavLinkSpec[];
41
+ }
42
+ export interface NavSpec {
43
+ label?: string;
44
+ idPrefix?: string;
45
+ items: NavItemSpec[];
46
+ }
47
+ export interface NavEmitterInput {
48
+ name: string;
49
+ spec: NavSpec;
50
+ }
51
+ export interface NavMarkupEntry {
52
+ type: "block_markup";
53
+ format: "divi_block_markup";
54
+ name: string;
55
+ markup: string;
56
+ notes: string[];
57
+ }
58
+ export declare function parseNavSpec(raw: unknown): ParsedNavSpec;
59
+ export declare function parseNavSpecJson(json: string): ParsedNavSpec;
60
+ export declare function emitNavBlockMarkup(input: NavEmitterInput): NavMarkupEntry;
61
+ export declare function buildNavMarkupBody(entry: NavMarkupEntry, opts?: {
62
+ dry_run?: boolean;
63
+ }): Record<string, unknown>;
64
+ export {};
@@ -0,0 +1,328 @@
1
+ /**
2
+ * `diviops-preset nav` block-markup emitter.
3
+ *
4
+ * Emits a small, Free-safe Divi 5 navigation drawer skeleton from a compact
5
+ * JSON spec. This MVP is dry-run only: it writes no WordPress content and
6
+ * does not add MCP/plugin routes. The output is serialized Divi block markup
7
+ * with the high-signal nav reliability contracts encoded up front:
8
+ *
9
+ * - one leaf `divi/text` button trigger with `aria-controls`;
10
+ * - one `divi/dropdown` panel with the matching custom `id`;
11
+ * - `forceVisible:"whileInBuilder"` for Visual Builder editability;
12
+ * - semantic submenu list shape: dropdown as `ul`, links wrapped with
13
+ * `htmlBefore:"<li>"` / `htmlAfter:"</li>"`;
14
+ * - non-empty boolean-style custom attrs;
15
+ * - wrapper-level tap-highlight suppression and a floating-width CSS guard.
16
+ */
17
+ const BUILDER_VERSION = "5.7.4";
18
+ function isPlainObject(value) {
19
+ return !!value && typeof value === "object" && !Array.isArray(value);
20
+ }
21
+ function assertNonEmptyString(value, field) {
22
+ if (typeof value !== "string" || value.trim() === "") {
23
+ throw new Error(`nav spec requires non-empty ${field}.`);
24
+ }
25
+ return value.trim();
26
+ }
27
+ function normalizeTarget(target) {
28
+ if (target === undefined || target === "off" || target === "_self") {
29
+ return "off";
30
+ }
31
+ if (target === "on" || target === "_blank") {
32
+ return "on";
33
+ }
34
+ throw new Error(`nav spec link target must be "off", "on", "_self", or "_blank"; got ${JSON.stringify(target)}.`);
35
+ }
36
+ function slugifyId(value) {
37
+ const slug = value
38
+ .trim()
39
+ .toLowerCase()
40
+ .replace(/[^a-z0-9_-]+/g, "-")
41
+ .replace(/^-+|-+$/g, "");
42
+ return slug || "nav";
43
+ }
44
+ function textContent(html) {
45
+ return {
46
+ content: {
47
+ innerContent: {
48
+ desktop: {
49
+ value: html,
50
+ },
51
+ },
52
+ },
53
+ };
54
+ }
55
+ function htmlAttrs(value) {
56
+ return {
57
+ module: {
58
+ advanced: {
59
+ html: {
60
+ desktop: {
61
+ value,
62
+ },
63
+ },
64
+ },
65
+ },
66
+ };
67
+ }
68
+ function mergeObjects(...objects) {
69
+ const merged = {};
70
+ for (const object of objects) {
71
+ for (const [key, value] of Object.entries(object)) {
72
+ if (isPlainObject(value) && isPlainObject(merged[key])) {
73
+ merged[key] = mergeObjects(merged[key], value);
74
+ }
75
+ else {
76
+ merged[key] = value;
77
+ }
78
+ }
79
+ }
80
+ return merged;
81
+ }
82
+ function customAttributes(attributes) {
83
+ return {
84
+ module: {
85
+ decoration: {
86
+ attributes: {
87
+ desktop: {
88
+ value: {
89
+ attributes: attributes.map((attr) => ({
90
+ targetElement: "main",
91
+ ...attr,
92
+ })),
93
+ },
94
+ },
95
+ },
96
+ },
97
+ },
98
+ };
99
+ }
100
+ function withBuilderVersion(attrs) {
101
+ return { ...attrs, builderVersion: BUILDER_VERSION };
102
+ }
103
+ function escapeBlockJson(json) {
104
+ return json
105
+ .replace(/\\\\/g, "\\u005c")
106
+ .replace(/\\"/g, "\\u0022")
107
+ .replace(/&/g, "\\u0026")
108
+ .replace(/</g, "\\u003c")
109
+ .replace(/>/g, "\\u003e")
110
+ .replace(/--/g, "\\u002d\\u002d");
111
+ }
112
+ function serializeAttrs(attrs) {
113
+ return escapeBlockJson(JSON.stringify(withBuilderVersion(attrs)));
114
+ }
115
+ function serializeBlock(name, attrs, innerBlocks = []) {
116
+ const blockName = `divi/${name}`;
117
+ const serializedAttrs = serializeAttrs(attrs);
118
+ if (innerBlocks.length === 0) {
119
+ return `<!-- wp:${blockName} ${serializedAttrs} /-->`;
120
+ }
121
+ return [
122
+ `<!-- wp:${blockName} ${serializedAttrs} -->`,
123
+ ...innerBlocks,
124
+ `<!-- /wp:${blockName} -->`,
125
+ ].join("\n");
126
+ }
127
+ function rootNavBlock(label, panelId, children) {
128
+ const css = "selector{-webkit-tap-highlight-color:transparent;}" +
129
+ "selector a:focus-visible,selector button:focus-visible{outline:2px solid currentColor;outline-offset:3px;}" +
130
+ "selector .et_pb_dropdown,selector .et_pb_dropdown_content{width:min(100vw,24rem);max-width:calc(100vw - 2rem);}";
131
+ return serializeBlock("group", mergeObjects(htmlAttrs({ elementType: "nav" }), customAttributes([
132
+ { name: "aria-label", value: label },
133
+ { name: "data-diviops-nav", value: "true" },
134
+ ]), {
135
+ module: {
136
+ decoration: {
137
+ layout: {
138
+ desktop: {
139
+ value: {
140
+ display: "flex",
141
+ flexDirection: "column",
142
+ gap: "0px",
143
+ },
144
+ },
145
+ },
146
+ },
147
+ },
148
+ css: {
149
+ desktop: {
150
+ value: {
151
+ freeForm: css,
152
+ },
153
+ },
154
+ },
155
+ }), [
156
+ serializeBlock("text", mergeObjects(htmlAttrs({ elementType: "button" }), customAttributes([
157
+ { name: "aria-controls", value: panelId },
158
+ { name: "aria-expanded", value: "false" },
159
+ { name: "data-diviops-nav-trigger", value: "true" },
160
+ ]), textContent(`<span>${escapeHtml(label)}</span>`))),
161
+ ...children,
162
+ ]);
163
+ }
164
+ function dropdownBlock(panelId, children) {
165
+ return serializeBlock("dropdown", mergeObjects(htmlAttrs({ elementType: "ul" }), customAttributes([
166
+ { name: "id", value: panelId },
167
+ { name: "role", value: "menu" },
168
+ { name: "aria-hidden", value: "true" },
169
+ ]), {
170
+ module: {
171
+ meta: {
172
+ meta: {
173
+ forceVisible: {
174
+ desktop: {
175
+ value: "whileInBuilder",
176
+ },
177
+ },
178
+ },
179
+ },
180
+ advanced: {
181
+ dropdown: {
182
+ desktop: {
183
+ value: {
184
+ showOn: "click",
185
+ position: "floating",
186
+ direction: "below",
187
+ alignment: "start",
188
+ },
189
+ },
190
+ },
191
+ },
192
+ decoration: {
193
+ layout: {
194
+ desktop: {
195
+ value: {
196
+ display: "flex",
197
+ flexDirection: "column",
198
+ gap: "0px",
199
+ },
200
+ },
201
+ },
202
+ },
203
+ },
204
+ }), children);
205
+ }
206
+ function linkBlock(link) {
207
+ return serializeBlock("link", mergeObjects(htmlAttrs({
208
+ htmlBefore: '<li role="none">',
209
+ htmlAfter: "</li>",
210
+ }), customAttributes([{ name: "role", value: "menuitem" }]), {
211
+ link: {
212
+ innerContent: {
213
+ desktop: {
214
+ value: {
215
+ text: link.label,
216
+ url: link.url,
217
+ target: link.target,
218
+ },
219
+ },
220
+ },
221
+ },
222
+ }));
223
+ }
224
+ function sectionLabelBlock(label) {
225
+ return serializeBlock("text", mergeObjects(htmlAttrs({ elementType: "li" }), customAttributes([{ name: "data-diviops-nav-section", value: "true" }]), textContent(`<span>${escapeHtml(label)}</span>`)));
226
+ }
227
+ function escapeHtml(value) {
228
+ return value
229
+ .replace(/&/g, "&amp;")
230
+ .replace(/</g, "&lt;")
231
+ .replace(/>/g, "&gt;")
232
+ .replace(/"/g, "&quot;");
233
+ }
234
+ function parseLinkSpec(raw, field) {
235
+ if (!isPlainObject(raw)) {
236
+ throw new Error(`nav spec ${field} must be an object.`);
237
+ }
238
+ const label = assertNonEmptyString(raw.label, `${field}.label`);
239
+ const url = assertNonEmptyString(raw.url, `${field}.url`);
240
+ const target = normalizeTarget(raw.target);
241
+ return { label, url, target };
242
+ }
243
+ export function parseNavSpec(raw) {
244
+ if (!isPlainObject(raw)) {
245
+ throw new Error("nav spec must be a JSON object.");
246
+ }
247
+ const itemsRaw = raw.items;
248
+ if (!Array.isArray(itemsRaw) || itemsRaw.length === 0) {
249
+ throw new Error("nav spec requires a non-empty items array.");
250
+ }
251
+ const spec = {
252
+ items: itemsRaw.map((itemRaw, itemIndex) => {
253
+ if (!isPlainObject(itemRaw)) {
254
+ throw new Error(`nav spec items[${itemIndex}] must be an object.`);
255
+ }
256
+ const label = assertNonEmptyString(itemRaw.label, `items[${itemIndex}].label`);
257
+ if (Array.isArray(itemRaw.links)) {
258
+ if (itemRaw.links.length === 0) {
259
+ throw new Error(`nav spec items[${itemIndex}].links must not be empty.`);
260
+ }
261
+ return {
262
+ label,
263
+ links: itemRaw.links.map((link, linkIndex) => parseLinkSpec(link, `items[${itemIndex}].links[${linkIndex}]`)),
264
+ };
265
+ }
266
+ return parseLinkSpec(itemRaw, `items[${itemIndex}]`);
267
+ }),
268
+ };
269
+ if (raw.label !== undefined) {
270
+ spec.label = assertNonEmptyString(raw.label, "label");
271
+ }
272
+ if (raw.idPrefix !== undefined) {
273
+ spec.idPrefix = assertNonEmptyString(raw.idPrefix, "idPrefix");
274
+ }
275
+ return spec;
276
+ }
277
+ export function parseNavSpecJson(json) {
278
+ let parsed;
279
+ try {
280
+ parsed = JSON.parse(json);
281
+ }
282
+ catch (err) {
283
+ throw new Error(`nav spec must be valid JSON: ${err instanceof Error ? err.message : String(err)}`);
284
+ }
285
+ return parseNavSpec(parsed);
286
+ }
287
+ export function emitNavBlockMarkup(input) {
288
+ const name = assertNonEmptyString(input.name, "name");
289
+ const spec = parseNavSpec(input.spec);
290
+ const label = spec.label ?? name;
291
+ const idPrefix = slugifyId(spec.idPrefix ?? name);
292
+ const panelId = `${idPrefix}-panel`;
293
+ const listChildren = [];
294
+ for (const item of spec.items) {
295
+ if ("links" in item) {
296
+ listChildren.push(sectionLabelBlock(item.label));
297
+ for (const link of item.links) {
298
+ listChildren.push(linkBlock(link));
299
+ }
300
+ }
301
+ else {
302
+ listChildren.push(linkBlock(item));
303
+ }
304
+ }
305
+ const markup = rootNavBlock(label, panelId, [dropdownBlock(panelId, listChildren)]);
306
+ return {
307
+ type: "block_markup",
308
+ format: "divi_block_markup",
309
+ name,
310
+ markup,
311
+ notes: [
312
+ "Dry-run only: no WordPress write path is invoked.",
313
+ "Use targeted create/clone/tree-surgery flows for placement; do not route this through whole-layout update paths.",
314
+ ],
315
+ };
316
+ }
317
+ export function buildNavMarkupBody(entry, opts = {}) {
318
+ const body = {
319
+ type: entry.type,
320
+ format: entry.format,
321
+ name: entry.name,
322
+ markup: entry.markup,
323
+ notes: entry.notes,
324
+ };
325
+ if (opts.dry_run)
326
+ body.dry_run = true;
327
+ return body;
328
+ }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@diviops/mcp-server",
3
- "version": "1.5.29",
3
+ "version": "1.5.30",
4
4
  "description": "MCP server exposing Divi 5 Visual Builder as tools for Claude",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
8
8
  "diviops-mcp": "dist/index.js",
9
- "diviops-preset": "dist/preset-cli/bin.js"
9
+ "diviops-preset": "dist/preset-cli/bin.js",
10
+ "diviops-cross-env-preflight": "dist/cross-env-preflight/bin.js"
10
11
  },
11
12
  "files": [
12
13
  "dist/**/*",
@@ -20,7 +21,7 @@
20
21
  "build": "tsc",
21
22
  "start": "node dist/index.js",
22
23
  "dev": "tsc --watch",
23
- "test": "npm run build && node --test \"dist/preset-cli/__tests__/*.test.js\"",
24
+ "test": "npm run build && node --test \"dist/preset-cli/__tests__/*.test.js\" \"dist/cross-env-preflight/__tests__/*.test.js\"",
24
25
  "prepublishOnly": "npm run build",
25
26
  "regen:skill": "node scripts/regen-module-formats.mjs"
26
27
  },