@devvit/public-api 0.11.0-next-2024-07-09-d548ed0e0.0 → 0.11.0-next-2024-07-09-2412ac001.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"BlocksReconciler.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/BlocksReconciler.ts"],"names":[],"mappings":"AA6CA,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC;IAC9C,QAAQ,EAAE,4BAA4B,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,mBAAmB,GAAG,MAAM,CAAC;AAYxE,wBAAgB,eAAe,CAC7B,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,OAAO,IAAI,mBAAmB,CAIxC"}
1
+ {"version":3,"file":"BlocksReconciler.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/BlocksReconciler.ts"],"names":[],"mappings":"AA+CA,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC;IAC9C,QAAQ,EAAE,4BAA4B,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,mBAAmB,GAAG,MAAM,CAAC;AAYxE,wBAAgB,eAAe,CAC7B,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,OAAO,IAAI,mBAAmB,CAIxC"}
@@ -11,6 +11,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
11
11
  };
12
12
  var _BlocksReconciler_instances, _BlocksReconciler_reset, _BlocksReconciler_makeContextProps, _BlocksReconciler_flatten, _BlocksReconciler_rerenderAlreadyScheduled;
13
13
  import { BlockRenderEventType, EffectType } from '@devvit/protos';
14
+ import { DEFAULT_DIMENSIONS } from '@devvit/shared-types/dimensions.js';
14
15
  import { Header } from '@devvit/shared-types/Header.js';
15
16
  import { makeAPIClients } from '../../../apis/makeAPIClients.js';
16
17
  import { getEffectsFromUIClient } from '../../../apis/ui/helpers/getEffectsFromUIClient.js';
@@ -154,6 +155,9 @@ export class BlocksReconciler {
154
155
  }
155
156
  return uniqueId;
156
157
  }
158
+ makeTransformContext(ctx) {
159
+ return { maxDimensions: ctx.dimensions ?? DEFAULT_DIMENSIONS };
160
+ }
157
161
  async reconcile() {
158
162
  const ctx = __classPrivateFieldGet(this, _BlocksReconciler_instances, "m", _BlocksReconciler_makeContextProps).call(this);
159
163
  const blockElement = {
@@ -163,7 +167,8 @@ export class BlocksReconciler {
163
167
  };
164
168
  const reified = await this.processBlock(blockElement);
165
169
  assertNotString(reified);
166
- this.transformer.createBlocksElementOrThrow(reified);
170
+ const transformContext = this.makeTransformContext(ctx);
171
+ this.transformer.createBlocksElementOrThrow(reified, transformContext);
167
172
  if (this.isUserActionRender && this.blockRenderEventId) {
168
173
  const handler = this.actions.get(this.blockRenderEventId);
169
174
  if (handler) {
@@ -184,7 +189,8 @@ export class BlocksReconciler {
184
189
  children: [],
185
190
  };
186
191
  const block = await this.renderElement(ctx, rootBlockElement);
187
- return this.transformer.ensureRootBlock(block);
192
+ const transformContext = this.makeTransformContext(ctx);
193
+ return this.transformer.ensureRootBlock(block, transformContext);
188
194
  }
189
195
  async renderElement(ctx, element) {
190
196
  const reified = await this.processBlock(element);
@@ -193,7 +199,8 @@ export class BlocksReconciler {
193
199
  console.debug(indentXML(toXML(reified)));
194
200
  if (Devvit.debug.emitState || ctx.debug.emitState)
195
201
  console.debug(JSON.stringify(this.state, undefined, 2));
196
- return this.transformer.createBlocksElementOrThrow(reified);
202
+ const transformContext = this.makeTransformContext(ctx);
203
+ return this.transformer.createBlocksElementOrThrow(reified, transformContext);
197
204
  }
198
205
  async processProps(block) {
199
206
  const props = block.props ?? {};
@@ -1,14 +1,18 @@
1
- import type { Block, BlockAction, BlockAlignment, BlockBorder, BlockColor, BlockConfig, BlockSize, BlockSizes, BlockSizes_Dimension_Value } from '@devvit/protos';
1
+ import type { Block, BlockAction, BlockAlignment, BlockBorder, BlockColor, BlockConfig, BlockSizes, Dimensions, UIDimensions } from '@devvit/protos';
2
2
  import { BlockAnimationDirection, BlockAnimationLoopMode, BlockAnimationType, BlockAvatarBackground, BlockAvatarFacing, BlockAvatarSize, BlockButtonAppearance, BlockButtonSize, BlockFullSnooSize, BlockGap, BlockIconSize, BlockImageResizeMode, BlockPadding, BlockRadius, BlockSpacerShape, BlockSpacerSize, BlockStackDirection, BlockTextOutline, BlockTextOverflow, BlockTextSize, BlockTextStyle, BlockTextWeight, BlockType } from '@devvit/protos';
3
3
  import { Devvit } from '../../Devvit.js';
4
4
  import type { ReifiedBlockElement, ReifiedBlockElementOrLiteral } from './BlocksReconciler.js';
5
5
  import type { AssetsClient, GetURLOptions } from '../../../apis/AssetsClient/AssetsClient.js';
6
+ export type TransformContext = {
7
+ /** The maximum size a block may take up per dimension (height/width), in pixels */
8
+ maxDimensions: Dimensions | UIDimensions;
9
+ };
6
10
  type DataSet = Record<string, unknown>;
7
11
  export declare class BlocksTransformer {
8
12
  #private;
9
13
  constructor(getAssetsClient?: () => AssetsClient | undefined);
10
- createBlocksElementOrThrow({ type, props, children }: ReifiedBlockElement): Block;
11
- createBlocksElement({ type, props, children }: ReifiedBlockElement): Block | undefined;
14
+ createBlocksElementOrThrow({ type, props, children }: ReifiedBlockElement, transformContext: TransformContext): Block;
15
+ createBlocksElement({ type, props, children }: ReifiedBlockElement, transformContext: TransformContext): Block | undefined;
12
16
  makeRootHeight(height: Devvit.Blocks.RootHeight): number;
13
17
  makeBlockPadding(padding: Devvit.Blocks.ContainerPadding | undefined): BlockPadding | undefined;
14
18
  makeBlockRadius(radius: Devvit.Blocks.ContainerCornerRadius | undefined): BlockRadius | undefined;
@@ -33,36 +37,34 @@ export declare class BlocksTransformer {
33
37
  makeBlockAnimationType(type: Devvit.Blocks.AnimationType | undefined): BlockAnimationType;
34
38
  makeBlockAnimationDirection(type: Devvit.Blocks.AnimationDirection | undefined): BlockAnimationDirection | undefined;
35
39
  makeBlockLoopMode(mode: Devvit.Blocks.AnimationLoop | undefined): BlockAnimationLoopMode | undefined;
36
- makeBlockSize(props: Devvit.Blocks.BaseProps | undefined): BlockSize | undefined;
37
- makeBlockSizes(props: Devvit.Blocks.BaseProps | undefined): BlockSizes | undefined;
38
- parseSize(size: Devvit.Blocks.SizeString | undefined): BlockSizes_Dimension_Value | undefined;
40
+ makeBlockSizes(props: Devvit.Blocks.BaseProps | undefined, maxDimensions: Dimensions | UIDimensions): BlockSizes | undefined;
39
41
  getDataSet(props: DataSet): DataSet;
40
42
  makeActions(_type: BlockType, props: {
41
43
  [key: string]: unknown;
42
44
  }): BlockAction[];
43
45
  blockColorToHex(color: Devvit.Blocks.ColorString | undefined, theme?: 'light' | 'dark'): Devvit.Blocks.ColorString | undefined;
44
- childrenToBlocks(children: ReifiedBlockElementOrLiteral[]): Block[];
46
+ childrenToBlocks(children: ReifiedBlockElementOrLiteral[], transformContext: TransformContext): Block[];
45
47
  getThemedColors(color: Devvit.Blocks.ColorString | undefined, light?: Devvit.Blocks.ColorString | undefined, dark?: Devvit.Blocks.ColorString | undefined): BlockColor | undefined;
46
48
  parsePixels(input: Devvit.Blocks.SizePixels | number): number;
47
49
  resolveAssetUrl(url: string, options?: GetURLOptions): string;
48
50
  childrenToString(children: ReifiedBlockElementOrLiteral[]): string;
49
- makeRoot(props: Devvit.Blocks.BaseProps | undefined, ...children: ReifiedBlockElementOrLiteral[]): Block;
50
- wrapRoot(props: Devvit.Blocks.BaseProps | undefined, children: Block[]): Block;
51
- makeStackBlock(direction: BlockStackDirection, props: Devvit.Blocks.StackProps | undefined, children: ReifiedBlockElementOrLiteral[]): Block;
52
- makeHStack(props: Devvit.Blocks.StackProps | undefined, ...children: ReifiedBlockElementOrLiteral[]): Block;
53
- makeVStack(props: Devvit.Blocks.StackProps | undefined, ...children: ReifiedBlockElementOrLiteral[]): Block;
54
- makeZStack(props: Devvit.Blocks.StackProps | undefined, ...children: ReifiedBlockElementOrLiteral[]): Block;
55
- makeText(props: Devvit.Blocks.TextProps | undefined, ...children: ReifiedBlockElementOrLiteral[]): Block;
56
- makeButton(props: Devvit.Blocks.ButtonProps | undefined, ...children: ReifiedBlockElementOrLiteral[]): Block;
57
- makeImage(props: Devvit.Blocks.ImageProps | undefined): Block | undefined;
58
- makeSpacer(props: Devvit.Blocks.SpacerProps | undefined): Block;
59
- makeIcon(props: Devvit.Blocks.IconProps | undefined): Block | undefined;
60
- makeAvatar(props: Devvit.Blocks.AvatarProps | undefined): Block | undefined;
61
- makeFullSnoo(props: Devvit.Blocks.FullSnooProps | undefined): Block | undefined;
62
- makeAnimation(props: Devvit.Blocks.AnimationProps | undefined): Block | undefined;
63
- makeWebView(props: Devvit.Blocks.WebViewProps | undefined): Block | undefined;
64
- makeBlock(type: BlockType, props: Devvit.Blocks.BaseProps | undefined, config?: BlockConfig | undefined): Block;
65
- ensureRootBlock(b: Block): Block;
51
+ makeRoot(props: Devvit.Blocks.BaseProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
52
+ wrapRoot(props: Devvit.Blocks.BaseProps | undefined, transformContext: TransformContext, children: Block[]): Block;
53
+ makeStackBlock(direction: BlockStackDirection, props: Devvit.Blocks.StackProps | undefined, transformContext: TransformContext, children: ReifiedBlockElementOrLiteral[]): Block;
54
+ makeHStack(props: Devvit.Blocks.StackProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
55
+ makeVStack(props: Devvit.Blocks.StackProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
56
+ makeZStack(props: Devvit.Blocks.StackProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
57
+ makeText(props: Devvit.Blocks.TextProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
58
+ makeButton(props: Devvit.Blocks.ButtonProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
59
+ makeImage(props: Devvit.Blocks.ImageProps | undefined, transformContext: TransformContext): Block | undefined;
60
+ makeSpacer(props: Devvit.Blocks.SpacerProps | undefined, transformContext: TransformContext): Block;
61
+ makeIcon(props: Devvit.Blocks.IconProps | undefined, transformContext: TransformContext): Block | undefined;
62
+ makeAvatar(props: Devvit.Blocks.AvatarProps | undefined, transformContext: TransformContext): Block | undefined;
63
+ makeFullSnoo(props: Devvit.Blocks.FullSnooProps | undefined, transformContext: TransformContext): Block | undefined;
64
+ makeAnimation(props: Devvit.Blocks.AnimationProps | undefined, transformContext: TransformContext): Block | undefined;
65
+ makeWebView(props: Devvit.Blocks.WebViewProps | undefined, transformContext: TransformContext): Block | undefined;
66
+ makeBlock(type: BlockType, props: Devvit.Blocks.BaseProps | undefined, transformContext: TransformContext, config?: BlockConfig | undefined): Block;
67
+ ensureRootBlock(b: Block, transformContext: TransformContext): Block;
66
68
  }
67
69
  export {};
68
70
  //# sourceMappingURL=BlocksTransformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BlocksTransformer.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/BlocksTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,UAAU,EACV,0BAA0B,EAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EAEf,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,QAAQ,EAER,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,WAAW,EAEX,gBA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AAS,GAC/B,KAAK;IAaR,eAAe,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK;CAkBjC"}
1
+ {"version":3,"file":"BlocksTransformer.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/BlocksTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EAEf,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,QAAQ,EAER,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,eAAe,EACf,SAAS,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAW/F,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAG9F,MAAM,MAAM,gBAAgB,GAAG;IAC7B,mFAAmF;IACnF,aAAa,EAAE,UAAU,GAAG,YAAY,CAAC;CAC1C,CAAC;AAEF,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AASvC,qBAAa,iBAAiB;;gBAGhB,eAAe,GAAE,MAAM,YAAY,GAAG,SAA2B;IAI7E,0BAA0B,CACxB,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,mBAAmB,EAC9C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK;IAQR,mBAAmB,CACjB,EAAE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E,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,EAC3C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK,GAAG,SAAS;IAepB,UAAU,CACR,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,SAAS,EAC5C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK;IASR,QAAQ,CACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,EAC1C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK,GAAG,SAAS;IAepB,UAAU,CACR,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,SAAS,EAC5C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK,GAAG,SAAS;IAcpB,YAAY,CACV,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,GAAG,SAAS,EAC9C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK,GAAG,SAAS;IAapB,aAAa,CACX,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,GAAG,SAAS,EAC/C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK,GAAG,SAAS;IAmBpB,WAAW,CACT,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,SAAS,EAC7C,gBAAgB,EAAE,gBAAgB,GACjC,KAAK,GAAG,SAAS;IAYpB,SAAS,CACP,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,EAC1C,gBAAgB,EAAE,gBAAgB,EAClC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,GAC/B,KAAK;IAWR,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,KAAK;CAkBrE"}
@@ -10,9 +10,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _BlocksTransformer_assetsClient;
13
- import { BlockActionType, BlockAnimationDirection, BlockAnimationLoopMode, BlockAnimationType, BlockAvatarBackground, BlockAvatarFacing, BlockAvatarSize, BlockBorderWidth, BlockButtonAppearance, BlockButtonSize, BlockFullSnooSize, BlockGap, BlockHorizontalAlignment, BlockIconSize, BlockImageResizeMode, BlockPadding, BlockRadius, BlockSizeUnit, BlockSpacerShape, BlockSpacerSize, BlockStackDirection, BlockTextOutline, BlockTextOverflow, BlockTextSize, BlockTextStyle, BlockTextWeight, BlockType, BlockVerticalAlignment, } from '@devvit/protos';
13
+ import { BlockActionType, BlockAnimationDirection, BlockAnimationLoopMode, BlockAnimationType, BlockAvatarBackground, BlockAvatarFacing, BlockAvatarSize, BlockBorderWidth, BlockButtonAppearance, BlockButtonSize, BlockFullSnooSize, BlockGap, BlockHorizontalAlignment, BlockIconSize, BlockImageResizeMode, BlockPadding, BlockRadius, BlockSpacerShape, BlockSpacerSize, BlockStackDirection, BlockTextOutline, BlockTextOverflow, BlockTextSize, BlockTextStyle, BlockTextWeight, BlockType, BlockVerticalAlignment, } from '@devvit/protos';
14
14
  import { Devvit } from '../../Devvit.js';
15
15
  import { getHexFromNamedHTMLColor, getHexFromRgbaColor, getHexFromRPLColor, isHexColor, isHslColor, isNamedHTMLColor, isRgbaColor, isRPLColor, } from '../helpers/color.js';
16
+ import { calculateMaxDimensions, makeDimensionValue } from './transformContext.js';
16
17
  const DATA_PREFIX = 'data-';
17
18
  const ACTION_HANDLERS = new Set(['onPress', 'onMessage']);
18
19
  const ACTION_TYPES = new Map([
@@ -24,41 +25,41 @@ export class BlocksTransformer {
24
25
  _BlocksTransformer_assetsClient.set(this, void 0);
25
26
  __classPrivateFieldSet(this, _BlocksTransformer_assetsClient, getAssetsClient, "f");
26
27
  }
27
- createBlocksElementOrThrow({ type, props, children }) {
28
- const block = this.createBlocksElement({ type, props, children });
28
+ createBlocksElementOrThrow({ type, props, children }, transformContext) {
29
+ const block = this.createBlocksElement({ type, props, children }, transformContext);
29
30
  if (!block) {
30
31
  throw new Error(`Could not create block of type ${type}`);
31
32
  }
32
33
  return block;
33
34
  }
34
- createBlocksElement({ type, props, children }) {
35
+ createBlocksElement({ type, props, children }, transformContext) {
35
36
  switch (type) {
36
37
  case 'blocks':
37
- return this.makeRoot(props, ...children);
38
+ return this.makeRoot(props, transformContext, ...children);
38
39
  case 'hstack':
39
- return this.makeHStack(props, ...children);
40
+ return this.makeHStack(props, transformContext, ...children);
40
41
  case 'vstack':
41
- return this.makeVStack(props, ...children);
42
+ return this.makeVStack(props, transformContext, ...children);
42
43
  case 'zstack':
43
- return this.makeZStack(props, ...children);
44
+ return this.makeZStack(props, transformContext, ...children);
44
45
  case 'text':
45
- return this.makeText(props, ...children);
46
+ return this.makeText(props, transformContext, ...children);
46
47
  case 'button':
47
- return this.makeButton(props, ...children);
48
+ return this.makeButton(props, transformContext, ...children);
48
49
  case 'image':
49
- return this.makeImage(props);
50
+ return this.makeImage(props, transformContext);
50
51
  case 'spacer':
51
- return this.makeSpacer(props);
52
+ return this.makeSpacer(props, transformContext);
52
53
  case 'icon':
53
- return this.makeIcon(props);
54
+ return this.makeIcon(props, transformContext);
54
55
  case 'avatar':
55
- return this.makeAvatar(props);
56
+ return this.makeAvatar(props, transformContext);
56
57
  case 'fullsnoo':
57
- return this.makeFullSnoo(props);
58
+ return this.makeFullSnoo(props, transformContext);
58
59
  case 'animation':
59
- return this.makeAnimation(props);
60
+ return this.makeAnimation(props, transformContext);
60
61
  case 'webview':
61
- return this.makeWebView(props);
62
+ return this.makeWebView(props, transformContext);
62
63
  case '__fragment':
63
64
  throw new Error("root fragment is not supported - use 'blocks' instead");
64
65
  }
@@ -394,21 +395,7 @@ export class BlocksTransformer {
394
395
  }
395
396
  return undefined;
396
397
  }
397
- makeBlockSize(props) {
398
- if (props && (props.width != null || props.height != null || props.grow)) {
399
- const { value: width, unit: widthUnit } = this.parseSize(props.width) ?? {};
400
- const { value: height, unit: heightUnit } = this.parseSize(props.height) ?? {};
401
- return {
402
- width,
403
- widthUnit,
404
- height,
405
- heightUnit,
406
- grow: props.grow,
407
- };
408
- }
409
- return undefined;
410
- }
411
- makeBlockSizes(props) {
398
+ makeBlockSizes(props, maxDimensions) {
412
399
  if (props) {
413
400
  const hasWidth = props.width != null || props.minWidth != null || props.maxWidth != null;
414
401
  const hasHeight = props.height != null || props.minHeight != null || props.maxHeight != null;
@@ -416,16 +403,16 @@ export class BlocksTransformer {
416
403
  return {
417
404
  width: hasWidth
418
405
  ? {
419
- value: this.parseSize(props.width),
420
- min: this.parseSize(props.minWidth),
421
- max: this.parseSize(props.maxWidth),
406
+ value: makeDimensionValue(props.width, maxDimensions.width),
407
+ min: makeDimensionValue(props.minWidth, maxDimensions.width),
408
+ max: makeDimensionValue(props.maxWidth, maxDimensions.width),
422
409
  }
423
410
  : undefined,
424
411
  height: hasHeight
425
412
  ? {
426
- value: this.parseSize(props.height),
427
- min: this.parseSize(props.minHeight),
428
- max: this.parseSize(props.maxHeight),
413
+ value: makeDimensionValue(props.height, maxDimensions.height),
414
+ min: makeDimensionValue(props.minHeight, maxDimensions.height),
415
+ max: makeDimensionValue(props.maxHeight, maxDimensions.height),
429
416
  }
430
417
  : undefined,
431
418
  grow: props.grow,
@@ -434,27 +421,6 @@ export class BlocksTransformer {
434
421
  }
435
422
  return undefined;
436
423
  }
437
- parseSize(size) {
438
- if (size == null)
439
- return undefined;
440
- if (typeof size === 'number') {
441
- return { value: size, unit: BlockSizeUnit.SIZE_UNIT_PERCENT };
442
- }
443
- // Regex:
444
- // Group 1: Digits with optional decimal trailer
445
- // Group 2: Optional suffix: 'px' or '%' (defaults to %)
446
- // eslint-disable-next-line security/detect-unsafe-regex
447
- const parts = size.match(/^(\d+(?:\.\d+)?)(px|%)?$/);
448
- if (parts == null) {
449
- return undefined;
450
- }
451
- let unit = BlockSizeUnit.SIZE_UNIT_PERCENT;
452
- if (parts?.at(2) === 'px') {
453
- unit = BlockSizeUnit.SIZE_UNIT_PIXELS;
454
- }
455
- const value = Number.parseFloat(parts[1]);
456
- return { value, unit };
457
- }
458
424
  getDataSet(props) {
459
425
  return Object.keys(props)
460
426
  .filter((key) => key.startsWith(DATA_PREFIX))
@@ -501,8 +467,10 @@ export class BlocksTransformer {
501
467
  console.warn(`Could not parse color: ${color}.`);
502
468
  return getHexFromNamedHTMLColor('red');
503
469
  }
504
- childrenToBlocks(children) {
505
- return children.flatMap((child) => (typeof child !== 'string' ? this.createBlocksElement(child) : undefined) ?? []);
470
+ childrenToBlocks(children, transformContext) {
471
+ return children.flatMap((child) => (typeof child !== 'string'
472
+ ? this.createBlocksElement(child, transformContext)
473
+ : undefined) ?? []);
506
474
  }
507
475
  getThemedColors(color, light, dark) {
508
476
  let lightColor = this.blockColorToHex(light, 'light');
@@ -542,11 +510,11 @@ export class BlocksTransformer {
542
510
  childrenToString(children) {
543
511
  return children.map((c) => c.toString()).join('');
544
512
  }
545
- makeRoot(props, ...children) {
546
- return this.wrapRoot(props, this.childrenToBlocks(children));
513
+ makeRoot(props, transformContext, ...children) {
514
+ return this.wrapRoot(props, transformContext, this.childrenToBlocks(children, transformContext));
547
515
  }
548
- wrapRoot(props, children) {
549
- return this.makeBlock(BlockType.BLOCK_ROOT, {}, {
516
+ wrapRoot(props, transformContext, children) {
517
+ return this.makeBlock(BlockType.BLOCK_ROOT, {}, transformContext, {
550
518
  rootConfig: {
551
519
  children: children,
552
520
  height: this.makeRootHeight(Devvit.customPostType?.height ??
@@ -555,15 +523,19 @@ export class BlocksTransformer {
555
523
  },
556
524
  });
557
525
  }
558
- makeStackBlock(direction, props, children) {
526
+ makeStackBlock(direction, props, transformContext, children) {
559
527
  const backgroundColors = this.getThemedColors(props?.backgroundColor, props?.lightBackgroundColor, props?.darkBackgroundColor);
560
- return this.makeBlock(BlockType.BLOCK_STACK, props, {
528
+ const childrenMaxDimensions = calculateMaxDimensions(props, transformContext.maxDimensions, direction, children.length);
529
+ return this.makeBlock(BlockType.BLOCK_STACK, props, transformContext, {
561
530
  stackConfig: {
562
531
  alignment: this.makeBlockAlignment(props?.alignment),
563
532
  backgroundColor: backgroundColors?.light,
564
533
  backgroundColors,
565
534
  border: this.makeBlockBorder(props?.border, props?.borderColor, props?.lightBorderColor, props?.darkBorderColor),
566
- children: this.childrenToBlocks(children),
535
+ children: this.childrenToBlocks(children, {
536
+ ...transformContext,
537
+ maxDimensions: childrenMaxDimensions,
538
+ }),
567
539
  cornerRadius: this.makeBlockRadius(props?.cornerRadius),
568
540
  direction: direction,
569
541
  gap: this.makeBlockGap(props?.gap),
@@ -572,18 +544,18 @@ export class BlocksTransformer {
572
544
  },
573
545
  });
574
546
  }
575
- makeHStack(props, ...children) {
576
- return this.makeStackBlock(BlockStackDirection.STACK_HORIZONTAL, props, children);
547
+ makeHStack(props, transformContext, ...children) {
548
+ return this.makeStackBlock(BlockStackDirection.STACK_HORIZONTAL, props, transformContext, children);
577
549
  }
578
- makeVStack(props, ...children) {
579
- return this.makeStackBlock(BlockStackDirection.STACK_VERTICAL, props, children);
550
+ makeVStack(props, transformContext, ...children) {
551
+ return this.makeStackBlock(BlockStackDirection.STACK_VERTICAL, props, transformContext, children);
580
552
  }
581
- makeZStack(props, ...children) {
582
- return this.makeStackBlock(BlockStackDirection.STACK_DEPTH, props, children);
553
+ makeZStack(props, transformContext, ...children) {
554
+ return this.makeStackBlock(BlockStackDirection.STACK_DEPTH, props, transformContext, children);
583
555
  }
584
- makeText(props, ...children) {
556
+ makeText(props, transformContext, ...children) {
585
557
  const colors = this.getThemedColors(props?.color, props?.lightColor, props?.darkColor);
586
- return this.makeBlock(BlockType.BLOCK_TEXT, props, {
558
+ return this.makeBlock(BlockType.BLOCK_TEXT, props, transformContext, {
587
559
  textConfig: {
588
560
  alignment: this.makeBlockAlignment(props?.alignment),
589
561
  color: colors?.light,
@@ -599,9 +571,9 @@ export class BlocksTransformer {
599
571
  },
600
572
  });
601
573
  }
602
- makeButton(props, ...children) {
574
+ makeButton(props, transformContext, ...children) {
603
575
  const textColors = this.getThemedColors(props?.textColor, props?.lightTextColor, props?.darkTextColor);
604
- return this.makeBlock(BlockType.BLOCK_BUTTON, props, {
576
+ return this.makeBlock(BlockType.BLOCK_BUTTON, props, transformContext, {
605
577
  buttonConfig: {
606
578
  buttonAppearance: this.makeBlockButtonAppearance(props?.appearance),
607
579
  // not available in all platforms yet
@@ -615,9 +587,9 @@ export class BlocksTransformer {
615
587
  },
616
588
  });
617
589
  }
618
- makeImage(props) {
590
+ makeImage(props, transformContext) {
619
591
  return (props &&
620
- this.makeBlock(BlockType.BLOCK_IMAGE, props, {
592
+ this.makeBlock(BlockType.BLOCK_IMAGE, props, transformContext, {
621
593
  imageConfig: {
622
594
  description: props?.description,
623
595
  resizeMode: this.makeBlockImageResizeMode(props.resizeMode),
@@ -627,18 +599,18 @@ export class BlocksTransformer {
627
599
  },
628
600
  }));
629
601
  }
630
- makeSpacer(props) {
631
- return this.makeBlock(BlockType.BLOCK_SPACER, props, {
602
+ makeSpacer(props, transformContext) {
603
+ return this.makeBlock(BlockType.BLOCK_SPACER, props, transformContext, {
632
604
  spacerConfig: {
633
605
  size: this.makeBlockSpacerSize(props?.size),
634
606
  shape: this.makeBlockSpacerShape(props?.shape),
635
607
  },
636
608
  });
637
609
  }
638
- makeIcon(props) {
610
+ makeIcon(props, transformContext) {
639
611
  const colors = this.getThemedColors(props?.color, props?.lightColor, props?.darkColor);
640
612
  return (props &&
641
- this.makeBlock(BlockType.BLOCK_ICON, props, {
613
+ this.makeBlock(BlockType.BLOCK_ICON, props, transformContext, {
642
614
  iconConfig: {
643
615
  icon: props.name,
644
616
  color: colors?.light,
@@ -647,9 +619,9 @@ export class BlocksTransformer {
647
619
  },
648
620
  }));
649
621
  }
650
- makeAvatar(props) {
622
+ makeAvatar(props, transformContext) {
651
623
  return (props &&
652
- this.makeBlock(BlockType.BLOCK_AVATAR, props, {
624
+ this.makeBlock(BlockType.BLOCK_AVATAR, props, transformContext, {
653
625
  avatarConfig: {
654
626
  thingId: props.thingId,
655
627
  size: this.makeBlockAvatarSize(props.size),
@@ -658,9 +630,9 @@ export class BlocksTransformer {
658
630
  },
659
631
  }));
660
632
  }
661
- makeFullSnoo(props) {
633
+ makeFullSnoo(props, transformContext) {
662
634
  return (props &&
663
- this.makeBlock(BlockType.BLOCK_FULLSNOO, props, {
635
+ this.makeBlock(BlockType.BLOCK_FULLSNOO, props, transformContext, {
664
636
  fullsnooConfig: {
665
637
  userId: props.userId,
666
638
  facing: this.makeBlockAvatarFacing(props.facing),
@@ -668,9 +640,9 @@ export class BlocksTransformer {
668
640
  },
669
641
  }));
670
642
  }
671
- makeAnimation(props) {
643
+ makeAnimation(props, transformContext) {
672
644
  return (props &&
673
- this.makeBlock(BlockType.BLOCK_ANIMATION, props, {
645
+ this.makeBlock(BlockType.BLOCK_ANIMATION, props, transformContext, {
674
646
  animationConfig: {
675
647
  type: this.makeBlockAnimationType(props.type),
676
648
  url: this.resolveAssetUrl(props.url),
@@ -684,28 +656,26 @@ export class BlocksTransformer {
684
656
  },
685
657
  }));
686
658
  }
687
- makeWebView(props) {
659
+ makeWebView(props, transformContext) {
688
660
  return (props &&
689
- this.makeBlock(BlockType.BLOCK_WEBVIEW, props, {
661
+ this.makeBlock(BlockType.BLOCK_WEBVIEW, props, transformContext, {
690
662
  webviewConfig: {
691
663
  url: this.resolveAssetUrl(props.url, { webview: true }),
692
664
  state: props.state,
693
665
  },
694
666
  }));
695
667
  }
696
- makeBlock(type, props, config) {
668
+ makeBlock(type, props, transformContext, config) {
697
669
  return {
698
670
  type,
699
- // TODO: remove once clients have all updated to handle sizes
700
- size: this.makeBlockSize(props),
701
- sizes: this.makeBlockSizes(props),
671
+ sizes: this.makeBlockSizes(props, transformContext.maxDimensions),
702
672
  config: config,
703
673
  actions: (props && this.makeActions(type, props)) ?? [],
704
674
  id: props?.id,
705
675
  key: props?.key,
706
676
  };
707
677
  }
708
- ensureRootBlock(b) {
678
+ ensureRootBlock(b, transformContext) {
709
679
  const block = b;
710
680
  if (block.type === BlockType.BLOCK_ROOT) {
711
681
  if (block.config?.rootConfig && Devvit.customPostType?.height) {
@@ -713,7 +683,7 @@ export class BlocksTransformer {
713
683
  }
714
684
  return block;
715
685
  }
716
- const root = this.wrapRoot(undefined, [block]);
686
+ const root = this.wrapRoot(undefined, transformContext, [block]);
717
687
  if (!root) {
718
688
  throw new Error('Could not create root block');
719
689
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BlocksHandler.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/BlocksHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAgB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAe,IAAI,EAAE,UAAU,EAAE,WAAW,EAAS,MAAM,YAAY,CAAC;AAGpF;;;;;;GAMG;AACH,eAAO,IAAI,oBAAoB,EAAE,aAAa,GAAG,IAAW,CAAC;AAE7D,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD;AAED,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CASxD;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,IAAI,EACzC,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,CAAC,GAChC,CAAC,CAiCH;AAED,eAAO,IAAI,oBAAoB,EAAE,aAAa,GAAG,IAAW,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,aAAa;;IAMxB,oBAAoB,EAAE,aAAa,GAAG,IAAI,CAAQ;gBAEtC,IAAI,EAAE,GAAG,CAAC,iBAAiB;IAMjC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CA8W1E"}
1
+ {"version":3,"file":"BlocksHandler.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/BlocksHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAQ7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAgB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAe,IAAI,EAAE,UAAU,EAAE,WAAW,EAAS,MAAM,YAAY,CAAC;AAGpF;;;;;;GAMG;AACH,eAAO,IAAI,oBAAoB,EAAE,aAAa,GAAG,IAAW,CAAC;AAE7D,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD;AAED,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CASxD;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,IAAI,EACzC,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,CAAC,GAChC,CAAC,CAiCH;AAED,eAAO,IAAI,oBAAoB,EAAE,aAAa,GAAG,IAAW,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,aAAa;;IAMxB,oBAAoB,EAAE,aAAa,GAAG,IAAI,CAAQ;gBAEtC,IAAI,EAAE,GAAG,CAAC,iBAAiB;IAMjC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAmX1E"}
@@ -9,7 +9,8 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _BlocksHandler_instances, _BlocksHandler_root, _BlocksHandler_contextBuilder, _BlocksHandler_blocksTransformer, _BlocksHandler_debug_get, _BlocksHandler_loadHooks, _BlocksHandler_handleAsyncQueues, _BlocksHandler_attemptHook, _BlocksHandler_handleMainQueue, _BlocksHandler_renderRoot, _BlocksHandler_render, _BlocksHandler_renderList, _BlocksHandler_renderElement, _BlocksHandler_reifyProps;
12
+ var _BlocksHandler_instances, _BlocksHandler_root, _BlocksHandler_contextBuilder, _BlocksHandler_blocksTransformer, _BlocksHandler_debug_get, _BlocksHandler_loadHooks, _BlocksHandler_handleAsyncQueues, _BlocksHandler_attemptHook, _BlocksHandler_handleMainQueue, _BlocksHandler_makeTransformContext, _BlocksHandler_renderRoot, _BlocksHandler_render, _BlocksHandler_renderList, _BlocksHandler_renderElement, _BlocksHandler_reifyProps;
13
+ import { DEFAULT_DIMENSIONS } from '@devvit/shared-types/dimensions.js';
13
14
  import isEqual from 'lodash.isequal';
14
15
  import { BlocksTransformer } from '../BlocksTransformer.js';
15
16
  import { ContextBuilder } from './ContextBuilder.js';
@@ -242,8 +243,9 @@ export class BlocksHandler {
242
243
  console.error('[blocks] Effects were mutated during rendering', context._effects, effectsCopy);
243
244
  }
244
245
  if (tags) {
245
- blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").createBlocksElementOrThrow(tags);
246
- blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").ensureRootBlock(blocks);
246
+ const transformContext = __classPrivateFieldGet(this, _BlocksHandler_instances, "m", _BlocksHandler_makeTransformContext).call(this, context);
247
+ blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").createBlocksElementOrThrow(tags, transformContext);
248
+ blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").ensureRootBlock(blocks, transformContext);
247
249
  }
248
250
  }
249
251
  return {
@@ -309,6 +311,8 @@ async function _BlocksHandler_handleAsyncQueues(context, ...batch) {
309
311
  }
310
312
  // TODO: Decide whether this is excessive. It doesn't hurt anything besides performance.
311
313
  __classPrivateFieldGet(this, _BlocksHandler_instances, "m", _BlocksHandler_loadHooks).call(this, context);
314
+ }, _BlocksHandler_makeTransformContext = function _BlocksHandler_makeTransformContext(context) {
315
+ return { maxDimensions: context.devvitContext.dimensions ?? DEFAULT_DIMENSIONS };
312
316
  }, _BlocksHandler_renderRoot = function _BlocksHandler_renderRoot(component, props, context) {
313
317
  if (__classPrivateFieldGet(this, _BlocksHandler_instances, "a", _BlocksHandler_debug_get))
314
318
  console.debug('[blocks] renderRoot');
@@ -0,0 +1,6 @@
1
+ import type { BlockSizes_Dimension_Value, Dimensions, UIDimensions } from '@devvit/protos';
2
+ import { BlockStackDirection } from '@devvit/protos';
3
+ import type { Devvit } from '../../Devvit.js';
4
+ export declare const makeDimensionValue: (size: Devvit.Blocks.SizeString | undefined, maxDimension: number) => BlockSizes_Dimension_Value | undefined;
5
+ export declare const calculateMaxDimensions: (props: Devvit.Blocks.StackProps | undefined, parentMaxDimensions: Dimensions | UIDimensions, stackDirection: BlockStackDirection, childrenCount: number) => UIDimensions;
6
+ //# sourceMappingURL=transformContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformContext.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/transformContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAiB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAK9C,eAAO,MAAM,kBAAkB,SACvB,OAAO,MAAM,CAAC,UAAU,GAAG,SAAS,gBAC5B,MAAM,KACnB,0BAA0B,GAAG,SAI/B,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAC1B,OAAO,MAAM,CAAC,UAAU,GAAG,SAAS,uBACtB,UAAU,GAAG,YAAY,kBAC9B,mBAAmB,iBACpB,MAAM,KACpB,YA6CF,CAAC"}