@marvalt/wadapter 2.0.0 → 2.2.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/README.md +27 -6
- package/dist/client/wordpress-client.d.ts.map +1 -1
- package/dist/generators/gravity-forms/gravity-forms-generator.d.ts +3 -3
- package/dist/generators/gravity-forms/gravity-forms-generator.d.ts.map +1 -1
- package/dist/generators/wordpress/wordpress-generator.d.ts.map +1 -1
- package/dist/gravity-forms/gravity-forms-client.d.ts.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.esm.js +214 -27
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +214 -27
- package/dist/index.js.map +1 -1
- package/dist/types/wordpress.d.ts +2 -0
- package/dist/types/wordpress.d.ts.map +1 -1
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -52,19 +52,7 @@ class WordPressClient {
|
|
|
52
52
|
'Content-Type': 'application/json',
|
|
53
53
|
};
|
|
54
54
|
// Add authentication based on mode
|
|
55
|
-
if (this.config.authMode === 'cloudflare_proxy')
|
|
56
|
-
// Add Cloudflare proxy authentication headers
|
|
57
|
-
if (this.config.appId) {
|
|
58
|
-
headers['x-app-id'] = this.config.appId;
|
|
59
|
-
}
|
|
60
|
-
if (this.config.workerSecret) {
|
|
61
|
-
headers['x-app-secret'] = this.config.workerSecret;
|
|
62
|
-
}
|
|
63
|
-
if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
|
|
64
|
-
headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
|
|
65
|
-
headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
55
|
+
if (this.config.authMode === 'cloudflare_proxy') ;
|
|
68
56
|
else {
|
|
69
57
|
// Direct mode - use basic auth
|
|
70
58
|
if (this.config.username && this.config.password) {
|
|
@@ -298,19 +286,7 @@ class GravityFormsClient {
|
|
|
298
286
|
...options.headers,
|
|
299
287
|
};
|
|
300
288
|
// Add authentication based on mode
|
|
301
|
-
if (this.config.authMode === 'cloudflare_proxy')
|
|
302
|
-
// Add Cloudflare proxy authentication headers
|
|
303
|
-
if (this.config.appId) {
|
|
304
|
-
headers['x-app-id'] = this.config.appId;
|
|
305
|
-
}
|
|
306
|
-
if (this.config.workerSecret) {
|
|
307
|
-
headers['x-app-secret'] = this.config.workerSecret;
|
|
308
|
-
}
|
|
309
|
-
if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
|
|
310
|
-
headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
|
|
311
|
-
headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
289
|
+
if (this.config.authMode === 'cloudflare_proxy') ;
|
|
314
290
|
else {
|
|
315
291
|
// Direct mode - use basic auth
|
|
316
292
|
if (this.config.username && this.config.password) {
|
|
@@ -2107,6 +2083,205 @@ function getFormById(id) {
|
|
|
2107
2083
|
return (gravityFormsStaticData?.forms ?? []).find(f => String(f.id) === key);
|
|
2108
2084
|
}
|
|
2109
2085
|
|
|
2086
|
+
let document;
|
|
2087
|
+
let offset;
|
|
2088
|
+
let output;
|
|
2089
|
+
let stack;
|
|
2090
|
+
const tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?=([^}]+|}+(?=})|(?!}\s+\/?-->)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g;
|
|
2091
|
+
function Block(blockName, attrs, innerBlocks, innerHTML, innerContent) {
|
|
2092
|
+
return {
|
|
2093
|
+
blockName,
|
|
2094
|
+
attrs,
|
|
2095
|
+
innerBlocks,
|
|
2096
|
+
innerHTML,
|
|
2097
|
+
innerContent
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
function Freeform(innerHTML) {
|
|
2101
|
+
return Block(null, {}, [], innerHTML, [innerHTML]);
|
|
2102
|
+
}
|
|
2103
|
+
function Frame(block, tokenStart, tokenLength, prevOffset, leadingHtmlStart) {
|
|
2104
|
+
return {
|
|
2105
|
+
block,
|
|
2106
|
+
tokenStart,
|
|
2107
|
+
tokenLength,
|
|
2108
|
+
prevOffset: prevOffset || tokenStart + tokenLength,
|
|
2109
|
+
leadingHtmlStart
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
const parse = (doc) => {
|
|
2113
|
+
document = doc;
|
|
2114
|
+
offset = 0;
|
|
2115
|
+
output = [];
|
|
2116
|
+
stack = [];
|
|
2117
|
+
tokenizer.lastIndex = 0;
|
|
2118
|
+
do {
|
|
2119
|
+
} while (proceed());
|
|
2120
|
+
return output;
|
|
2121
|
+
};
|
|
2122
|
+
function proceed() {
|
|
2123
|
+
const stackDepth = stack.length;
|
|
2124
|
+
const next = nextToken();
|
|
2125
|
+
const [tokenType, blockName, attrs, startOffset, tokenLength] = next;
|
|
2126
|
+
const leadingHtmlStart = startOffset > offset ? offset : null;
|
|
2127
|
+
switch (tokenType) {
|
|
2128
|
+
case "no-more-tokens":
|
|
2129
|
+
if (0 === stackDepth) {
|
|
2130
|
+
addFreeform();
|
|
2131
|
+
return false;
|
|
2132
|
+
}
|
|
2133
|
+
if (1 === stackDepth) {
|
|
2134
|
+
addBlockFromStack();
|
|
2135
|
+
return false;
|
|
2136
|
+
}
|
|
2137
|
+
while (0 < stack.length) {
|
|
2138
|
+
addBlockFromStack();
|
|
2139
|
+
}
|
|
2140
|
+
return false;
|
|
2141
|
+
case "void-block":
|
|
2142
|
+
if (0 === stackDepth) {
|
|
2143
|
+
if (null !== leadingHtmlStart) {
|
|
2144
|
+
output.push(
|
|
2145
|
+
Freeform(
|
|
2146
|
+
document.substr(
|
|
2147
|
+
leadingHtmlStart,
|
|
2148
|
+
startOffset - leadingHtmlStart
|
|
2149
|
+
)
|
|
2150
|
+
)
|
|
2151
|
+
);
|
|
2152
|
+
}
|
|
2153
|
+
output.push(Block(blockName, attrs, [], "", []));
|
|
2154
|
+
offset = startOffset + tokenLength;
|
|
2155
|
+
return true;
|
|
2156
|
+
}
|
|
2157
|
+
addInnerBlock(
|
|
2158
|
+
Block(blockName, attrs, [], "", []),
|
|
2159
|
+
startOffset,
|
|
2160
|
+
tokenLength
|
|
2161
|
+
);
|
|
2162
|
+
offset = startOffset + tokenLength;
|
|
2163
|
+
return true;
|
|
2164
|
+
case "block-opener":
|
|
2165
|
+
stack.push(
|
|
2166
|
+
Frame(
|
|
2167
|
+
Block(blockName, attrs, [], "", []),
|
|
2168
|
+
startOffset,
|
|
2169
|
+
tokenLength,
|
|
2170
|
+
startOffset + tokenLength,
|
|
2171
|
+
leadingHtmlStart
|
|
2172
|
+
)
|
|
2173
|
+
);
|
|
2174
|
+
offset = startOffset + tokenLength;
|
|
2175
|
+
return true;
|
|
2176
|
+
case "block-closer":
|
|
2177
|
+
if (0 === stackDepth) {
|
|
2178
|
+
addFreeform();
|
|
2179
|
+
return false;
|
|
2180
|
+
}
|
|
2181
|
+
if (1 === stackDepth) {
|
|
2182
|
+
addBlockFromStack(startOffset);
|
|
2183
|
+
offset = startOffset + tokenLength;
|
|
2184
|
+
return true;
|
|
2185
|
+
}
|
|
2186
|
+
const stackTop = stack.pop();
|
|
2187
|
+
const html = document.substr(
|
|
2188
|
+
stackTop.prevOffset,
|
|
2189
|
+
startOffset - stackTop.prevOffset
|
|
2190
|
+
);
|
|
2191
|
+
stackTop.block.innerHTML += html;
|
|
2192
|
+
stackTop.block.innerContent.push(html);
|
|
2193
|
+
stackTop.prevOffset = startOffset + tokenLength;
|
|
2194
|
+
addInnerBlock(
|
|
2195
|
+
stackTop.block,
|
|
2196
|
+
stackTop.tokenStart,
|
|
2197
|
+
stackTop.tokenLength,
|
|
2198
|
+
startOffset + tokenLength
|
|
2199
|
+
);
|
|
2200
|
+
offset = startOffset + tokenLength;
|
|
2201
|
+
return true;
|
|
2202
|
+
default:
|
|
2203
|
+
addFreeform();
|
|
2204
|
+
return false;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
function parseJSON(input) {
|
|
2208
|
+
try {
|
|
2209
|
+
return JSON.parse(input);
|
|
2210
|
+
} catch (e) {
|
|
2211
|
+
return null;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
function nextToken() {
|
|
2215
|
+
const matches = tokenizer.exec(document);
|
|
2216
|
+
if (null === matches) {
|
|
2217
|
+
return ["no-more-tokens", "", null, 0, 0];
|
|
2218
|
+
}
|
|
2219
|
+
const startedAt = matches.index;
|
|
2220
|
+
const [
|
|
2221
|
+
match,
|
|
2222
|
+
closerMatch,
|
|
2223
|
+
namespaceMatch,
|
|
2224
|
+
nameMatch,
|
|
2225
|
+
attrsMatch,
|
|
2226
|
+
,
|
|
2227
|
+
voidMatch
|
|
2228
|
+
] = matches;
|
|
2229
|
+
const length = match.length;
|
|
2230
|
+
const isCloser = !!closerMatch;
|
|
2231
|
+
const isVoid = !!voidMatch;
|
|
2232
|
+
const namespace = namespaceMatch || "core/";
|
|
2233
|
+
const name = namespace + nameMatch;
|
|
2234
|
+
const hasAttrs = !!attrsMatch;
|
|
2235
|
+
const attrs = hasAttrs ? parseJSON(attrsMatch) : {};
|
|
2236
|
+
if (isVoid) {
|
|
2237
|
+
return ["void-block", name, attrs, startedAt, length];
|
|
2238
|
+
}
|
|
2239
|
+
if (isCloser) {
|
|
2240
|
+
return ["block-closer", name, null, startedAt, length];
|
|
2241
|
+
}
|
|
2242
|
+
return ["block-opener", name, attrs, startedAt, length];
|
|
2243
|
+
}
|
|
2244
|
+
function addFreeform(rawLength) {
|
|
2245
|
+
const length = document.length - offset;
|
|
2246
|
+
if (0 === length) {
|
|
2247
|
+
return;
|
|
2248
|
+
}
|
|
2249
|
+
output.push(Freeform(document.substr(offset, length)));
|
|
2250
|
+
}
|
|
2251
|
+
function addInnerBlock(block, tokenStart, tokenLength, lastOffset) {
|
|
2252
|
+
const parent = stack[stack.length - 1];
|
|
2253
|
+
parent.block.innerBlocks.push(block);
|
|
2254
|
+
const html = document.substr(
|
|
2255
|
+
parent.prevOffset,
|
|
2256
|
+
tokenStart - parent.prevOffset
|
|
2257
|
+
);
|
|
2258
|
+
if (html) {
|
|
2259
|
+
parent.block.innerHTML += html;
|
|
2260
|
+
parent.block.innerContent.push(html);
|
|
2261
|
+
}
|
|
2262
|
+
parent.block.innerContent.push(null);
|
|
2263
|
+
parent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;
|
|
2264
|
+
}
|
|
2265
|
+
function addBlockFromStack(endOffset) {
|
|
2266
|
+
const { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();
|
|
2267
|
+
const html = endOffset ? document.substr(prevOffset, endOffset - prevOffset) : document.substr(prevOffset);
|
|
2268
|
+
if (html) {
|
|
2269
|
+
block.innerHTML += html;
|
|
2270
|
+
block.innerContent.push(html);
|
|
2271
|
+
}
|
|
2272
|
+
if (null !== leadingHtmlStart) {
|
|
2273
|
+
output.push(
|
|
2274
|
+
Freeform(
|
|
2275
|
+
document.substr(
|
|
2276
|
+
leadingHtmlStart,
|
|
2277
|
+
tokenStart - leadingHtmlStart
|
|
2278
|
+
)
|
|
2279
|
+
)
|
|
2280
|
+
);
|
|
2281
|
+
}
|
|
2282
|
+
output.push(block);
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2110
2285
|
/**
|
|
2111
2286
|
* @license GPL-3.0-or-later
|
|
2112
2287
|
*
|
|
@@ -2137,6 +2312,8 @@ class WordPressGenerator {
|
|
|
2137
2312
|
const data = await client.getAllData({
|
|
2138
2313
|
per_page: this.config.maxItems || 100,
|
|
2139
2314
|
_embed: this.config.includeEmbedded || false,
|
|
2315
|
+
// required for content.raw with Gutenberg comments
|
|
2316
|
+
context: 'edit',
|
|
2140
2317
|
});
|
|
2141
2318
|
// Create the static data structure matching the existing format
|
|
2142
2319
|
const staticData = {
|
|
@@ -2158,7 +2335,17 @@ class WordPressGenerator {
|
|
|
2158
2335
|
},
|
|
2159
2336
|
// Map the data to the expected structure
|
|
2160
2337
|
posts: data.posts,
|
|
2161
|
-
pages: data.pages
|
|
2338
|
+
pages: (data.pages || []).map((p) => {
|
|
2339
|
+
let blocks = [];
|
|
2340
|
+
try {
|
|
2341
|
+
const raw = p?.content?.raw || '';
|
|
2342
|
+
blocks = raw ? parse(raw) : [];
|
|
2343
|
+
}
|
|
2344
|
+
catch (e) {
|
|
2345
|
+
console.warn('⚠️ Failed to parse Gutenberg blocks for page', p?.id, e);
|
|
2346
|
+
}
|
|
2347
|
+
return { ...p, blocks };
|
|
2348
|
+
}),
|
|
2162
2349
|
media: data.media,
|
|
2163
2350
|
categories: data.categories,
|
|
2164
2351
|
tags: data.tags,
|