@shoplix-ai/sdui-schema 1.0.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/LICENSE +21 -0
- package/dist/action.d.ts +26 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/action.js +27 -0
- package/dist/action.js.map +1 -0
- package/dist/assets.d.ts +80 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +101 -0
- package/dist/assets.js.map +1 -0
- package/dist/binding.d.ts +144 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/binding.js +80 -0
- package/dist/binding.js.map +1 -0
- package/dist/block-definition.d.ts +1639 -0
- package/dist/block-definition.d.ts.map +1 -0
- package/dist/block-definition.js +527 -0
- package/dist/block-definition.js.map +1 -0
- package/dist/block-type-id.d.ts +15 -0
- package/dist/block-type-id.d.ts.map +1 -0
- package/dist/block-type-id.js +43 -0
- package/dist/block-type-id.js.map +1 -0
- package/dist/block-type.d.ts +21 -0
- package/dist/block-type.d.ts.map +1 -0
- package/dist/block-type.js +24 -0
- package/dist/block-type.js.map +1 -0
- package/dist/blocks.d.ts +922 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +353 -0
- package/dist/blocks.js.map +1 -0
- package/dist/definition-validator.d.ts +47 -0
- package/dist/definition-validator.d.ts.map +1 -0
- package/dist/definition-validator.js +340 -0
- package/dist/definition-validator.js.map +1 -0
- package/dist/display.d.ts +139 -0
- package/dist/display.d.ts.map +1 -0
- package/dist/display.js +118 -0
- package/dist/display.js.map +1 -0
- package/dist/envelope.d.ts +2721 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +116 -0
- package/dist/envelope.js.map +1 -0
- package/dist/icons.d.ts +10 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +49 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/locale.d.ts +11 -0
- package/dist/locale.d.ts.map +1 -0
- package/dist/locale.js +15 -0
- package/dist/locale.js.map +1 -0
- package/dist/manifest.d.ts +28 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +242 -0
- package/dist/manifest.js.map +1 -0
- package/dist/parse.d.ts +33 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +61 -0
- package/dist/parse.js.map +1 -0
- package/dist/path.d.ts +3 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +14 -0
- package/dist/path.js.map +1 -0
- package/dist/primitives.d.ts +1206 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +631 -0
- package/dist/primitives.js.map +1 -0
- package/dist/props.d.ts +9 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +12 -0
- package/dist/props.js.map +1 -0
- package/dist/screen.d.ts +57 -0
- package/dist/screen.d.ts.map +1 -0
- package/dist/screen.js +76 -0
- package/dist/screen.js.map +1 -0
- package/dist/starters/electronics.d.ts +3 -0
- package/dist/starters/electronics.d.ts.map +1 -0
- package/dist/starters/electronics.js +235 -0
- package/dist/starters/electronics.js.map +1 -0
- package/dist/starters/fashion.d.ts +3 -0
- package/dist/starters/fashion.d.ts.map +1 -0
- package/dist/starters/fashion.js +232 -0
- package/dist/starters/fashion.js.map +1 -0
- package/dist/starters/index.d.ts +5 -0
- package/dist/starters/index.d.ts.map +1 -0
- package/dist/starters/index.js +10 -0
- package/dist/starters/index.js.map +1 -0
- package/dist/starters/minimal.d.ts +3 -0
- package/dist/starters/minimal.d.ts.map +1 -0
- package/dist/starters/minimal.js +232 -0
- package/dist/starters/minimal.js.map +1 -0
- package/dist/starters/starter-seed.d.ts +17 -0
- package/dist/starters/starter-seed.d.ts.map +1 -0
- package/dist/starters/starter-seed.js +2 -0
- package/dist/starters/starter-seed.js.map +1 -0
- package/dist/theme.d.ts +54 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +68 -0
- package/dist/theme.js.map +1 -0
- package/dist/tokens.d.ts +115 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +349 -0
- package/dist/tokens.js.map +1 -0
- package/dist/version.d.ts +11 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rastova
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/action.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The closed action set for standalone tappable blocks. It doubles as the
|
|
4
|
+
* deep-link vocabulary for the future push composer. Cards inside bound
|
|
5
|
+
* lists navigate implicitly and never carry an action.
|
|
6
|
+
*/
|
|
7
|
+
export declare const actionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
|
+
type: z.ZodLiteral<"open_screen">;
|
|
9
|
+
screenId: z.ZodUUID;
|
|
10
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
11
|
+
type: z.ZodLiteral<"open_cart">;
|
|
12
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"open_url">;
|
|
14
|
+
url: z.ZodURL;
|
|
15
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"none">;
|
|
17
|
+
}, z.core.$strip>], "type">;
|
|
18
|
+
export type Action = z.infer<typeof actionSchema>;
|
|
19
|
+
export type ActionType = Action['type'];
|
|
20
|
+
/**
|
|
21
|
+
* One resolved value read back as an action, or nothing when it is not one.
|
|
22
|
+
* A setting a definition names may be absent from a placed block's props, and
|
|
23
|
+
* a renderer must draw nothing rather than run a guess.
|
|
24
|
+
*/
|
|
25
|
+
export declare function actionOf(value: unknown): Action | undefined;
|
|
26
|
+
//# sourceMappingURL=action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;2BAUvB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG3D"}
|
package/dist/action.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The closed action set for standalone tappable blocks. It doubles as the
|
|
4
|
+
* deep-link vocabulary for the future push composer. Cards inside bound
|
|
5
|
+
* lists navigate implicitly and never carry an action.
|
|
6
|
+
*/
|
|
7
|
+
export const actionSchema = z.discriminatedUnion('type', [
|
|
8
|
+
z.object({ type: z.literal('open_screen'), screenId: z.uuid() }),
|
|
9
|
+
z.object({ type: z.literal('open_cart') }),
|
|
10
|
+
z.object({
|
|
11
|
+
type: z.literal('open_url'),
|
|
12
|
+
url: z
|
|
13
|
+
.url()
|
|
14
|
+
.refine((value) => value.startsWith('https://'), { message: 'external links must be https' }),
|
|
15
|
+
}),
|
|
16
|
+
z.object({ type: z.literal('none') }),
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* One resolved value read back as an action, or nothing when it is not one.
|
|
20
|
+
* A setting a definition names may be absent from a placed block's props, and
|
|
21
|
+
* a renderer must draw nothing rather than run a guess.
|
|
22
|
+
*/
|
|
23
|
+
export function actionOf(value) {
|
|
24
|
+
const parsed = actionSchema.safeParse(value);
|
|
25
|
+
return parsed.success ? parsed.data : undefined;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACvD,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;IAChE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;IAC1C,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;QAC3B,GAAG,EAAE,CAAC;aACH,GAAG,EAAE;aACL,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC;KAChG,CAAC;IACF,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;CACtC,CAAC,CAAC;AAKH;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC"}
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Block } from './blocks.js';
|
|
3
|
+
/** One asset id a block carries, with the path of the prop that carries it. */
|
|
4
|
+
export interface AssetReference {
|
|
5
|
+
readonly assetId: string;
|
|
6
|
+
readonly path: readonly (string | number)[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Every asset id a block references. Owned here so the api never learns
|
|
10
|
+
* which prop of which block type carries an asset — a new asset-bearing
|
|
11
|
+
* block updates this walker in the same change.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assetReferencesOf(block: Block): readonly AssetReference[];
|
|
14
|
+
/** One picture a block cannot be published without, and does not have yet. */
|
|
15
|
+
export interface MissingMedia {
|
|
16
|
+
readonly path: readonly (string | number)[];
|
|
17
|
+
/** What the merchant still has to choose, in their own words. */
|
|
18
|
+
readonly label: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The media a block needs before a buyer can see it. An image block with no
|
|
22
|
+
* picture is a fine draft and a broken screen, so this is what the publish
|
|
23
|
+
* gate asks, and never what a save asks.
|
|
24
|
+
*/
|
|
25
|
+
export declare function missingMediaOf(block: Block): readonly MissingMedia[];
|
|
26
|
+
/**
|
|
27
|
+
* An editor holds half-filled media while the merchant works: alt text typed
|
|
28
|
+
* before the picture is chosen, a poster field opened and left empty. The
|
|
29
|
+
* document never carries a picture without an id, so those are dropped on the
|
|
30
|
+
* way out rather than saved as an empty one.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withoutUnchosenMedia<T extends Block>(block: T): T;
|
|
33
|
+
declare const assetRenditionSchema: z.ZodObject<{
|
|
34
|
+
url: z.ZodString;
|
|
35
|
+
width: z.ZodNumber;
|
|
36
|
+
height: z.ZodNumber;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
/**
|
|
39
|
+
* How an envelope serves one referenced asset: URLs assembled from config
|
|
40
|
+
* plus rendition data at serve time — documents keep carrying ids only.
|
|
41
|
+
*/
|
|
42
|
+
export declare const assetDisplaySchema: z.ZodObject<{
|
|
43
|
+
kind: z.ZodEnum<{
|
|
44
|
+
image: "image";
|
|
45
|
+
video: "video";
|
|
46
|
+
}>;
|
|
47
|
+
url: z.ZodString;
|
|
48
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
51
|
+
dominantColor: z.ZodOptional<z.ZodString>;
|
|
52
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
renditions: z.ZodArray<z.ZodObject<{
|
|
54
|
+
url: z.ZodString;
|
|
55
|
+
width: z.ZodNumber;
|
|
56
|
+
height: z.ZodNumber;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
export declare const envelopeAssetsSchema: z.ZodDefault<z.ZodRecord<z.ZodUUID, z.ZodObject<{
|
|
60
|
+
kind: z.ZodEnum<{
|
|
61
|
+
image: "image";
|
|
62
|
+
video: "video";
|
|
63
|
+
}>;
|
|
64
|
+
url: z.ZodString;
|
|
65
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
66
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
68
|
+
dominantColor: z.ZodOptional<z.ZodString>;
|
|
69
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
renditions: z.ZodArray<z.ZodObject<{
|
|
71
|
+
url: z.ZodString;
|
|
72
|
+
width: z.ZodNumber;
|
|
73
|
+
height: z.ZodNumber;
|
|
74
|
+
}, z.core.$strip>>;
|
|
75
|
+
}, z.core.$strip>>>;
|
|
76
|
+
export type AssetRendition = z.infer<typeof assetRenditionSchema>;
|
|
77
|
+
export type AssetDisplay = z.infer<typeof assetDisplaySchema>;
|
|
78
|
+
export type EnvelopeAssets = z.infer<typeof envelopeAssetsSchema>;
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAe,KAAK,KAAK,EAAmB,MAAM,aAAa,CAAC;AAIvE,+EAA+E;AAC/E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,cAAc,EAAE,CA0BzE;AAED,8EAA8E;AAC9E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC5C,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,YAAY,EAAE,CAYpE;AAID;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAkBjE;AAED,QAAA,MAAM,oBAAoB;;;;iBAIxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;iBAS7B,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;mBAAqD,CAAC;AAEvF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BLOCK_TYPES } from './blocks.js';
|
|
3
|
+
const KNOWN_TYPES = new Set(BLOCK_TYPES);
|
|
4
|
+
/**
|
|
5
|
+
* Every asset id a block references. Owned here so the api never learns
|
|
6
|
+
* which prop of which block type carries an asset — a new asset-bearing
|
|
7
|
+
* block updates this walker in the same change.
|
|
8
|
+
*/
|
|
9
|
+
export function assetReferencesOf(block) {
|
|
10
|
+
if (!KNOWN_TYPES.has(block.type))
|
|
11
|
+
return [];
|
|
12
|
+
const known = block;
|
|
13
|
+
switch (known.type) {
|
|
14
|
+
case 'image':
|
|
15
|
+
return known.props.image
|
|
16
|
+
? [{ assetId: known.props.image.assetId, path: ['props', 'image', 'assetId'] }]
|
|
17
|
+
: [];
|
|
18
|
+
case 'video': {
|
|
19
|
+
const refs = [];
|
|
20
|
+
if (known.props.assetId) {
|
|
21
|
+
refs.push({ assetId: known.props.assetId, path: ['props', 'assetId'] });
|
|
22
|
+
}
|
|
23
|
+
if (known.props.poster) {
|
|
24
|
+
refs.push({ assetId: known.props.poster.assetId, path: ['props', 'poster', 'assetId'] });
|
|
25
|
+
}
|
|
26
|
+
return refs;
|
|
27
|
+
}
|
|
28
|
+
case 'hero_banner':
|
|
29
|
+
case 'promo_banner':
|
|
30
|
+
return known.props.image
|
|
31
|
+
? [{ assetId: known.props.image.assetId, path: ['props', 'image', 'assetId'] }]
|
|
32
|
+
: [];
|
|
33
|
+
default:
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The media a block needs before a buyer can see it. An image block with no
|
|
39
|
+
* picture is a fine draft and a broken screen, so this is what the publish
|
|
40
|
+
* gate asks, and never what a save asks.
|
|
41
|
+
*/
|
|
42
|
+
export function missingMediaOf(block) {
|
|
43
|
+
if (!KNOWN_TYPES.has(block.type))
|
|
44
|
+
return [];
|
|
45
|
+
const known = block;
|
|
46
|
+
switch (known.type) {
|
|
47
|
+
case 'image':
|
|
48
|
+
case 'promo_banner':
|
|
49
|
+
return known.props.image ? [] : [{ path: ['props', 'image'], label: 'an image' }];
|
|
50
|
+
case 'video':
|
|
51
|
+
return known.props.assetId ? [] : [{ path: ['props', 'assetId'], label: 'a video' }];
|
|
52
|
+
default:
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* An editor holds half-filled media while the merchant works: alt text typed
|
|
58
|
+
* before the picture is chosen, a poster field opened and left empty. The
|
|
59
|
+
* document never carries a picture without an id, so those are dropped on the
|
|
60
|
+
* way out rather than saved as an empty one.
|
|
61
|
+
*/
|
|
62
|
+
export function withoutUnchosenMedia(block) {
|
|
63
|
+
const props = block.props;
|
|
64
|
+
if (!props)
|
|
65
|
+
return block;
|
|
66
|
+
const cleaned = { ...props };
|
|
67
|
+
let changed = false;
|
|
68
|
+
for (const key of ['image', 'poster']) {
|
|
69
|
+
const ref = cleaned[key];
|
|
70
|
+
if (ref && !ref.assetId) {
|
|
71
|
+
delete cleaned[key];
|
|
72
|
+
changed = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (cleaned.assetId === '') {
|
|
76
|
+
delete cleaned.assetId;
|
|
77
|
+
changed = true;
|
|
78
|
+
}
|
|
79
|
+
return changed ? { ...block, props: cleaned } : block;
|
|
80
|
+
}
|
|
81
|
+
const assetRenditionSchema = z.object({
|
|
82
|
+
url: z.string().min(1),
|
|
83
|
+
width: z.number().int().positive(),
|
|
84
|
+
height: z.number().int().positive(),
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* How an envelope serves one referenced asset: URLs assembled from config
|
|
88
|
+
* plus rendition data at serve time — documents keep carrying ids only.
|
|
89
|
+
*/
|
|
90
|
+
export const assetDisplaySchema = z.object({
|
|
91
|
+
kind: z.enum(['image', 'video']),
|
|
92
|
+
url: z.string().min(1),
|
|
93
|
+
width: z.number().int().positive().optional(),
|
|
94
|
+
height: z.number().int().positive().optional(),
|
|
95
|
+
placeholder: z.string().min(1).optional(),
|
|
96
|
+
dominantColor: z.string().min(1).optional(),
|
|
97
|
+
durationMs: z.number().int().positive().optional(),
|
|
98
|
+
renditions: z.array(assetRenditionSchema),
|
|
99
|
+
});
|
|
100
|
+
export const envelopeAssetsSchema = z.record(z.uuid(), assetDisplaySchema).default({});
|
|
101
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,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CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACzC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC3C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAClD,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC;CAC1C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,kBAAkB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const PRODUCT_SORT_KEYS: readonly ["collection_default", "best_selling", "newest", "price_asc", "price_desc", "title"];
|
|
3
|
+
declare const productSortKeySchema: z.ZodEnum<{
|
|
4
|
+
collection_default: "collection_default";
|
|
5
|
+
best_selling: "best_selling";
|
|
6
|
+
newest: "newest";
|
|
7
|
+
price_asc: "price_asc";
|
|
8
|
+
price_desc: "price_desc";
|
|
9
|
+
title: "title";
|
|
10
|
+
}>;
|
|
11
|
+
/** The two ways a Binding names its target: a chosen entity, or the Screen Subject. */
|
|
12
|
+
export declare const BINDING_TARGET_FORMS: readonly ["literal", "subject"];
|
|
13
|
+
/**
|
|
14
|
+
* A Binding targets either a chosen entity (literal) or the Screen Subject.
|
|
15
|
+
* Whether a subject form is valid on a given screen kind is the validation
|
|
16
|
+
* ladder's call, driven by the block manifest.
|
|
17
|
+
*/
|
|
18
|
+
declare const entityTargetSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
19
|
+
form: z.ZodLiteral<"literal">;
|
|
20
|
+
id: z.ZodString;
|
|
21
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
22
|
+
form: z.ZodLiteral<"subject">;
|
|
23
|
+
}, z.core.$strip>], "form">;
|
|
24
|
+
export declare const productBindingSchema: z.ZodObject<{
|
|
25
|
+
kind: z.ZodLiteral<"product">;
|
|
26
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
27
|
+
form: z.ZodLiteral<"literal">;
|
|
28
|
+
id: z.ZodString;
|
|
29
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
30
|
+
form: z.ZodLiteral<"subject">;
|
|
31
|
+
}, z.core.$strip>], "form">;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
/** The subject-only narrowing used by blocks welded to the Screen Subject. */
|
|
34
|
+
export declare const subjectProductBindingSchema: z.ZodObject<{
|
|
35
|
+
kind: z.ZodLiteral<"product">;
|
|
36
|
+
target: z.ZodObject<{
|
|
37
|
+
form: z.ZodLiteral<"subject">;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
/** The literal-only narrowing used by blocks that always pick their product. */
|
|
41
|
+
export declare const literalProductBindingSchema: z.ZodObject<{
|
|
42
|
+
kind: z.ZodLiteral<"product">;
|
|
43
|
+
target: z.ZodObject<{
|
|
44
|
+
form: z.ZodLiteral<"literal">;
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export declare const productsBindingSchema: z.ZodObject<{
|
|
49
|
+
kind: z.ZodLiteral<"products">;
|
|
50
|
+
selection: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
51
|
+
mode: z.ZodLiteral<"handpicked">;
|
|
52
|
+
ids: z.ZodArray<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
54
|
+
mode: z.ZodLiteral<"collection">;
|
|
55
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
56
|
+
form: z.ZodLiteral<"literal">;
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
59
|
+
form: z.ZodLiteral<"subject">;
|
|
60
|
+
}, z.core.$strip>], "form">;
|
|
61
|
+
limit: z.ZodNumber;
|
|
62
|
+
sort: z.ZodEnum<{
|
|
63
|
+
collection_default: "collection_default";
|
|
64
|
+
best_selling: "best_selling";
|
|
65
|
+
newest: "newest";
|
|
66
|
+
price_asc: "price_asc";
|
|
67
|
+
price_desc: "price_desc";
|
|
68
|
+
title: "title";
|
|
69
|
+
}>;
|
|
70
|
+
}, z.core.$strip>], "mode">;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export declare const collectionBindingSchema: z.ZodObject<{
|
|
73
|
+
kind: z.ZodLiteral<"collection">;
|
|
74
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
75
|
+
form: z.ZodLiteral<"literal">;
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
78
|
+
form: z.ZodLiteral<"subject">;
|
|
79
|
+
}, z.core.$strip>], "form">;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
export declare const collectionsBindingSchema: z.ZodObject<{
|
|
82
|
+
kind: z.ZodLiteral<"collections">;
|
|
83
|
+
ids: z.ZodArray<z.ZodString>;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
/**
|
|
86
|
+
* The four provider-silent Binding kinds. A Binding never names a data
|
|
87
|
+
* source; resolving it into display shapes is a Provider's job.
|
|
88
|
+
*/
|
|
89
|
+
export declare const bindingSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
90
|
+
kind: z.ZodLiteral<"product">;
|
|
91
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
92
|
+
form: z.ZodLiteral<"literal">;
|
|
93
|
+
id: z.ZodString;
|
|
94
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
95
|
+
form: z.ZodLiteral<"subject">;
|
|
96
|
+
}, z.core.$strip>], "form">;
|
|
97
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
98
|
+
kind: z.ZodLiteral<"products">;
|
|
99
|
+
selection: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
100
|
+
mode: z.ZodLiteral<"handpicked">;
|
|
101
|
+
ids: z.ZodArray<z.ZodString>;
|
|
102
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
103
|
+
mode: z.ZodLiteral<"collection">;
|
|
104
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
105
|
+
form: z.ZodLiteral<"literal">;
|
|
106
|
+
id: z.ZodString;
|
|
107
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
108
|
+
form: z.ZodLiteral<"subject">;
|
|
109
|
+
}, z.core.$strip>], "form">;
|
|
110
|
+
limit: z.ZodNumber;
|
|
111
|
+
sort: z.ZodEnum<{
|
|
112
|
+
collection_default: "collection_default";
|
|
113
|
+
best_selling: "best_selling";
|
|
114
|
+
newest: "newest";
|
|
115
|
+
price_asc: "price_asc";
|
|
116
|
+
price_desc: "price_desc";
|
|
117
|
+
title: "title";
|
|
118
|
+
}>;
|
|
119
|
+
}, z.core.$strip>], "mode">;
|
|
120
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
121
|
+
kind: z.ZodLiteral<"collection">;
|
|
122
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
123
|
+
form: z.ZodLiteral<"literal">;
|
|
124
|
+
id: z.ZodString;
|
|
125
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
126
|
+
form: z.ZodLiteral<"subject">;
|
|
127
|
+
}, z.core.$strip>], "form">;
|
|
128
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
129
|
+
kind: z.ZodLiteral<"collections">;
|
|
130
|
+
ids: z.ZodArray<z.ZodString>;
|
|
131
|
+
}, z.core.$strip>], "kind">;
|
|
132
|
+
export type EntityTarget = z.infer<typeof entityTargetSchema>;
|
|
133
|
+
export type BindingTargetForm = EntityTarget['form'];
|
|
134
|
+
export type ProductSortKey = z.infer<typeof productSortKeySchema>;
|
|
135
|
+
export type ProductBinding = z.infer<typeof productBindingSchema>;
|
|
136
|
+
export type ProductsBinding = z.infer<typeof productsBindingSchema>;
|
|
137
|
+
export type CollectionBinding = z.infer<typeof collectionBindingSchema>;
|
|
138
|
+
export type CollectionsBinding = z.infer<typeof collectionsBindingSchema>;
|
|
139
|
+
export type Binding = z.infer<typeof bindingSchema>;
|
|
140
|
+
export type BindingKind = Binding['kind'];
|
|
141
|
+
/** A JSON Schema for one Binding kind, for an editor completing a file that carries one. */
|
|
142
|
+
export declare function describeBinding(kind: BindingKind): Record<string, unknown>;
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,iBAAiB,+FAOpB,CAAC;AAEX,QAAA,MAAM,oBAAoB;;;;;;;EAA4B,CAAC;AAEvD,uFAAuF;AACvF,eAAO,MAAM,oBAAoB,iCAAkC,CAAC;AAEpE;;;;GAIG;AACH,QAAA,MAAM,kBAAkB;;;;;2BAGtB,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;iBAG/B,CAAC;AAEH,8EAA8E;AAC9E,eAAO,MAAM,2BAA2B;;;;;iBAGtC,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,2BAA2B;;;;;;iBAGtC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;iBAchC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;iBAGlC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;iBAGnC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAKxB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAS1C,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE1E"}
|
package/dist/binding.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const entityIdSchema = z.string().regex(/^\d+$/, 'expected a Shopify numeric id as a string');
|
|
3
|
+
export const PRODUCT_SORT_KEYS = [
|
|
4
|
+
'collection_default',
|
|
5
|
+
'best_selling',
|
|
6
|
+
'newest',
|
|
7
|
+
'price_asc',
|
|
8
|
+
'price_desc',
|
|
9
|
+
'title',
|
|
10
|
+
];
|
|
11
|
+
const productSortKeySchema = z.enum(PRODUCT_SORT_KEYS);
|
|
12
|
+
/** The two ways a Binding names its target: a chosen entity, or the Screen Subject. */
|
|
13
|
+
export const BINDING_TARGET_FORMS = ['literal', 'subject'];
|
|
14
|
+
/**
|
|
15
|
+
* A Binding targets either a chosen entity (literal) or the Screen Subject.
|
|
16
|
+
* Whether a subject form is valid on a given screen kind is the validation
|
|
17
|
+
* ladder's call, driven by the block manifest.
|
|
18
|
+
*/
|
|
19
|
+
const entityTargetSchema = z.discriminatedUnion('form', [
|
|
20
|
+
z.object({ form: z.literal('literal'), id: entityIdSchema }),
|
|
21
|
+
z.object({ form: z.literal('subject') }),
|
|
22
|
+
]);
|
|
23
|
+
export const productBindingSchema = z.object({
|
|
24
|
+
kind: z.literal('product'),
|
|
25
|
+
target: entityTargetSchema,
|
|
26
|
+
});
|
|
27
|
+
/** The subject-only narrowing used by blocks welded to the Screen Subject. */
|
|
28
|
+
export const subjectProductBindingSchema = z.object({
|
|
29
|
+
kind: z.literal('product'),
|
|
30
|
+
target: z.object({ form: z.literal('subject') }),
|
|
31
|
+
});
|
|
32
|
+
/** The literal-only narrowing used by blocks that always pick their product. */
|
|
33
|
+
export const literalProductBindingSchema = z.object({
|
|
34
|
+
kind: z.literal('product'),
|
|
35
|
+
target: z.object({ form: z.literal('literal'), id: entityIdSchema }),
|
|
36
|
+
});
|
|
37
|
+
export const productsBindingSchema = z.object({
|
|
38
|
+
kind: z.literal('products'),
|
|
39
|
+
selection: z.discriminatedUnion('mode', [
|
|
40
|
+
z.object({
|
|
41
|
+
mode: z.literal('handpicked'),
|
|
42
|
+
ids: z.array(entityIdSchema).min(1).max(24),
|
|
43
|
+
}),
|
|
44
|
+
z.object({
|
|
45
|
+
mode: z.literal('collection'),
|
|
46
|
+
target: entityTargetSchema,
|
|
47
|
+
limit: z.number().int().min(1).max(24),
|
|
48
|
+
sort: productSortKeySchema,
|
|
49
|
+
}),
|
|
50
|
+
]),
|
|
51
|
+
});
|
|
52
|
+
export const collectionBindingSchema = z.object({
|
|
53
|
+
kind: z.literal('collection'),
|
|
54
|
+
target: entityTargetSchema,
|
|
55
|
+
});
|
|
56
|
+
export const collectionsBindingSchema = z.object({
|
|
57
|
+
kind: z.literal('collections'),
|
|
58
|
+
ids: z.array(entityIdSchema).min(1).max(24),
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* The four provider-silent Binding kinds. A Binding never names a data
|
|
62
|
+
* source; resolving it into display shapes is a Provider's job.
|
|
63
|
+
*/
|
|
64
|
+
export const bindingSchema = z.discriminatedUnion('kind', [
|
|
65
|
+
productBindingSchema,
|
|
66
|
+
productsBindingSchema,
|
|
67
|
+
collectionBindingSchema,
|
|
68
|
+
collectionsBindingSchema,
|
|
69
|
+
]);
|
|
70
|
+
const bindingSchemaByKind = {
|
|
71
|
+
product: productBindingSchema,
|
|
72
|
+
products: productsBindingSchema,
|
|
73
|
+
collection: collectionBindingSchema,
|
|
74
|
+
collections: collectionsBindingSchema,
|
|
75
|
+
};
|
|
76
|
+
/** A JSON Schema for one Binding kind, for an editor completing a file that carries one. */
|
|
77
|
+
export function describeBinding(kind) {
|
|
78
|
+
return z.toJSONSchema(bindingSchemaByKind[kind], { unrepresentable: 'any' });
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,2CAA2C,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,oBAAoB;IACpB,cAAc;IACd,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,OAAO;CACC,CAAC;AAEX,MAAM,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAEvD,uFAAuF;AACvF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,SAAS,CAAU,CAAC;AAEpE;;;;GAIG;A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