@cntrl-site/components 1.0.115-alpha.0 → 1.0.115-alpha.2

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.
@@ -1,11 +1,13 @@
1
1
  import { CommonComponentProps } from '../props';
2
- import { PopupMenuAlign, PopupMenuBlockType, PopupMenuGridSettings, PopupMenuSidesSetting, PopupMenuLayout } from './popupMenuLayout';
2
+ import { EmbedMediaLike } from '../utils/embedMedia';
3
+ import { PopupMenuAlign, PopupMenuBlockType, PopupMenuGridSettings, PopupMenuSidesSetting, PopupMenuSavedLayout } from './popupMenuLayout';
3
4
  /** How the popup comes in as it opens and goes as it closes; the overlay behind it fades with it, but for 'none'. */
4
5
  export declare const POPUP_MENU_TRANSITIONS: readonly ["slide down", "slide up", "fade", "scale", "none"];
5
6
  export type PopupMenuTransition = (typeof POPUP_MENU_TRANSITIONS)[number];
6
7
  export declare const POPUP_MENU_TRIGGER_TYPES: readonly ["burger", "plus", "icon", "text"];
7
8
  export type PopupMenuTriggerType = (typeof POPUP_MENU_TRIGGER_TYPES)[number];
8
- type PopupMenuImage = {
9
+ /** An image, an uploaded video, or a Vimeo or YouTube one, as a media item holds it. */
10
+ type PopupMenuImage = EmbedMediaLike & {
9
11
  assetId: string;
10
12
  name?: string;
11
13
  };
@@ -18,7 +20,8 @@ export type PopupMenuBlock = {
18
20
  };
19
21
  type PopupMenuColorKey = 'barBackgroundColor' | 'triggerColor' | 'overlayColor' | 'popupBackgroundColor' | 'titleColor' | 'textColor' | 'listAColor' | 'listBColor';
20
22
  type PopupMenuSettings = PopupMenuGridSettings & {
21
- menuLayout?: PopupMenuLayout | null;
23
+ /** Saved as it was drawn; one saved before blocks were placed freely has its placements in whole columns. */
24
+ menuLayout?: PopupMenuSavedLayout | null;
22
25
  /** None, as in a menu saved before there was a choice, is a text trigger. */
23
26
  triggerType?: PopupMenuTriggerType;
24
27
  triggerLabel?: string;
@@ -66,5 +69,5 @@ type PopupMenuProps = {
66
69
  portalId?: string;
67
70
  onOpenChange?: (isOpen: boolean) => void;
68
71
  } & CommonComponentProps;
69
- export declare function PopupMenu({ settings, content, isEditor, isEditMode, isPreviewMode, layoutId, portalId, currentState, unavailableStates, onOpenChange, onUpdateSettings, }: PopupMenuProps): import("react/jsx-runtime").JSX.Element;
72
+ export declare function PopupMenu({ settings, content, isEditor, isEditMode, isPreviewMode, portalId, currentState, unavailableStates, onOpenChange, onUpdateSettings, }: PopupMenuProps): import("react/jsx-runtime").JSX.Element;
70
73
  export {};
@@ -28,6 +28,7 @@ export declare const PopupMenuComponent: {
28
28
  type: "array";
29
29
  settings: {
30
30
  addItemWithoutImage: true;
31
+ allowsVideo: true;
31
32
  };
32
33
  display: {
33
34
  type: string;
@@ -132,10 +133,6 @@ export declare const PopupMenuComponent: {
132
133
  menuLayout: {
133
134
  type: "object";
134
135
  scope: "layout";
135
- title: string;
136
- display: {
137
- type: string;
138
- };
139
136
  };
140
137
  gridLayout: {
141
138
  type: "grid-layout";
@@ -10,13 +10,22 @@ export type PopupMenuGrid = {
10
10
  beat?: number;
11
11
  };
12
12
  /**
13
- * A block's place in the popup: `column` skipped from the left edge, `span` columns wide, and `top` down from
14
- * the popup's top, in fractions of the layout width like the popup's other sizes. A block is always drawn at
15
- * its top; one reaching below the popup's bottom is scrolled to, the popup scrolling down as far as it reaches.
16
- * `height`, set once an image block was resized by its top or bottom edge, holds it to that many beats of the
17
- * rhythm, the image cut to fill it. Without it, the block is as tall as its content, as text and lists always are.
13
+ * A block's place in the popup: `left` from the grid's left edge, `width` across, and `top` down from the popup's
14
+ * top, in fractions of the layout width like the popup's other sizes. Blocks sit anywhere on the grid, as an
15
+ * article's items do: its columns, the popup's edges and the other blocks are only what they snap to as they are
16
+ * moved or resized. A block is always drawn at its top; one reaching below the popup's bottom is scrolled to, the
17
+ * popup scrolling down as far as it reaches. `height`, set once an image block was resized by its top or bottom
18
+ * edge, holds it to that height, the image cut to fill it. Without it, the block is as tall as its content, as
19
+ * text and lists always are.
18
20
  */
19
21
  export type PopupMenuPlacement = {
22
+ left: number;
23
+ width: number;
24
+ top: number;
25
+ height?: number;
26
+ };
27
+ /** A placement as saved before blocks were placed freely: `column` skipped from the left edge, `span` columns wide. */
28
+ export type PopupMenuColumnPlacement = {
20
29
  column: number;
21
30
  span: number;
22
31
  top: number;
@@ -103,6 +112,26 @@ export type PopupMenuLayout = {
103
112
  /** Set once a block was moved by hand, after which the seed no longer gives this layout. */
104
113
  edited?: boolean;
105
114
  };
115
+ /** A layout as it may be saved: one from before blocks were placed freely has its placements in whole columns. */
116
+ export type PopupMenuSavedLayout = Omit<PopupMenuLayout, 'placements'> & {
117
+ placements: readonly (PopupMenuPlacement | PopupMenuColumnPlacement)[];
118
+ };
119
+ /** A column's width on the grid: as set, or, with none set, the columns spread alike over the whole layout width. */
120
+ export declare function getPopupMenuColumnWidth(grid: PopupMenuGrid): number;
121
+ /** How wide the grid blocks are placed on is: its columns and the gutters between them. */
122
+ export declare function getPopupMenuGridWidth(grid: PopupMenuGrid): number;
123
+ /** Both edges of every column, from the grid's left edge, left to right. */
124
+ export declare function getPopupMenuColumnEdges(grid: PopupMenuGrid): number[];
125
+ /** The place of `span` columns from `column` on, at `top`. */
126
+ export declare function getPopupMenuColumnsPlacement(grid: PopupMenuGrid, column: number, span: number, top: number, height?: number): PopupMenuPlacement;
127
+ /** The least a block may be resized across to: about 8px of a desktop layout. */
128
+ export declare function getPopupMenuMinWidth(): number;
129
+ /** Where a block without a placement yet sits: at the top left, a quarter of the columns wide. */
130
+ export declare function getDefaultPopupMenuPlacement(grid: PopupMenuGrid): PopupMenuPlacement;
131
+ /** A saved placement as a free one; one in whole columns is placed where those columns are on `grid`, the grid it was saved on. */
132
+ export declare function toPopupMenuPlacement(placement: PopupMenuPlacement | PopupMenuColumnPlacement, grid: PopupMenuGrid): PopupMenuPlacement;
133
+ /** A saved layout with every placement a free one; one that has them all so already comes back as it is. */
134
+ export declare function normalizePopupMenuLayout(layout: PopupMenuSavedLayout): PopupMenuLayout;
106
135
  /** How wide each block type may be, as fractions of the grid's columns, and how often a row is left with empty cells. */
107
136
  export type PopupMenuLayoutRules = {
108
137
  span: Record<PopupMenuBlockType, {
@@ -122,7 +151,6 @@ export declare const defaultPopupMenuLayoutRules: PopupMenuLayoutRules;
122
151
  * out to be. The same seed on the same grid always gives the same layout.
123
152
  */
124
153
  export declare function generatePopupMenuLayout(blocks: readonly PopupMenuBlockType[], grid: PopupMenuGrid, seed: number, height: number, rules?: PopupMenuLayoutRules): PopupMenuLayout;
125
- export declare function randomPopupMenuSeed(): number;
126
154
  /**
127
155
  * The top nearest to `top` on the grid's rhythm, within `room`, the most a top may be for the block to end
128
156
  * inside the popup: past it, the last beat the block still ends above.
@@ -139,8 +167,8 @@ export declare function snapPopupMenuHeight(grid: PopupMenuGrid, height: number,
139
167
  export declare function isSamePopupMenuGrid(a: PopupMenuGrid, b: PopupMenuGrid): boolean;
140
168
  /**
141
169
  * The layout on another grid, the layout grid as it is now rather than as it was when the layout was saved.
142
- * On as many columns, every block keeps its own; on more or fewer, each keeps its share of the width, at least a
143
- * column. Tops and set heights snap to the new rhythm. A layout already on `grid` comes back as it is.
170
+ * Every block keeps its share of the grid's width, so that blocks on its columns stay on them as the columns
171
+ * widen or narrow, and stays within it; tops and set heights are kept. A layout already on `grid` comes back as it is.
144
172
  */
145
173
  export declare function fitPopupMenuLayoutToGrid(layout: PopupMenuLayout, grid: PopupMenuGrid): PopupMenuLayout;
146
174
  /**
@@ -152,16 +180,15 @@ export type PopupMenuMeasure = {
152
180
  heights: readonly number[];
153
181
  };
154
182
  /**
155
- * The layout with one block moved to another column and top, keeping its span, its top snapped to the
156
- * grid's rhythm and, given the popup measured, held where the block still ends inside it. Null when the
157
- * column is off the grid, or, measured, when the block would cover part of another or come within a
158
- * vertical gap of one above or below it.
183
+ * The layout with one block moved to another left and top, keeping its size, held within the grid's width and,
184
+ * given the popup measured, where the block still ends inside it. Null when, measured, the block would cover part
185
+ * of another or come within a vertical gap of one above or below it.
159
186
  */
160
- export declare function movePopupMenuBlock(layout: PopupMenuLayout, index: number, column: number, top: number, measure?: PopupMenuMeasure): PopupMenuLayout | null;
187
+ export declare function movePopupMenuBlock(layout: PopupMenuLayout, index: number, left: number, top: number, measure?: PopupMenuMeasure): PopupMenuLayout | null;
161
188
  /**
162
- * The layout with one block resized to `next`, its columns and its top and height on the grid: the span at least
163
- * one column, the height (when set) in whole beats, at least one, and both within the popup. Null on the same
164
- * terms as movePopupMenuBlock. A block without a height keeps the one it was measured at.
189
+ * The layout with one block resized to `next`: at least the least width and height, and within the grid's width
190
+ * and, measured, the popup's height. Null on the same terms as movePopupMenuBlock. A block without a height keeps
191
+ * the one it was measured at.
165
192
  */
166
193
  export declare function resizePopupMenuBlock(layout: PopupMenuLayout, index: number, next: PopupMenuPlacement, measure?: PopupMenuMeasure): PopupMenuLayout | null;
167
194
  /**
@@ -169,8 +196,8 @@ export declare function resizePopupMenuBlock(layout: PopupMenuLayout, index: num
169
196
  * below it onto the next beat. A generated layout spreads its rows without knowing how tall the blocks turn
170
197
  * out, so a tall image or list can reach into the next row. Blocks are taken from the top down, each below
171
198
  * every one already settled, so a pushed block pushes the ones under it in turn. A block pushed so low that it
172
- * would reach below the popup's bottom, `measure.height`, moves instead to the columns nearest it where it is
173
- * pushed least and still ends inside the popup, and stays where it was pushed, the popup scrolling to it, only
199
+ * would reach below the popup's bottom, `measure.height`, moves instead to the column start nearest it where it
200
+ * is pushed least and still ends inside the popup, and stays where it was pushed, the popup scrolling to it, only
174
201
  * where none does. A layout that crowds nowhere comes back as it is.
175
202
  */
176
203
  export declare function settlePopupMenuLayout(layout: PopupMenuLayout, measure: PopupMenuMeasure): PopupMenuLayout;
@@ -0,0 +1,61 @@
1
+ import { PopupMenuGrid, PopupMenuLayout, PopupMenuMeasure, PopupMenuPlacement } from './popupMenuLayout';
2
+ /**
3
+ * Snapping for the popup's blocks as they are moved and resized on the canvas, as an article's items snap: a block
4
+ * goes where the pointer takes it, and an edge or its centre comes to a line only once it is within a few pixels of
5
+ * one. All in fractions of the layout width, `xs` from the grid's left edge and `ys` from the popup's top.
6
+ * `baselines` are what a text block's first line's baseline snaps to, as an article's text snaps by its baselines:
7
+ * the grid's rows and the other text blocks' first baselines.
8
+ */
9
+ export type PopupMenuSnapLines = {
10
+ xs: number[];
11
+ ys: number[];
12
+ baselines?: number[];
13
+ };
14
+ /** How near, in screen pixels, a block's edge or centre comes to a line before it snaps to it, as in an article. */
15
+ export declare const POPUP_MENU_SNAP_MARGIN_PX = 5;
16
+ /** The handles a block is resized by on the canvas, by the edges each one takes along. */
17
+ export type PopupMenuResizeHandle = 'top' | 'right' | 'bottom' | 'left' | 'top-left' | 'top-right' | 'bottom-right' | 'bottom-left';
18
+ /**
19
+ * The grid's rows, as the editor draws them: a line every beat from the popup's top where the grid has a rhythm,
20
+ * else one every vertical gap, down to its bottom.
21
+ */
22
+ export declare function getPopupMenuGridRows(grid: PopupMenuGrid, room: number): number[];
23
+ /**
24
+ * The lines block `index` snaps to: both edges of every column, the grid's edges and centre, the popup's top and
25
+ * bottom, every beat where the grid has a rhythm, and the other blocks' edges and centres, and a vertical gap above
26
+ * and below each, where a block may sit right under or over it. A text block's first baseline snaps to the grid's
27
+ * rows and to the other text blocks' first baselines, `baselines` being each block's, down from its top, where it
28
+ * has one.
29
+ */
30
+ export declare function getPopupMenuSnapLines(layout: PopupMenuLayout, index: number, measure: PopupMenuMeasure, baselines?: readonly (number | null | undefined)[]): PopupMenuSnapLines;
31
+ /** The lines any of `points` is on, to draw while the block is there; a baseline on any of `lines.baselines`. */
32
+ export declare function getPopupMenuSnapGuides(points: PopupMenuSnapLines, lines: PopupMenuSnapLines): PopupMenuSnapLines;
33
+ export type PopupMenuSnapMargin = {
34
+ x: number;
35
+ y: number;
36
+ };
37
+ export type PopupMenuSnapped = {
38
+ placement: PopupMenuPlacement;
39
+ guides: PopupMenuSnapLines;
40
+ };
41
+ /**
42
+ * A block moved from `start`, `height` tall, by `dx` and `dy`: its left edge, centre or right edge snapped to the
43
+ * nearest line across, and its top, middle or bottom to the nearest line down, or, for a text block, its first
44
+ * line's `baseline`, that far down from its top, to the nearest of `lines.baselines`, whichever is nearer, each within
45
+ * `margin`; then held within the grid's width and the popup's height, `room`.
46
+ */
47
+ export declare function snapPopupMenuMove(start: PopupMenuPlacement, height: number, dx: number, dy: number, lines: PopupMenuSnapLines, margin: PopupMenuSnapMargin, gridWidth: number, room: number, baseline?: number | null): PopupMenuSnapped;
48
+ export type PopupMenuResizeOptions = {
49
+ /** Shift: a corner keeps the block's shape as it was when the drag started. */
50
+ keepRatio?: boolean;
51
+ /** Alt: the opposite edge moves alike the other way, the block resized about its centre. */
52
+ fromCenter?: boolean;
53
+ };
54
+ /**
55
+ * A block resized from `start`, `height` tall, by one of its handles moved by `dx` and `dy`, as an article's items
56
+ * are: the edge it is dragged by snaps to the nearest line within `margin`, the other staying where it was, or,
57
+ * from its centre, moving alike the other way. Held at the least width and height at least, and within the grid's
58
+ * width and the popup's height, `room`. A block that is not resized down keeps its height unset, as tall as its
59
+ * content.
60
+ */
61
+ export declare function snapPopupMenuResize(start: PopupMenuPlacement, height: number, handle: PopupMenuResizeHandle, dx: number, dy: number, lines: PopupMenuSnapLines, margin: PopupMenuSnapMargin, gridWidth: number, room: number, minHeight: number, { keepRatio, fromCenter }?: PopupMenuResizeOptions): PopupMenuSnapped;