@astl/editor 0.3.0 → 0.3.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.
- package/CHANGELOG.md +26 -0
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +10 -7
- package/dist/authoring.js.map +1 -1
- package/dist/elements/color-control.d.ts +4 -1
- package/dist/elements/color-control.d.ts.map +1 -1
- package/dist/elements/color-control.js +6 -2
- package/dist/elements/color-control.js.map +1 -1
- package/dist/elements/inspector.d.ts.map +1 -1
- package/dist/elements/inspector.js +11 -2
- package/dist/elements/inspector.js.map +1 -1
- package/dist/elements/issues.d.ts.map +1 -1
- package/dist/elements/issues.js +11 -3
- package/dist/elements/issues.js.map +1 -1
- package/dist/elements/picture-dialog.d.ts +1 -0
- package/dist/elements/picture-dialog.d.ts.map +1 -1
- package/dist/elements/picture-dialog.js +16 -3
- package/dist/elements/picture-dialog.js.map +1 -1
- package/dist/elements/preview.d.ts.map +1 -1
- package/dist/elements/preview.js +11 -2
- package/dist/elements/preview.js.map +1 -1
- package/dist/elements/style-popups.js +3 -3
- package/dist/elements/styles.d.ts +36 -1
- package/dist/elements/styles.d.ts.map +1 -1
- package/dist/elements/styles.js +97 -1
- package/dist/elements/styles.js.map +1 -1
- package/dist/elements/toolbar.d.ts.map +1 -1
- package/dist/elements/toolbar.js +40 -16
- package/dist/elements/toolbar.js.map +1 -1
- package/package.json +5 -5
- package/src/authoring.ts +9 -7
- package/src/elements/color-control.ts +6 -2
- package/src/elements/inspector.ts +19 -2
- package/src/elements/issues.ts +11 -3
- package/src/elements/picture-dialog.ts +17 -3
- package/src/elements/preview.ts +11 -2
- package/src/elements/style-popups.ts +3 -3
- package/src/elements/styles.ts +111 -1
- package/src/elements/toolbar.ts +42 -16
package/src/elements/toolbar.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { AuthoringElement } from './base.js';
|
|
|
26
26
|
import { type AstlInsertMenu, GLYPHS, type Glyph, type InsertGroup, TYPE_GLYPHS } from './insert-menu.js';
|
|
27
27
|
import { loadStyleElements, STYLE_OPEN, type StyleOpen } from './style-load.js';
|
|
28
28
|
import type { StylePopup } from './style-popups.js';
|
|
29
|
-
import { inheritTokens, kitStyles } from './styles.js';
|
|
29
|
+
import { fitViewport, inheritTokens, kitStyles, VIEWPORT_MARGIN } from './styles.js';
|
|
30
30
|
|
|
31
31
|
/** Kit items a host can feature besides component tags (`tag`) and starters (`tag:template`). */
|
|
32
32
|
export const FEATURED_ITEMS: readonly string[] = ['text', 'picture', 'page-break'];
|
|
@@ -293,6 +293,8 @@ const popupStyles: CSSResult = css`
|
|
|
293
293
|
block-size: 1rem;
|
|
294
294
|
}
|
|
295
295
|
[popover] {
|
|
296
|
+
--room-inline: calc(100vw - 2 * var(--astl-space-4));
|
|
297
|
+
--room-block: calc(100dvh - 2 * var(--astl-space-4));
|
|
296
298
|
box-sizing: border-box;
|
|
297
299
|
position: fixed;
|
|
298
300
|
inset: auto;
|
|
@@ -304,6 +306,8 @@ const popupStyles: CSSResult = css`
|
|
|
304
306
|
color: var(--astl-ink);
|
|
305
307
|
box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2);
|
|
306
308
|
overflow: auto;
|
|
309
|
+
max-inline-size: var(--room-inline);
|
|
310
|
+
max-block-size: var(--room-block);
|
|
307
311
|
}
|
|
308
312
|
[popover]:not(:popover-open) {
|
|
309
313
|
display: none;
|
|
@@ -312,8 +316,7 @@ const popupStyles: CSSResult = css`
|
|
|
312
316
|
display: flex;
|
|
313
317
|
flex-direction: column;
|
|
314
318
|
gap: 2px;
|
|
315
|
-
min-inline-size: 12rem;
|
|
316
|
-
max-block-size: calc(100dvh - 2 * var(--astl-space-4));
|
|
319
|
+
min-inline-size: min(12rem, var(--room-inline));
|
|
317
320
|
}
|
|
318
321
|
.menu button {
|
|
319
322
|
justify-content: flex-start;
|
|
@@ -326,8 +329,8 @@ const popupStyles: CSSResult = css`
|
|
|
326
329
|
font-weight: 600;
|
|
327
330
|
}
|
|
328
331
|
.insert {
|
|
329
|
-
inline-size: min(26rem,
|
|
330
|
-
max-block-size: min(32rem,
|
|
332
|
+
inline-size: min(26rem, var(--room-inline));
|
|
333
|
+
max-block-size: min(32rem, var(--room-block));
|
|
331
334
|
padding: 0;
|
|
332
335
|
}
|
|
333
336
|
.insert .search {
|
|
@@ -355,7 +358,7 @@ const popupStyles: CSSResult = css`
|
|
|
355
358
|
.link {
|
|
356
359
|
display: flex;
|
|
357
360
|
flex-direction: column;
|
|
358
|
-
inline-size: min(22rem,
|
|
361
|
+
inline-size: min(22rem, var(--room-inline));
|
|
359
362
|
}
|
|
360
363
|
.menu .menu-section {
|
|
361
364
|
display: contents;
|
|
@@ -536,6 +539,7 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
536
539
|
this.#follow();
|
|
537
540
|
document.addEventListener('pointerdown', this.#outside, true);
|
|
538
541
|
document.addEventListener('keydown', this.#escape);
|
|
542
|
+
window.addEventListener('resize', this.#replace);
|
|
539
543
|
}
|
|
540
544
|
|
|
541
545
|
override disconnectedCallback(): void {
|
|
@@ -543,6 +547,7 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
543
547
|
this.#follow();
|
|
544
548
|
document.removeEventListener('pointerdown', this.#outside, true);
|
|
545
549
|
document.removeEventListener('keydown', this.#escape);
|
|
550
|
+
window.removeEventListener('resize', this.#replace);
|
|
546
551
|
}
|
|
547
552
|
|
|
548
553
|
protected override willUpdate(changed: PropertyValues<this>): void {
|
|
@@ -629,18 +634,34 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
629
634
|
this.requestUpdate();
|
|
630
635
|
}
|
|
631
636
|
|
|
632
|
-
/**
|
|
637
|
+
/**
|
|
638
|
+
* Puts a popup below its button, its start edge on the button's, and keeps it inside the viewport: no wider or taller
|
|
639
|
+
* than the viewport less a margin (`fitViewport`: it scrolls inside), moved along to fit, and above the button where
|
|
640
|
+
* it fits only there (else as low as it fits). Rectangles are in the viewport's pixels, the popup's insets in its own,
|
|
641
|
+
* zoomed ones (a page that enlarges its text with `zoom`).
|
|
642
|
+
*/
|
|
633
643
|
#place(popup: HTMLElement, opener: HTMLElement): void {
|
|
644
|
+
const zoom = fitViewport(popup);
|
|
645
|
+
const margin = VIEWPORT_MARGIN;
|
|
646
|
+
const { clientWidth: width, clientHeight: height } = document.documentElement;
|
|
647
|
+
// Measured at the start, where a popup that sizes to its content has the whole width to take.
|
|
648
|
+
popup.style.setProperty('inset-inline-start', `${margin / zoom}px`);
|
|
649
|
+
popup.style.setProperty('inset-block-start', `${margin / zoom}px`);
|
|
650
|
+
const box = popup.getBoundingClientRect();
|
|
634
651
|
const rect = opener.getBoundingClientRect();
|
|
635
652
|
const rtl = getComputedStyle(opener).direction === 'rtl';
|
|
636
|
-
const
|
|
637
|
-
const
|
|
638
|
-
const
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
653
|
+
const start = rtl ? width - rect.right : rect.left;
|
|
654
|
+
const inline = Math.max(margin, Math.min(start, width - box.width - margin));
|
|
655
|
+
const below = rect.bottom + 4;
|
|
656
|
+
const above = rect.top - 4 - box.height;
|
|
657
|
+
const block =
|
|
658
|
+
below + box.height <= height - margin
|
|
659
|
+
? below
|
|
660
|
+
: above >= margin
|
|
661
|
+
? above
|
|
662
|
+
: Math.max(margin, height - margin - box.height);
|
|
663
|
+
popup.style.setProperty('inset-inline-start', `${inline / zoom}px`);
|
|
664
|
+
popup.style.setProperty('inset-block-start', `${block / zoom}px`);
|
|
644
665
|
}
|
|
645
666
|
|
|
646
667
|
/** After a command: the editor gets the focus back when a key pressed the button (a pointer never took it). */
|
|
@@ -1420,11 +1441,16 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
1420
1441
|
choice.style.fontFamily = choice.dataset.font ?? '';
|
|
1421
1442
|
}
|
|
1422
1443
|
// Popups stay where their buttons are while the page scrolls or the bar wraps.
|
|
1444
|
+
this.#replace();
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
/** Places the open popup again: its button moved, or the viewport changed (a turned phone). */
|
|
1448
|
+
#replace = (): void => {
|
|
1423
1449
|
if (this.#popup === null) return;
|
|
1424
1450
|
const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(this.#popup)}`);
|
|
1425
1451
|
const opener = this.renderRoot.querySelector<HTMLElement>(`[data-popup="${openerOf(this.#popup)}"]`);
|
|
1426
1452
|
if (element !== null && opener !== null && element.matches(':popover-open')) this.#place(element, opener);
|
|
1427
|
-
}
|
|
1453
|
+
};
|
|
1428
1454
|
}
|
|
1429
1455
|
|
|
1430
1456
|
declare global {
|