@poadio/app-core 0.1.0 → 0.2.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/CHANGELOG.md +26 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +5 -1
- package/dist/app.js.map +1 -1
- package/dist/catalog.d.ts +90 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +433 -0
- package/dist/catalog.js.map +1 -0
- package/dist/designer.d.ts +3 -0
- package/dist/designer.d.ts.map +1 -0
- package/dist/designer.js +5 -0
- package/dist/designer.js.map +1 -0
- package/dist/draft-toolbar.d.ts +59 -0
- package/dist/draft-toolbar.d.ts.map +1 -0
- package/dist/draft-toolbar.js +74 -0
- package/dist/draft-toolbar.js.map +1 -0
- package/dist/grid.d.ts +83 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +181 -0
- package/dist/grid.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +4 -1
- package/dist/model.js.map +1 -1
- package/dist/preview.d.ts +13 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +10 -2
- package/dist/preview.js.map +1 -1
- package/package.json +6 -1
- package/schema/front.v1.json +19 -1
- package/src/app.ts +5 -1
- package/src/catalog.ts +499 -0
- package/src/designer.ts +4 -0
- package/src/draft-toolbar.ts +104 -0
- package/src/grid.ts +183 -0
- package/src/index.ts +15 -1
- package/src/model.ts +5 -2
- package/src/preview.ts +15 -3
package/src/grid.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Éléments posés sur la grille d'une page (section `grid`) : format, validation et gestes du designer, en fonctions
|
|
2
|
+
// pures. La console les emploie pour poser, déplacer, redimensionner et retirer ; le moteur pour valider et
|
|
3
|
+
// afficher. Aucune fonction ne modifie son entrée : chacune rend une nouvelle liste.
|
|
4
|
+
//
|
|
5
|
+
// { id, type, x, y, w, h, props } x : colonne (0 à 23), y : ligne (0…), w : largeur en colonnes, h : hauteur en
|
|
6
|
+
// lignes de `rowHeight` px ; props : les propriétés du type (catalog.ts)
|
|
7
|
+
import { catalogEntry, checkPropValue, defaultProps, type CatalogLang, type GridSize, type PropValue } from './catalog.js';
|
|
8
|
+
|
|
9
|
+
export const GRID_COLS = 24;
|
|
10
|
+
/** Éléments par grille, au plus (le schéma le dit aussi) */
|
|
11
|
+
export const MAX_ITEMS = 200;
|
|
12
|
+
/** Lignes d'une grille, au plus : y + h ≤ MAX_ROWS */
|
|
13
|
+
export const MAX_ROWS = 500;
|
|
14
|
+
export const ITEM_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
|
|
15
|
+
|
|
16
|
+
export type GridItem = { id: string; type: string; x: number; y: number; w: number; h: number; props: Record<string, unknown> };
|
|
17
|
+
export type Rect = { x: number; y: number; w: number; h: number };
|
|
18
|
+
export type Cell = { x: number; y: number };
|
|
19
|
+
export type GridIssue = { path: string; message: string };
|
|
20
|
+
|
|
21
|
+
export const overlaps = (a: Rect, b: Rect): boolean => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
22
|
+
|
|
23
|
+
export const inBounds = (r: Rect): boolean =>
|
|
24
|
+
Number.isInteger(r.x) && Number.isInteger(r.y) && Number.isInteger(r.w) && Number.isInteger(r.h) &&
|
|
25
|
+
r.x >= 0 && r.y >= 0 && r.w >= 1 && r.h >= 1 && r.x + r.w <= GRID_COLS && r.y + r.h <= MAX_ROWS;
|
|
26
|
+
|
|
27
|
+
/** La place est-elle libre (dans la grille, sans chevaucher un autre élément que `ignore`) ? */
|
|
28
|
+
export const fits = (items: readonly GridItem[], r: Rect, ignore?: string): boolean => inBounds(r) && !items.some((i) => i.id !== ignore && overlaps(i, r));
|
|
29
|
+
|
|
30
|
+
/** Nombre de lignes occupées (le bas du dernier élément) */
|
|
31
|
+
export const gridRows = (items: readonly GridItem[]): number => items.reduce((m, i) => Math.max(m, i.y + i.h), 0);
|
|
32
|
+
|
|
33
|
+
const minSize = (type: string): GridSize => catalogEntry(type)?.min ?? { w: 1, h: 1 };
|
|
34
|
+
|
|
35
|
+
/** Taille ramenée dans la grille et au-dessus du minimum du type */
|
|
36
|
+
export const clampSize = (type: string, w: number, h: number): GridSize => {
|
|
37
|
+
const min = minSize(type);
|
|
38
|
+
return {
|
|
39
|
+
w: Math.min(GRID_COLS, Math.max(min.w, Math.round(w) || min.w)),
|
|
40
|
+
h: Math.min(MAX_ROWS, Math.max(min.h, Math.round(h) || min.h)),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Position ramenée dans la grille pour une taille donnée */
|
|
45
|
+
export const clampCell = (cell: Cell, size: GridSize): Cell => ({
|
|
46
|
+
x: Math.min(GRID_COLS - size.w, Math.max(0, Math.round(cell.x) || 0)),
|
|
47
|
+
y: Math.min(MAX_ROWS - size.h, Math.max(0, Math.round(cell.y) || 0)),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* La place libre la plus proche de `near` pour un élément de taille `size` (null : la grille est pleine).
|
|
52
|
+
* Sans `near` : la première place libre, ligne par ligne, de gauche à droite. Distance : euclidienne en cellules,
|
|
53
|
+
* à égalité la plus haute puis la plus à gauche.
|
|
54
|
+
*/
|
|
55
|
+
export const findFreeSpot = (items: readonly GridItem[], size: GridSize, near?: Cell, ignore?: string): Cell | null => {
|
|
56
|
+
if (size.w > GRID_COLS || size.h > MAX_ROWS) return null;
|
|
57
|
+
const others = ignore ? items.filter((i) => i.id !== ignore) : items;
|
|
58
|
+
const lastRow = Math.min(MAX_ROWS - size.h, gridRows(others));
|
|
59
|
+
if (!near) {
|
|
60
|
+
for (let y = 0; y <= lastRow; y++) for (let x = 0; x + size.w <= GRID_COLS; x++) if (fits(others, { x, y, ...size })) return { x, y };
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const target = clampCell(near, size);
|
|
64
|
+
if (fits(others, { ...target, ...size })) return target;
|
|
65
|
+
let best: Cell | null = null;
|
|
66
|
+
let bestD = Infinity;
|
|
67
|
+
// Au-delà du dernier élément tout est libre : chercher jusqu'à la ligne de la cible, ou juste sous le dernier
|
|
68
|
+
const maxY = Math.min(MAX_ROWS - size.h, Math.max(lastRow, target.y));
|
|
69
|
+
for (let y = 0; y <= maxY; y++) {
|
|
70
|
+
const dy = y - target.y;
|
|
71
|
+
if (dy * dy > bestD) {
|
|
72
|
+
if (y > target.y) break;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
for (let x = 0; x + size.w <= GRID_COLS; x++) {
|
|
76
|
+
const dx = x - target.x;
|
|
77
|
+
const d = dx * dx + dy * dy;
|
|
78
|
+
if (d < bestD && fits(others, { x, y, ...size })) {
|
|
79
|
+
best = { x, y };
|
|
80
|
+
bestD = d;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return best;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Un identifiant libre pour un nouvel élément : <type>-<n>, le plus petit n libre */
|
|
88
|
+
export const newItemId = (items: readonly GridItem[], type: string): string => {
|
|
89
|
+
const base = /^[a-z][a-z0-9-]{0,33}$/.test(type) ? type : 'item';
|
|
90
|
+
const used = new Set(items.map((i) => i.id));
|
|
91
|
+
for (let n = 1; ; n++) if (!used.has(`${base}-${n}`)) return `${base}-${n}`;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type AddResult = { items: GridItem[]; item: GridItem } | { items: GridItem[]; item: null; reason: 'unknown_type' | 'full' };
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Pose un composant du catalogue : à sa taille par défaut, à la place libre la plus proche de `at` (glisser-déposer)
|
|
98
|
+
* ou à la première place libre (clic), avec ses props par défaut dans la langue de la console.
|
|
99
|
+
*/
|
|
100
|
+
export const addItem = (items: readonly GridItem[], type: string, options: { at?: Cell; lang?: CatalogLang; id?: string } = {}): AddResult => {
|
|
101
|
+
const entry = catalogEntry(type);
|
|
102
|
+
if (!entry) return { items: [...items], item: null, reason: 'unknown_type' };
|
|
103
|
+
if (items.length >= MAX_ITEMS) return { items: [...items], item: null, reason: 'full' };
|
|
104
|
+
const size = clampSize(type, entry.size.w, entry.size.h);
|
|
105
|
+
const spot = findFreeSpot(items, size, options.at);
|
|
106
|
+
if (!spot) return { items: [...items], item: null, reason: 'full' };
|
|
107
|
+
const id = options.id && ITEM_ID_RE.test(options.id) && !items.some((i) => i.id === options.id) ? options.id : newItemId(items, type);
|
|
108
|
+
const item: GridItem = { id, type, ...spot, ...size, props: defaultProps(type, options.lang ?? 'fr') };
|
|
109
|
+
return { items: [...items, item], item };
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Déplace un élément vers `to` ; occupé : la place libre la plus proche. Introuvable ou sans place : inchangé. */
|
|
113
|
+
export const moveItem = (items: readonly GridItem[], id: string, to: Cell): GridItem[] => {
|
|
114
|
+
const item = items.find((i) => i.id === id);
|
|
115
|
+
if (!item) return [...items];
|
|
116
|
+
const spot = findFreeSpot(items, { w: item.w, h: item.h }, to, id);
|
|
117
|
+
if (!spot || (spot.x === item.x && spot.y === item.y)) return [...items];
|
|
118
|
+
return items.map((i) => (i.id === id ? { ...i, ...spot } : i));
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Redimensionne un élément (son coin haut-gauche reste en place) : taille bornée par le minimum du type et la
|
|
123
|
+
* grille ; si la nouvelle taille chevauche un voisin, la plus grande taille libre entre l'ancienne et la demandée.
|
|
124
|
+
*/
|
|
125
|
+
export const resizeItem = (items: readonly GridItem[], id: string, size: GridSize): GridItem[] => {
|
|
126
|
+
const item = items.find((i) => i.id === id);
|
|
127
|
+
if (!item) return [...items];
|
|
128
|
+
const want = clampSize(item.type, size.w, size.h);
|
|
129
|
+
want.w = Math.min(want.w, GRID_COLS - item.x);
|
|
130
|
+
want.h = Math.min(want.h, MAX_ROWS - item.y);
|
|
131
|
+
const free = (w: number, h: number) => fits(items, { x: item.x, y: item.y, w, h }, id);
|
|
132
|
+
let w = want.w;
|
|
133
|
+
let h = want.h;
|
|
134
|
+
// Reculer vers l'ancienne taille, largeur puis hauteur, jusqu'à une place libre
|
|
135
|
+
while (!free(w, h) && (w !== item.w || h !== item.h)) {
|
|
136
|
+
if (w !== item.w) w += w > item.w ? -1 : 1;
|
|
137
|
+
else h += h > item.h ? -1 : 1;
|
|
138
|
+
}
|
|
139
|
+
if (w === item.w && h === item.h) return [...items];
|
|
140
|
+
return items.map((i) => (i.id === id ? { ...i, w, h } : i));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const removeItem = (items: readonly GridItem[], id: string): GridItem[] => items.filter((i) => i.id !== id);
|
|
144
|
+
|
|
145
|
+
/** Change des props d'un élément (les autres gardent leur valeur) */
|
|
146
|
+
export const updateItemProps = (items: readonly GridItem[], id: string, patch: Record<string, PropValue>): GridItem[] =>
|
|
147
|
+
items.map((i) => (i.id === id ? { ...i, props: { ...i.props, ...patch } } : i));
|
|
148
|
+
|
|
149
|
+
/** Ordre de lecture (rangées puis colonnes) : l'ordre des calques, et l'empilement sur un petit écran */
|
|
150
|
+
export const readingOrder = (items: readonly GridItem[]): GridItem[] => [...items].sort((a, b) => a.y - b.y || a.x - b.x || a.id.localeCompare(b.id));
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Ce qu'un schéma JSON ne dit pas des éléments d'une grille : type connu du catalogue, place dans les 24 colonnes,
|
|
154
|
+
* taille minimale du type, identifiants uniques, aucun chevauchement, props connues et du bon type.
|
|
155
|
+
*/
|
|
156
|
+
export const validateGridItems = (items: readonly GridItem[], base = ''): GridIssue[] => {
|
|
157
|
+
const out: GridIssue[] = [];
|
|
158
|
+
const ids = new Set<string>();
|
|
159
|
+
items.forEach((it, i) => {
|
|
160
|
+
const at = `${base}/items[${i}]`;
|
|
161
|
+
if (ids.has(it.id)) out.push({ path: `${at}/id`, message: `duplicate item id "${it.id}"` });
|
|
162
|
+
ids.add(it.id);
|
|
163
|
+
const entry = catalogEntry(it.type);
|
|
164
|
+
if (!entry) {
|
|
165
|
+
out.push({ path: `${at}/type`, message: `unknown component type "${it.type}"` });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (!inBounds(it)) out.push({ path: at, message: `out of the ${GRID_COLS}-column grid (x + w ≤ ${GRID_COLS}, y + h ≤ ${MAX_ROWS})` });
|
|
169
|
+
if (it.w < entry.min.w || it.h < entry.min.h) out.push({ path: at, message: `smaller than the minimum size of "${it.type}" (${entry.min.w}×${entry.min.h})` });
|
|
170
|
+
for (const [k, v] of Object.entries(it.props ?? {})) {
|
|
171
|
+
const spec = entry.props.find((p) => p.key === k);
|
|
172
|
+
if (!spec) out.push({ path: `${at}/props/${k}`, message: `unknown property of "${it.type}"` });
|
|
173
|
+
else {
|
|
174
|
+
const m = checkPropValue(spec, v);
|
|
175
|
+
if (m) out.push({ path: `${at}/props/${k}`, message: m });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
for (let i = 0; i < items.length; i++)
|
|
180
|
+
for (let j = i + 1; j < items.length; j++)
|
|
181
|
+
if (overlaps(items[i]!, items[j]!)) out.push({ path: `${base}/items[${j}]`, message: `overlaps item "${items[i]!.id}"` });
|
|
182
|
+
return out;
|
|
183
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -12,10 +12,24 @@ export type { AuthPort, AuthResult, FrontUser, PoadAuthLike } from './auth.js';
|
|
|
12
12
|
export { createFrontLogger, sanitizeLine, maskText, MAX_BATCH, MAX_PER_MINUTE } from './logs.js';
|
|
13
13
|
export type { FrontLogger, BrowserLogLine, LogLevel, LogSender } from './logs.js';
|
|
14
14
|
export { PROTOCOL, previewModeOf, createPreviewBridge } from './preview.js';
|
|
15
|
-
export type { PreviewMode, PreviewOptions, ViewAs, Theme, ToConsole, ToFront, PreviewWindow, PreviewHandlers } from './preview.js';
|
|
15
|
+
export type { PreviewMode, PreviewOptions, ViewAs, Theme, ToConsole, ToFront, PreviewWindow, PreviewHandlers, GridLayout } from './preview.js';
|
|
16
16
|
export { runActions, fail, ActionFailure } from './actions.js';
|
|
17
17
|
export type { Action, AppContext, Handler, HandlerRegistry, RunResult } from './actions.js';
|
|
18
18
|
export { createFrontApp, isFrontConfig } from './app.js';
|
|
19
19
|
export type { FrontApp, FrontAppOptions, FrontConfig, AppState, Mode, Status } from './app.js';
|
|
20
20
|
export { toFiles, fromFiles } from './files.js';
|
|
21
21
|
export type { FrontFiles } from './files.js';
|
|
22
|
+
export {
|
|
23
|
+
CATEGORIES, CATALOG, CATALOG_TYPES, catalogEntry, catalogLang, localize, defaultValue, defaultProps, resolveProps, checkPropValue, searchCatalog,
|
|
24
|
+
MAX_TEXT, MAX_LONGTEXT, MAX_LINES, MAX_LINE,
|
|
25
|
+
} from './catalog.js';
|
|
26
|
+
export type { CatalogEntry, CatalogLang, Category, CategoryId, GridSize, Localized, PropKind, PropOption, PropSpec, PropValue } from './catalog.js';
|
|
27
|
+
export {
|
|
28
|
+
GRID_COLS, MAX_ITEMS, MAX_ROWS, ITEM_ID_RE, overlaps, inBounds, fits, gridRows, clampSize, clampCell, findFreeSpot, newItemId, addItem, moveItem,
|
|
29
|
+
resizeItem, removeItem, updateItemProps, readingOrder, validateGridItems,
|
|
30
|
+
} from './grid.js';
|
|
31
|
+
export type { GridItem, Rect, Cell, GridIssue, AddResult } from './grid.js';
|
|
32
|
+
export {
|
|
33
|
+
DRAFT_DEVICE_WIDTHS, DRAFT_DEVICES, DRAFT_TOOLBAR_DEFAULT, draftToolbarKey, readDraftToolbar, writeDraftToolbar, draftToolbarReduce, draftFrameWidth, draftFoldIcon, draftToolbarLog,
|
|
34
|
+
} from './draft-toolbar.js';
|
|
35
|
+
export type { DraftDevice, DraftToolbarState, DraftToolbarAction } from './draft-toolbar.js';
|
package/src/model.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// viennent de la configuration servie par l'engine (front.json), jamais de la définition.
|
|
5
5
|
import schema from '../schema/front.v1.json' with { type: 'json' };
|
|
6
6
|
import { checkSchema, type SchemaIssue } from './json-schema.js';
|
|
7
|
+
import { validateGridItems, type GridItem } from './grid.js';
|
|
7
8
|
|
|
8
9
|
export const FORMAT = 'poad.front/1' as const;
|
|
9
10
|
export const FRONT_SCHEMA: unknown = schema;
|
|
@@ -16,7 +17,8 @@ export type UnderConstructionSection = {
|
|
|
16
17
|
type: 'under-construction';
|
|
17
18
|
props: { project?: string; front?: string; message?: string };
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
/** Grille de 24 colonnes : les composants posés (grid.ts) */
|
|
21
|
+
export type GridSection = { id: string; type: 'grid'; cols: 24; rowHeight: number; items: GridItem[] };
|
|
20
22
|
export type Section = UnderConstructionSection | GridSection;
|
|
21
23
|
|
|
22
24
|
export type Page = { id: string; title: string; path: string; auth: PageAuth; sections: Section[] };
|
|
@@ -101,7 +103,7 @@ export type Validation = { ok: true; front: FrontDefinition } | { ok: false; iss
|
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
105
|
* Valide une définition : le schéma JSON (front.v1.json), puis ce qu'un schéma ne dit pas (identifiants et
|
|
104
|
-
* adresses de pages uniques, page d'accueil existante).
|
|
106
|
+
* adresses de pages uniques, page d'accueil existante, éléments des grilles : grid.ts).
|
|
105
107
|
*/
|
|
106
108
|
export const validateFront = (value: unknown): Validation => {
|
|
107
109
|
const issues = checkSchema(schema, value);
|
|
@@ -119,6 +121,7 @@ export const validateFront = (value: unknown): Validation => {
|
|
|
119
121
|
p.sections.forEach((s, j) => {
|
|
120
122
|
if (sections.has(s.id)) out.push({ path: `/pages[${i}]/sections[${j}]/id`, message: `duplicate section id "${s.id}"` });
|
|
121
123
|
sections.add(s.id);
|
|
124
|
+
if (s.type === 'grid') out.push(...validateGridItems(s.items, `/pages[${i}]/sections[${j}]`));
|
|
122
125
|
});
|
|
123
126
|
});
|
|
124
127
|
if (!ids.has(front.home)) out.push({ path: '/home', message: `unknown page "${front.home}"` });
|
package/src/preview.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
//
|
|
3
3
|
// iframe : <adresse du front><chemin de la page>?poad_preview=canvas|play
|
|
4
4
|
// moteur → console { type: 'poad:front:ready', protocol: 1 }
|
|
5
|
-
// { type: 'poad:front:rendered', page, width, height }
|
|
5
|
+
// { type: 'poad:front:rendered', page, width, height, grids? }
|
|
6
|
+
// grids : la place de chaque grille dans la page (px de l'iframe) — la console y dessine la
|
|
7
|
+
// sélection, les poignées et le dépôt des composants ; stacked : écran étroit, empilés
|
|
6
8
|
// { type: 'poad:front:navigate', page }
|
|
7
9
|
// console → moteur { type: 'poad:front:load', protocol: 1, definition, page, mode, theme, viewAs?, single? }
|
|
8
10
|
// viewAs : 'member' (défaut : le contenu de la page, quelle que soit sa règle d'accès — en
|
|
@@ -24,9 +26,12 @@ export type Theme = 'light' | 'dark';
|
|
|
24
26
|
export type ViewAs = 'member' | 'visitor';
|
|
25
27
|
export type PreviewOptions = { viewAs?: ViewAs; single?: boolean };
|
|
26
28
|
|
|
29
|
+
/** Place d'une grille dans la page rendue (pixels de l'iframe, avant la mise à l'échelle de la console) */
|
|
30
|
+
export type GridLayout = { section: string; x: number; y: number; width: number; height: number; rowHeight: number; rows: number; stacked: boolean };
|
|
31
|
+
|
|
27
32
|
export type ToConsole =
|
|
28
33
|
| { type: 'poad:front:ready'; protocol: typeof PROTOCOL }
|
|
29
|
-
| { type: 'poad:front:rendered'; page: string; width: number; height: number }
|
|
34
|
+
| { type: 'poad:front:rendered'; page: string; width: number; height: number; grids?: GridLayout[] }
|
|
30
35
|
| { type: 'poad:front:navigate'; page: string }
|
|
31
36
|
| { type: 'poad:front:invalid'; issues: { path: string; message: string }[] };
|
|
32
37
|
|
|
@@ -91,7 +96,14 @@ export const createPreviewBridge = (win: PreviewWindow, origins: readonly string
|
|
|
91
96
|
win.addEventListener('message', onMessage);
|
|
92
97
|
return {
|
|
93
98
|
ready: () => send({ type: 'poad:front:ready', protocol: PROTOCOL }),
|
|
94
|
-
rendered: (page: string, width: number, height: number
|
|
99
|
+
rendered: (page: string, width: number, height: number, grids?: GridLayout[]) =>
|
|
100
|
+
send({
|
|
101
|
+
type: 'poad:front:rendered',
|
|
102
|
+
page,
|
|
103
|
+
width: Math.round(width),
|
|
104
|
+
height: Math.round(height),
|
|
105
|
+
...(grids ? { grids: grids.map((g) => ({ ...g, x: Math.round(g.x), y: Math.round(g.y), width: Math.round(g.width), height: Math.round(g.height) })) } : {}),
|
|
106
|
+
}),
|
|
95
107
|
navigate: (page: string) => send({ type: 'poad:front:navigate', page }),
|
|
96
108
|
dispose: () => win.removeEventListener('message', onMessage),
|
|
97
109
|
};
|