@devvit/public-api 0.11.0-next-2024-07-22-0a49bf500.0 → 0.11.0-next-2024-07-23-33f5f2eff.0
Sign up to get free protection for your applications and to get access to all the features.
- package/devvit/internals/blocks/BlocksReconciler.d.ts.map +1 -1
- package/devvit/internals/blocks/BlocksReconciler.js +3 -10
- package/devvit/internals/blocks/BlocksTransformer.d.ts +6 -10
- package/devvit/internals/blocks/BlocksTransformer.d.ts.map +1 -1
- package/devvit/internals/blocks/BlocksTransformer.js +17 -41
- package/devvit/internals/blocks/handler/BlocksHandler.d.ts.map +1 -1
- package/devvit/internals/blocks/handler/BlocksHandler.js +3 -7
- package/devvit/internals/blocks/transformContext.d.ts +26 -3
- package/devvit/internals/blocks/transformContext.d.ts.map +1 -1
- package/devvit/internals/blocks/transformContext.js +67 -101
- package/devvit/internals/blocks/transformerUtils.d.ts +11 -0
- package/devvit/internals/blocks/transformerUtils.d.ts.map +1 -0
- package/devvit/internals/blocks/transformerUtils.js +75 -0
- package/devvit/internals/blocks/transformerUtils.test.d.ts.map +1 -0
- package/meta.json +30 -29
- package/meta.min.json +34 -28
- package/package.json +7 -7
- package/public-api.d.ts +20 -0
- package/public-api.iife.js +177 -179
- package/public-api.min.js +5 -5
- package/public-api.min.js.map +4 -4
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"BlocksReconciler.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/BlocksReconciler.ts"],"names":[],"mappings":"
|
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"}
|
@@ -11,7 +11,6 @@ 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';
|
15
14
|
import { Header } from '@devvit/shared-types/Header.js';
|
16
15
|
import { makeAPIClients } from '../../../apis/makeAPIClients.js';
|
17
16
|
import { getEffectsFromUIClient } from '../../../apis/ui/helpers/getEffectsFromUIClient.js';
|
@@ -155,9 +154,6 @@ export class BlocksReconciler {
|
|
155
154
|
}
|
156
155
|
return uniqueId;
|
157
156
|
}
|
158
|
-
makeTransformContext(ctx) {
|
159
|
-
return { maxDimensions: ctx.dimensions ?? DEFAULT_DIMENSIONS };
|
160
|
-
}
|
161
157
|
async reconcile() {
|
162
158
|
const ctx = __classPrivateFieldGet(this, _BlocksReconciler_instances, "m", _BlocksReconciler_makeContextProps).call(this);
|
163
159
|
const blockElement = {
|
@@ -167,8 +163,7 @@ export class BlocksReconciler {
|
|
167
163
|
};
|
168
164
|
const reified = await this.processBlock(blockElement);
|
169
165
|
assertNotString(reified);
|
170
|
-
|
171
|
-
this.transformer.createBlocksElementOrThrow(reified, transformContext);
|
166
|
+
this.transformer.createBlocksElementOrThrow(reified);
|
172
167
|
if (this.isUserActionRender && this.blockRenderEventId) {
|
173
168
|
const handler = this.actions.get(this.blockRenderEventId);
|
174
169
|
if (handler) {
|
@@ -189,8 +184,7 @@ export class BlocksReconciler {
|
|
189
184
|
children: [],
|
190
185
|
};
|
191
186
|
const block = await this.renderElement(ctx, rootBlockElement);
|
192
|
-
|
193
|
-
return this.transformer.ensureRootBlock(block, transformContext);
|
187
|
+
return this.transformer.ensureRootBlock(block);
|
194
188
|
}
|
195
189
|
async renderElement(ctx, element) {
|
196
190
|
const reified = await this.processBlock(element);
|
@@ -199,8 +193,7 @@ export class BlocksReconciler {
|
|
199
193
|
console.debug(indentXML(toXML(reified)));
|
200
194
|
if (Devvit.debug.emitState || ctx.debug.emitState)
|
201
195
|
console.debug(JSON.stringify(this.state, undefined, 2));
|
202
|
-
|
203
|
-
return this.transformer.createBlocksElementOrThrow(reified, transformContext);
|
196
|
+
return this.transformer.createBlocksElementOrThrow(reified);
|
204
197
|
}
|
205
198
|
async processProps(block) {
|
206
199
|
const props = block.props ?? {};
|
@@ -1,17 +1,14 @@
|
|
1
|
-
import type { Block, BlockAction, BlockAlignment, BlockBorder, BlockColor, BlockConfig
|
1
|
+
import type { Block, BlockAction, BlockAlignment, BlockBorder, BlockColor, BlockConfig } 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
|
-
|
7
|
-
/** The maximum size a block may take up per dimension (height/width), in pixels */
|
8
|
-
maxDimensions: Dimensions | UIDimensions;
|
9
|
-
};
|
6
|
+
import type { TransformContext } from './transformContext.js';
|
10
7
|
type DataSet = Record<string, unknown>;
|
11
8
|
export declare class BlocksTransformer {
|
12
9
|
#private;
|
13
10
|
constructor(getAssetsClient?: () => AssetsClient | undefined);
|
14
|
-
createBlocksElementOrThrow({ type, props, children }: ReifiedBlockElement
|
11
|
+
createBlocksElementOrThrow({ type, props, children }: ReifiedBlockElement): Block;
|
15
12
|
createBlocksElement({ type, props, children }: ReifiedBlockElement, transformContext: TransformContext): Block | undefined;
|
16
13
|
makeRootHeight(height: Devvit.Blocks.RootHeight): number;
|
17
14
|
makeBlockPadding(padding: Devvit.Blocks.ContainerPadding | undefined): BlockPadding | undefined;
|
@@ -37,7 +34,6 @@ export declare class BlocksTransformer {
|
|
37
34
|
makeBlockAnimationType(type: Devvit.Blocks.AnimationType | undefined): BlockAnimationType;
|
38
35
|
makeBlockAnimationDirection(type: Devvit.Blocks.AnimationDirection | undefined): BlockAnimationDirection | undefined;
|
39
36
|
makeBlockLoopMode(mode: Devvit.Blocks.AnimationLoop | undefined): BlockAnimationLoopMode | undefined;
|
40
|
-
makeBlockSizes(props: Devvit.Blocks.BaseProps | undefined, maxDimensions: Dimensions | UIDimensions): BlockSizes | undefined;
|
41
37
|
getDataSet(props: DataSet): DataSet;
|
42
38
|
makeActions(_type: BlockType, props: {
|
43
39
|
[key: string]: unknown;
|
@@ -48,8 +44,8 @@ export declare class BlocksTransformer {
|
|
48
44
|
parsePixels(input: Devvit.Blocks.SizePixels | number): number;
|
49
45
|
resolveAssetUrl(url: string, options?: GetURLOptions): string;
|
50
46
|
childrenToString(children: ReifiedBlockElementOrLiteral[]): string;
|
51
|
-
makeRoot(props: Devvit.Blocks.BaseProps | undefined,
|
52
|
-
wrapRoot(props: Devvit.Blocks.BaseProps | undefined,
|
47
|
+
makeRoot(props: Devvit.Blocks.BaseProps | undefined, ...children: ReifiedBlockElementOrLiteral[]): Block;
|
48
|
+
wrapRoot(props: Devvit.Blocks.BaseProps | undefined, children: Block[]): Block;
|
53
49
|
makeStackBlock(direction: BlockStackDirection, props: Devvit.Blocks.StackProps | undefined, transformContext: TransformContext, children: ReifiedBlockElementOrLiteral[]): Block;
|
54
50
|
makeHStack(props: Devvit.Blocks.StackProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
|
55
51
|
makeVStack(props: Devvit.Blocks.StackProps | undefined, transformContext: TransformContext, ...children: ReifiedBlockElementOrLiteral[]): Block;
|
@@ -64,7 +60,7 @@ export declare class BlocksTransformer {
|
|
64
60
|
makeAnimation(props: Devvit.Blocks.AnimationProps | undefined, transformContext: TransformContext): Block | undefined;
|
65
61
|
makeWebView(props: Devvit.Blocks.WebViewProps | undefined, transformContext: TransformContext): Block | undefined;
|
66
62
|
makeBlock(type: BlockType, props: Devvit.Blocks.BaseProps | undefined, transformContext: TransformContext, config?: BlockConfig | undefined): Block;
|
67
|
-
ensureRootBlock(b: Block
|
63
|
+
ensureRootBlock(b: Block): Block;
|
68
64
|
}
|
69
65
|
export {};
|
70
66
|
//# 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,
|
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,EACZ,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,E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AAE,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,GAAG,KAAK;CAkBjC"}
|
@@ -13,7 +13,8 @@ var _BlocksTransformer_assetsClient;
|
|
13
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 {
|
16
|
+
import { makeStackDimensionsDetails, ROOT_STACK_TRANSFORM_CONTEXT } from './transformContext.js';
|
17
|
+
import { makeBlockSizes } from './transformerUtils.js';
|
17
18
|
const DATA_PREFIX = 'data-';
|
18
19
|
const ACTION_HANDLERS = new Set(['onPress', 'onMessage']);
|
19
20
|
const ACTION_TYPES = new Map([
|
@@ -25,8 +26,8 @@ export class BlocksTransformer {
|
|
25
26
|
_BlocksTransformer_assetsClient.set(this, void 0);
|
26
27
|
__classPrivateFieldSet(this, _BlocksTransformer_assetsClient, getAssetsClient, "f");
|
27
28
|
}
|
28
|
-
createBlocksElementOrThrow({ type, props, children }
|
29
|
-
const block = this.createBlocksElement({ type, props, children },
|
29
|
+
createBlocksElementOrThrow({ type, props, children }) {
|
30
|
+
const block = this.createBlocksElement({ type, props, children }, ROOT_STACK_TRANSFORM_CONTEXT);
|
30
31
|
if (!block) {
|
31
32
|
throw new Error(`Could not create block of type ${type}`);
|
32
33
|
}
|
@@ -35,7 +36,7 @@ export class BlocksTransformer {
|
|
35
36
|
createBlocksElement({ type, props, children }, transformContext) {
|
36
37
|
switch (type) {
|
37
38
|
case 'blocks':
|
38
|
-
return this.makeRoot(props,
|
39
|
+
return this.makeRoot(props, ...children);
|
39
40
|
case 'hstack':
|
40
41
|
return this.makeHStack(props, transformContext, ...children);
|
41
42
|
case 'vstack':
|
@@ -395,32 +396,6 @@ export class BlocksTransformer {
|
|
395
396
|
}
|
396
397
|
return undefined;
|
397
398
|
}
|
398
|
-
makeBlockSizes(props, maxDimensions) {
|
399
|
-
if (props) {
|
400
|
-
const hasWidth = props.width != null || props.minWidth != null || props.maxWidth != null;
|
401
|
-
const hasHeight = props.height != null || props.minHeight != null || props.maxHeight != null;
|
402
|
-
if (hasWidth || hasHeight || props.grow != null) {
|
403
|
-
return {
|
404
|
-
width: hasWidth
|
405
|
-
? {
|
406
|
-
value: makeDimensionValue(props.width, maxDimensions.width),
|
407
|
-
min: makeDimensionValue(props.minWidth, maxDimensions.width),
|
408
|
-
max: makeDimensionValue(props.maxWidth, maxDimensions.width),
|
409
|
-
}
|
410
|
-
: undefined,
|
411
|
-
height: hasHeight
|
412
|
-
? {
|
413
|
-
value: makeDimensionValue(props.height, maxDimensions.height),
|
414
|
-
min: makeDimensionValue(props.minHeight, maxDimensions.height),
|
415
|
-
max: makeDimensionValue(props.maxHeight, maxDimensions.height),
|
416
|
-
}
|
417
|
-
: undefined,
|
418
|
-
grow: props.grow,
|
419
|
-
};
|
420
|
-
}
|
421
|
-
}
|
422
|
-
return undefined;
|
423
|
-
}
|
424
399
|
getDataSet(props) {
|
425
400
|
return Object.keys(props)
|
426
401
|
.filter((key) => key.startsWith(DATA_PREFIX))
|
@@ -510,11 +485,11 @@ export class BlocksTransformer {
|
|
510
485
|
childrenToString(children) {
|
511
486
|
return children.map((c) => c.toString()).join('');
|
512
487
|
}
|
513
|
-
makeRoot(props,
|
514
|
-
return this.wrapRoot(props,
|
488
|
+
makeRoot(props, ...children) {
|
489
|
+
return this.wrapRoot(props, this.childrenToBlocks(children, ROOT_STACK_TRANSFORM_CONTEXT));
|
515
490
|
}
|
516
|
-
wrapRoot(props,
|
517
|
-
return this.makeBlock(BlockType.BLOCK_ROOT, {},
|
491
|
+
wrapRoot(props, children) {
|
492
|
+
return this.makeBlock(BlockType.BLOCK_ROOT, {}, {}, {
|
518
493
|
rootConfig: {
|
519
494
|
children: children,
|
520
495
|
height: this.makeRootHeight(Devvit.customPostType?.height ??
|
@@ -525,16 +500,17 @@ export class BlocksTransformer {
|
|
525
500
|
}
|
526
501
|
makeStackBlock(direction, props, transformContext, children) {
|
527
502
|
const backgroundColors = this.getThemedColors(props?.backgroundColor, props?.lightBackgroundColor, props?.darkBackgroundColor);
|
528
|
-
const
|
503
|
+
const alignment = this.makeBlockAlignment(props?.alignment);
|
504
|
+
const blockSizes = makeBlockSizes(props, transformContext);
|
505
|
+
const blockDimensionsDetails = makeStackDimensionsDetails(props, transformContext.stackParentLayout, blockSizes);
|
529
506
|
return this.makeBlock(BlockType.BLOCK_STACK, props, transformContext, {
|
530
507
|
stackConfig: {
|
531
|
-
alignment
|
508
|
+
alignment,
|
532
509
|
backgroundColor: backgroundColors?.light,
|
533
510
|
backgroundColors,
|
534
511
|
border: this.makeBlockBorder(props?.border, props?.borderColor, props?.lightBorderColor, props?.darkBorderColor),
|
535
512
|
children: this.childrenToBlocks(children, {
|
536
|
-
...
|
537
|
-
maxDimensions: childrenMaxDimensions,
|
513
|
+
stackParentLayout: { ...blockDimensionsDetails, direction, alignment },
|
538
514
|
}),
|
539
515
|
cornerRadius: this.makeBlockRadius(props?.cornerRadius),
|
540
516
|
direction: direction,
|
@@ -668,14 +644,14 @@ export class BlocksTransformer {
|
|
668
644
|
makeBlock(type, props, transformContext, config) {
|
669
645
|
return {
|
670
646
|
type,
|
671
|
-
sizes:
|
647
|
+
sizes: makeBlockSizes(props, transformContext),
|
672
648
|
config: config,
|
673
649
|
actions: (props && this.makeActions(type, props)) ?? [],
|
674
650
|
id: props?.id,
|
675
651
|
key: props?.key,
|
676
652
|
};
|
677
653
|
}
|
678
|
-
ensureRootBlock(b
|
654
|
+
ensureRootBlock(b) {
|
679
655
|
const block = b;
|
680
656
|
if (block.type === BlockType.BLOCK_ROOT) {
|
681
657
|
if (block.config?.rootConfig && Devvit.customPostType?.height) {
|
@@ -683,7 +659,7 @@ export class BlocksTransformer {
|
|
683
659
|
}
|
684
660
|
return block;
|
685
661
|
}
|
686
|
-
const root = this.wrapRoot(undefined,
|
662
|
+
const root = this.wrapRoot(undefined, [block]);
|
687
663
|
if (!root) {
|
688
664
|
throw new Error('Could not create root block');
|
689
665
|
}
|
@@ -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;
|
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"}
|
@@ -9,8 +9,7 @@ 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,
|
13
|
-
import { DEFAULT_DIMENSIONS } from '@devvit/shared-types/dimensions.js';
|
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;
|
14
13
|
import isEqual from 'lodash.isequal';
|
15
14
|
import { BlocksTransformer } from '../BlocksTransformer.js';
|
16
15
|
import { ContextBuilder } from './ContextBuilder.js';
|
@@ -243,9 +242,8 @@ export class BlocksHandler {
|
|
243
242
|
console.error('[blocks] Effects were mutated during rendering', context._effects, effectsCopy);
|
244
243
|
}
|
245
244
|
if (tags) {
|
246
|
-
|
247
|
-
blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").
|
248
|
-
blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").ensureRootBlock(blocks, transformContext);
|
245
|
+
blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").createBlocksElementOrThrow(tags);
|
246
|
+
blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").ensureRootBlock(blocks);
|
249
247
|
}
|
250
248
|
}
|
251
249
|
return {
|
@@ -311,8 +309,6 @@ async function _BlocksHandler_handleAsyncQueues(context, ...batch) {
|
|
311
309
|
}
|
312
310
|
// TODO: Decide whether this is excessive. It doesn't hurt anything besides performance.
|
313
311
|
__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 };
|
316
312
|
}, _BlocksHandler_renderRoot = function _BlocksHandler_renderRoot(component, props, context) {
|
317
313
|
if (__classPrivateFieldGet(this, _BlocksHandler_instances, "a", _BlocksHandler_debug_get))
|
318
314
|
console.debug('[blocks] renderRoot');
|
@@ -1,6 +1,29 @@
|
|
1
|
-
import type {
|
1
|
+
import type { BlockAlignment, BlockSizes } from '@devvit/protos';
|
2
2
|
import { BlockStackDirection } from '@devvit/protos';
|
3
3
|
import type { Devvit } from '../../Devvit.js';
|
4
|
-
export declare const
|
5
|
-
export
|
4
|
+
export declare const ROOT_STACK_TRANSFORM_CONTEXT: TransformContext;
|
5
|
+
export interface TransformContext {
|
6
|
+
stackParentLayout?: StackParentLayout;
|
7
|
+
}
|
8
|
+
export interface StackParentLayout {
|
9
|
+
hasHeight: boolean;
|
10
|
+
hasWidth: boolean;
|
11
|
+
direction: BlockStackDirection;
|
12
|
+
alignment: BlockAlignment | undefined;
|
13
|
+
}
|
14
|
+
declare enum ExpandDirection {
|
15
|
+
NONE = 0,
|
16
|
+
HORIZONTAL = 1,
|
17
|
+
VERTICAL = 2
|
18
|
+
}
|
19
|
+
export interface BlockGrowStretchDirection {
|
20
|
+
growDirection: ExpandDirection;
|
21
|
+
stretchDirection: ExpandDirection;
|
22
|
+
}
|
23
|
+
export interface BlockDimensionsDetails {
|
24
|
+
hasHeight: boolean;
|
25
|
+
hasWidth: boolean;
|
26
|
+
}
|
27
|
+
export declare function makeStackDimensionsDetails(props: Devvit.Blocks.StackProps | undefined, stackParentLayout: StackParentLayout | undefined, blockSizes: BlockSizes | undefined): BlockDimensionsDetails;
|
28
|
+
export {};
|
6
29
|
//# sourceMappingURL=transformContext.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transformContext.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/transformContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"transformContext.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/transformContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,eAAO,MAAM,4BAA4B,EAAE,gBAO1C,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,mBAAmB,CAAC;IAC/B,SAAS,EAAE,cAAc,GAAG,SAAS,CAAC;CACvC;AAED,aAAK,eAAe;IAClB,IAAI,IAAA;IACJ,UAAU,IAAA;IACV,QAAQ,IAAA;CACT;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,eAAe,CAAC;IAC/B,gBAAgB,EAAE,eAAe,CAAC;CACnC;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAKD,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,EAC3C,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,EAChD,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,sBAAsB,CAiCxB"}
|
@@ -1,108 +1,74 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
import { BlockStackDirection } from '@devvit/protos';
|
2
|
+
export const ROOT_STACK_TRANSFORM_CONTEXT = {
|
3
|
+
stackParentLayout: {
|
4
|
+
hasHeight: true,
|
5
|
+
hasWidth: true,
|
6
|
+
direction: BlockStackDirection.UNRECOGNIZED,
|
7
|
+
alignment: undefined,
|
8
|
+
},
|
9
9
|
};
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
if (hasWidthDefined) {
|
30
|
-
childMaxWidth = getMaxForDimension(props.width, props.minWidth, props.maxWidth, parentMaxDimensions.width);
|
31
|
-
}
|
32
|
-
let widthOffset = paddingOffset + borderOffset;
|
33
|
-
if (stackDirection === BlockStackDirection.STACK_HORIZONTAL && gapSize && childrenCount > 0) {
|
34
|
-
widthOffset = widthOffset + gapSize * (childrenCount - 1);
|
35
|
-
}
|
10
|
+
var ExpandDirection;
|
11
|
+
(function (ExpandDirection) {
|
12
|
+
ExpandDirection[ExpandDirection["NONE"] = 0] = "NONE";
|
13
|
+
ExpandDirection[ExpandDirection["HORIZONTAL"] = 1] = "HORIZONTAL";
|
14
|
+
ExpandDirection[ExpandDirection["VERTICAL"] = 2] = "VERTICAL";
|
15
|
+
})(ExpandDirection || (ExpandDirection = {}));
|
16
|
+
/*
|
17
|
+
Determine if a block has height and/or width based on its sizing, and its parent grow/stretch direction.
|
18
|
+
*/
|
19
|
+
export function makeStackDimensionsDetails(props, stackParentLayout, blockSizes) {
|
20
|
+
if (!stackParentLayout)
|
21
|
+
return { hasHeight: false, hasWidth: false };
|
22
|
+
const { growDirection, stretchDirection } = makeBlockGrowStretchDetails(props?.grow, stackParentLayout.direction, stackParentLayout.alignment);
|
23
|
+
const hasHeight = blockSizes?.height?.value?.value ||
|
24
|
+
blockSizes?.height?.min?.value ||
|
25
|
+
isExpandingOnConstrainedRespectiveAxis(ExpandDirection.VERTICAL, growDirection, stretchDirection, stackParentLayout.hasHeight);
|
26
|
+
const hasWidth = blockSizes?.width?.value?.value ||
|
27
|
+
blockSizes?.width?.min?.value ||
|
28
|
+
isExpandingOnConstrainedRespectiveAxis(ExpandDirection.HORIZONTAL, growDirection, stretchDirection, stackParentLayout.hasWidth);
|
36
29
|
return {
|
37
|
-
|
38
|
-
|
39
|
-
width: childMaxWidth - widthOffset,
|
30
|
+
hasHeight: Boolean(hasHeight),
|
31
|
+
hasWidth: Boolean(hasWidth),
|
40
32
|
};
|
41
|
-
}
|
42
|
-
/*
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
}
|
34
|
+
/*
|
35
|
+
Determine if the parent is growing or stretching on the defined axis.
|
36
|
+
If true, tells us that the child may have height/width, even if its parent is not explicitly set.
|
37
|
+
*/
|
38
|
+
function isExpandingOnConstrainedRespectiveAxis(axis, growDirection, stretchDirection, parentHasDimensionSet) {
|
39
|
+
return ((growDirection === axis && parentHasDimensionSet) ||
|
40
|
+
(stretchDirection === axis && parentHasDimensionSet));
|
41
|
+
}
|
42
|
+
/*
|
43
|
+
Determine the grow/stretch direction of a block based on its parent stack direction and alignment.
|
44
|
+
*/
|
45
|
+
function makeBlockGrowStretchDetails(isGrowing, parentStackDirection, parentAlignment) {
|
46
|
+
const parentIsVerticalOrRoot = parentStackDirection === BlockStackDirection.STACK_VERTICAL ||
|
47
|
+
parentStackDirection === BlockStackDirection.UNRECOGNIZED;
|
48
|
+
const parentIsHoritzontal = parentStackDirection === BlockStackDirection.STACK_HORIZONTAL;
|
49
|
+
let growDirection = ExpandDirection.NONE;
|
50
|
+
if (parentIsHoritzontal && isGrowing) {
|
51
|
+
growDirection = ExpandDirection.HORIZONTAL;
|
48
52
|
}
|
49
|
-
else {
|
50
|
-
|
51
|
-
if (parts == null)
|
52
|
-
return undefined;
|
53
|
-
const dimensions = Number.parseFloat(parts[1]);
|
54
|
-
if (parts?.at(2) === '%') {
|
55
|
-
return (maxDimension * dimensions) / 100;
|
56
|
-
}
|
57
|
-
return dimensions;
|
53
|
+
else if (parentIsVerticalOrRoot && isGrowing) {
|
54
|
+
growDirection = ExpandDirection.VERTICAL;
|
58
55
|
}
|
59
|
-
|
60
|
-
const
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
case 'large':
|
70
|
-
return 32 * fontScale;
|
71
|
-
default:
|
72
|
-
return 0;
|
56
|
+
const hnone = parentAlignment === undefined || parentAlignment.horizontal === undefined;
|
57
|
+
const vnone = parentAlignment === undefined || parentAlignment.vertical === undefined;
|
58
|
+
const isStretching = parentIsHoritzontal
|
59
|
+
? Boolean(vnone)
|
60
|
+
: parentIsVerticalOrRoot
|
61
|
+
? Boolean(hnone)
|
62
|
+
: false;
|
63
|
+
let stretchDirection = ExpandDirection.NONE;
|
64
|
+
if (parentIsHoritzontal && isStretching) {
|
65
|
+
stretchDirection = ExpandDirection.VERTICAL;
|
73
66
|
}
|
74
|
-
|
75
|
-
|
76
|
-
switch (gap) {
|
77
|
-
case 'small':
|
78
|
-
return 8;
|
79
|
-
case 'medium':
|
80
|
-
return 16;
|
81
|
-
case 'large':
|
82
|
-
return 32;
|
67
|
+
else if (parentIsVerticalOrRoot && isStretching) {
|
68
|
+
stretchDirection = ExpandDirection.HORIZONTAL;
|
83
69
|
}
|
84
|
-
return
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
switch (borderWidth) {
|
90
|
-
case 'none':
|
91
|
-
return 0;
|
92
|
-
case 'thin':
|
93
|
-
return 1;
|
94
|
-
case 'thick':
|
95
|
-
return 2;
|
96
|
-
default:
|
97
|
-
// Default to a thin border when a color was set, but no borderWidth.
|
98
|
-
return 1;
|
99
|
-
}
|
100
|
-
};
|
101
|
-
const getMaxForDimension = (value, min, max, maxDimension) => {
|
102
|
-
const pxValue = stackDimensionToPx(value, maxDimension) || 0;
|
103
|
-
const pxMin = stackDimensionToPx(min, maxDimension) || 0;
|
104
|
-
const pxMax = stackDimensionToPx(max, maxDimension) || 0;
|
105
|
-
const upperBound = Math.min(pxMax, pxValue);
|
106
|
-
const lowerBound = Math.max(pxMin, pxValue);
|
107
|
-
return Math.max(upperBound, lowerBound);
|
108
|
-
};
|
70
|
+
return {
|
71
|
+
growDirection,
|
72
|
+
stretchDirection,
|
73
|
+
};
|
74
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { BlockSizes, BlockSizes_Dimension_Value } from '@devvit/protos';
|
2
|
+
import type { Devvit } from '../../Devvit.js';
|
3
|
+
import type { StackParentLayout, TransformContext } from './transformContext.js';
|
4
|
+
export declare function parseSize(size: Devvit.Blocks.SizeString | undefined): BlockSizes_Dimension_Value | undefined;
|
5
|
+
/**
|
6
|
+
* If a child has a relative size along its parent's main axis, but that parent's axis is not set, omit the dimension.
|
7
|
+
* This is done to enforce consistency between web and Yoga (the layout engine used by mobile).
|
8
|
+
* */
|
9
|
+
export declare function omitRelativeSizes(blockSizes: BlockSizes, stackParentLayout: StackParentLayout): BlockSizes;
|
10
|
+
export declare function makeBlockSizes(props: Devvit.Blocks.BaseProps | undefined, transformContext: TransformContext): BlockSizes | undefined;
|
11
|
+
//# sourceMappingURL=transformerUtils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transformerUtils.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/transformerUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,GACzC,0BAA0B,GAAG,SAAS,CAoBxC;AAED;;;KAGK;AACL,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,UAAU,EACtB,iBAAiB,EAAE,iBAAiB,GACnC,UAAU,CAwBZ;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,EAC1C,gBAAgB,EAAE,gBAAgB,GACjC,UAAU,GAAG,SAAS,CA+BxB"}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { BlockSizeUnit, BlockStackDirection } from '@devvit/protos';
|
2
|
+
export function parseSize(size) {
|
3
|
+
if (size == null)
|
4
|
+
return undefined;
|
5
|
+
if (typeof size === 'number') {
|
6
|
+
return { value: size, unit: BlockSizeUnit.SIZE_UNIT_PERCENT };
|
7
|
+
}
|
8
|
+
// Regex:
|
9
|
+
// Group 1: Digits with optional decimal trailer
|
10
|
+
// Group 2: Optional suffix: 'px' or '%' (defaults to %)
|
11
|
+
// eslint-disable-next-line security/detect-unsafe-regex
|
12
|
+
const parts = size.match(/^(\d+(?:\.\d+)?)(px|%)?$/);
|
13
|
+
if (parts == null) {
|
14
|
+
return undefined;
|
15
|
+
}
|
16
|
+
let unit = BlockSizeUnit.SIZE_UNIT_PERCENT;
|
17
|
+
if (parts.at(2) === 'px') {
|
18
|
+
unit = BlockSizeUnit.SIZE_UNIT_PIXELS;
|
19
|
+
}
|
20
|
+
const value = Number.parseFloat(parts[1]);
|
21
|
+
return { value, unit };
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* If a child has a relative size along its parent's main axis, but that parent's axis is not set, omit the dimension.
|
25
|
+
* This is done to enforce consistency between web and Yoga (the layout engine used by mobile).
|
26
|
+
* */
|
27
|
+
export function omitRelativeSizes(blockSizes, stackParentLayout) {
|
28
|
+
if (blockSizes.width?.value?.unit === BlockSizeUnit.SIZE_UNIT_PERCENT ||
|
29
|
+
blockSizes.width?.min?.unit === BlockSizeUnit.SIZE_UNIT_PERCENT) {
|
30
|
+
if (stackParentLayout.direction === BlockStackDirection.STACK_HORIZONTAL) {
|
31
|
+
if (!stackParentLayout.hasWidth) {
|
32
|
+
blockSizes.width = undefined;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
if (blockSizes.height?.value?.unit === BlockSizeUnit.SIZE_UNIT_PERCENT ||
|
37
|
+
blockSizes.height?.min?.unit === BlockSizeUnit.SIZE_UNIT_PERCENT) {
|
38
|
+
if (stackParentLayout.direction === BlockStackDirection.STACK_VERTICAL) {
|
39
|
+
if (!stackParentLayout.hasHeight) {
|
40
|
+
blockSizes.height = undefined;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return blockSizes;
|
45
|
+
}
|
46
|
+
export function makeBlockSizes(props, transformContext) {
|
47
|
+
if (props) {
|
48
|
+
const hasWidth = props.width != null || props.minWidth != null || props.maxWidth != null;
|
49
|
+
const hasHeight = props.height != null || props.minHeight != null || props.maxHeight != null;
|
50
|
+
if (hasWidth || hasHeight || props.grow != null) {
|
51
|
+
let blockSizes = {
|
52
|
+
width: hasWidth
|
53
|
+
? {
|
54
|
+
value: parseSize(props.width),
|
55
|
+
min: parseSize(props.minWidth),
|
56
|
+
max: parseSize(props.maxWidth),
|
57
|
+
}
|
58
|
+
: undefined,
|
59
|
+
height: hasHeight
|
60
|
+
? {
|
61
|
+
value: parseSize(props.height),
|
62
|
+
min: parseSize(props.minHeight),
|
63
|
+
max: parseSize(props.maxHeight),
|
64
|
+
}
|
65
|
+
: undefined,
|
66
|
+
grow: props.grow,
|
67
|
+
};
|
68
|
+
if (transformContext.stackParentLayout) {
|
69
|
+
blockSizes = omitRelativeSizes(blockSizes, transformContext.stackParentLayout);
|
70
|
+
}
|
71
|
+
return blockSizes;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return undefined;
|
75
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transformerUtils.test.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/blocks/transformerUtils.test.ts"],"names":[],"mappings":""}
|