@seed-hypermedia/client 0.0.33 → 0.0.35
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/client.d.ts +1 -1
- package/dist/index.mjs +11 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type PublishDocumentInput = {
|
|
|
17
17
|
};
|
|
18
18
|
export type SeedClientOptions = {
|
|
19
19
|
fetch?: typeof globalThis.fetch;
|
|
20
|
-
headers?: Record<string, string
|
|
20
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
21
21
|
};
|
|
22
22
|
type PublishBlobsRequest = Extract<HMRequest, {
|
|
23
23
|
key: 'PublishBlobs';
|
package/dist/index.mjs
CHANGED
|
@@ -372,7 +372,7 @@ var QUERY_PARAM_SERIALIZERS = {
|
|
|
372
372
|
function createSeedClient(baseUrl, options) {
|
|
373
373
|
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
|
|
374
374
|
const fetchFn = (options == null ? void 0 : options.fetch) ?? globalThis.fetch;
|
|
375
|
-
const
|
|
375
|
+
const getDefaultHeaders = async () => typeof (options == null ? void 0 : options.headers) === "function" ? await options.headers() : (options == null ? void 0 : options.headers) ?? {};
|
|
376
376
|
async function request(key, input) {
|
|
377
377
|
const requestSchema = HMRequestSchema.options.find((schema) => schema.shape.key.value === key);
|
|
378
378
|
if (!requestSchema) {
|
|
@@ -385,6 +385,7 @@ function createSeedClient(baseUrl, options) {
|
|
|
385
385
|
throw new SeedValidationError(`Invalid input for ${key}: ${err instanceof Error ? err.message : String(err)}`);
|
|
386
386
|
}
|
|
387
387
|
let response;
|
|
388
|
+
const defaultHeaders = await getDefaultHeaders();
|
|
388
389
|
const isAction = HMActionSchema.options.some((s) => s.shape.key.value === key);
|
|
389
390
|
if (isAction) {
|
|
390
391
|
const url = `${normalizedBaseUrl}/api/${key}`;
|
|
@@ -3505,6 +3506,13 @@ function toHMBlockType(editorBlockType) {
|
|
|
3505
3506
|
if (editorBlockType === "query") return "Query";
|
|
3506
3507
|
return void 0;
|
|
3507
3508
|
}
|
|
3509
|
+
function toImageWidthNumber(width) {
|
|
3510
|
+
if (width == null ? void 0 : width.trim().endsWith("%")) {
|
|
3511
|
+
const percentage = Number(width.trim().slice(0, -1));
|
|
3512
|
+
return Number.isFinite(percentage) && percentage > 0 ? percentage : null;
|
|
3513
|
+
}
|
|
3514
|
+
return toNumber(width);
|
|
3515
|
+
}
|
|
3508
3516
|
function editorBlockToHMBlock(editorBlock) {
|
|
3509
3517
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3510
3518
|
const blockType = toHMBlockType(editorBlock.type);
|
|
@@ -3591,7 +3599,7 @@ function editorBlockToHMBlock(editorBlock) {
|
|
|
3591
3599
|
} else {
|
|
3592
3600
|
blockImage.link = "";
|
|
3593
3601
|
}
|
|
3594
|
-
const width =
|
|
3602
|
+
const width = toImageWidthNumber(editorBlock.props.width);
|
|
3595
3603
|
if (width) {
|
|
3596
3604
|
blockImage.attributes.width = width;
|
|
3597
3605
|
}
|
|
@@ -3804,7 +3812,7 @@ function hmBlockToEditorBlock(block) {
|
|
|
3804
3812
|
if (key == "width" || key == "size") {
|
|
3805
3813
|
if (typeof value == "number") {
|
|
3806
3814
|
;
|
|
3807
|
-
out.props[key] = String(value);
|
|
3815
|
+
out.props[key] = blockType === "image" && key === "width" && value > 0 && value <= 100 ? `${value}%` : String(value);
|
|
3808
3816
|
}
|
|
3809
3817
|
} else if (typeof value == "boolean") {
|
|
3810
3818
|
;
|