@r2digisolutions/components 0.24.4 → 0.24.6
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/dist/components/molecules/CanvasInspector/CanvasInspector.svelte +25 -5
- package/dist/components/molecules/LocaleSwitcher/LocaleSwitcher.svelte +1 -1
- package/dist/components/molecules/MediaStage/MediaStage.svelte +129 -45
- package/dist/components/molecules/PropertyField/PropertyField.svelte +14 -22
- package/dist/components/molecules/Stepper/Stepper.svelte +2 -0
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +307 -71
- package/dist/components/organisms/CanvasEditor/CanvasPageStrip.svelte +135 -0
- package/dist/components/organisms/CanvasEditor/CanvasPageStrip.svelte.d.ts +13 -0
- package/dist/components/organisms/CanvasEditor/CanvasQuickDock.svelte +132 -0
- package/dist/components/organisms/CanvasEditor/CanvasQuickDock.svelte.d.ts +10 -0
- package/dist/components/organisms/CommandPalette/CommandPalette.svelte +4 -4
- package/dist/components/organisms/DataListPage/DataListPage.svelte.d.ts +1 -1
- package/dist/components/organisms/ResourceStudio/ResourceStudio.svelte.d.ts +1 -1
- package/dist/components/organisms/SearchResults/SearchResults.svelte.d.ts +1 -1
- package/dist/components/templates/ListingTemplate/ListingTemplate.svelte.d.ts +1 -1
- package/dist/components/templates/ResourceStudioTemplate/ResourceStudioTemplate.svelte.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/utils/canvasDocument.d.ts +25 -0
- package/dist/utils/canvasDocument.js +104 -7
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import MediaAssetBrowser from '../../molecules/MediaAssetBrowser/MediaAssetBrowser.svelte';
|
|
4
4
|
import MediaLayerList from '../../molecules/MediaLayerList/MediaLayerList.svelte';
|
|
5
5
|
import MediaStage from '../../molecules/MediaStage/MediaStage.svelte';
|
|
6
|
+
import CanvasPageStrip from './CanvasPageStrip.svelte';
|
|
7
|
+
import CanvasQuickDock from './CanvasQuickDock.svelte';
|
|
6
8
|
import CanvasInspector from '../../molecules/CanvasInspector/CanvasInspector.svelte';
|
|
7
9
|
import CanvasElementsPanel, {
|
|
8
10
|
type CanvasElementDef
|
|
@@ -25,18 +27,26 @@
|
|
|
25
27
|
INSTAGRAM_GRID_PRESET_ID,
|
|
26
28
|
alignLayerRect,
|
|
27
29
|
applyTextAutoSize,
|
|
30
|
+
blankCanvasPage,
|
|
31
|
+
cloneCanvasLayers,
|
|
28
32
|
createCanvasGuide,
|
|
29
33
|
createCanvasLayer,
|
|
30
34
|
createPathFromDocPoints,
|
|
31
35
|
defaultSlotFromRect,
|
|
36
|
+
documentWithPages,
|
|
32
37
|
emptyCanvasDocument,
|
|
38
|
+
INSTAGRAM_GRID,
|
|
33
39
|
instagramGridGuides,
|
|
34
40
|
migrateCanvasDocument,
|
|
41
|
+
pagesOf,
|
|
35
42
|
presetIdForSize,
|
|
43
|
+
projectPage,
|
|
44
|
+
writePage,
|
|
36
45
|
type CanvasAlign,
|
|
37
46
|
type CanvasDocument,
|
|
38
47
|
type CanvasLayer,
|
|
39
|
-
type CanvasLayerKind
|
|
48
|
+
type CanvasLayerKind,
|
|
49
|
+
type CanvasPage
|
|
40
50
|
} from '../../../utils/canvasDocument.js';
|
|
41
51
|
import {
|
|
42
52
|
deleteSubtree,
|
|
@@ -173,11 +183,14 @@
|
|
|
173
183
|
onexport
|
|
174
184
|
}: CanvasEditorProps = $props();
|
|
175
185
|
|
|
176
|
-
// Ensure v2 document shape
|
|
186
|
+
// Ensure v2 document shape and a page list (older files are one sheet).
|
|
177
187
|
$effect.pre(() => {
|
|
178
188
|
if (value.version !== 2 || !value.widgets) {
|
|
179
189
|
value = migrateCanvasDocument(value);
|
|
180
190
|
}
|
|
191
|
+
if (!value.pages?.length) {
|
|
192
|
+
value = documentWithPages(value);
|
|
193
|
+
}
|
|
181
194
|
});
|
|
182
195
|
|
|
183
196
|
let selectedIds = $state<string[]>([]);
|
|
@@ -195,7 +208,12 @@
|
|
|
195
208
|
let editingWidgetId = $state<string | null>(null);
|
|
196
209
|
let history = $state<CanvasHistoryState>(createCanvasHistory(value));
|
|
197
210
|
let applyingHistory = false;
|
|
211
|
+
let activePageId = $state('');
|
|
212
|
+
type PageSnap = { width: number; height: number; page: CanvasPage };
|
|
213
|
+
type PageHist = { past: string[]; future: string[]; last: string };
|
|
214
|
+
let pageHistory = $state<Record<string, PageHist>>({});
|
|
198
215
|
let syncInstanceSizes = $state(true);
|
|
216
|
+
const toolOn = 'bg-neutral-200 text-neutral-950 dark:bg-neutral-700 dark:text-neutral-50';
|
|
199
217
|
|
|
200
218
|
const gridSizeOptions = [
|
|
201
219
|
{ value: '4', label: '4px' },
|
|
@@ -210,8 +228,22 @@
|
|
|
210
228
|
editingWidgetId ? ((value.widgets ?? []).find((w) => w.id === editingWidgetId) ?? null) : null
|
|
211
229
|
);
|
|
212
230
|
|
|
231
|
+
const designPages = $derived(pagesOf(value));
|
|
232
|
+
const resolvedPageId = $derived(
|
|
233
|
+
designPages.some((page) => page.id === activePageId)
|
|
234
|
+
? activePageId
|
|
235
|
+
: (designPages[0]?.id ?? '')
|
|
236
|
+
);
|
|
237
|
+
const activePageHist = $derived(pageHistory[resolvedPageId]);
|
|
238
|
+
const canUndo = $derived(
|
|
239
|
+
editingWidgetId ? history.past.length > 0 : (activePageHist?.past.length ?? 0) > 0
|
|
240
|
+
);
|
|
241
|
+
const canRedo = $derived(
|
|
242
|
+
editingWidgetId ? history.future.length > 0 : (activePageHist?.future.length ?? 0) > 0
|
|
243
|
+
);
|
|
244
|
+
|
|
213
245
|
const stageDoc = $derived.by((): CanvasDocument => {
|
|
214
|
-
if (!editingWidget) return value;
|
|
246
|
+
if (!editingWidget) return projectPage(value, resolvedPageId);
|
|
215
247
|
return {
|
|
216
248
|
...value,
|
|
217
249
|
width: editingWidget.width,
|
|
@@ -247,8 +279,8 @@
|
|
|
247
279
|
id: 'edit',
|
|
248
280
|
label: 'Edición',
|
|
249
281
|
items: [
|
|
250
|
-
{ id: 'undo', label: 'Deshacer', shortcut: '⌘Z', disabled:
|
|
251
|
-
{ id: 'redo', label: 'Rehacer', shortcut: '⇧⌘Z', disabled:
|
|
282
|
+
{ id: 'undo', label: 'Deshacer', shortcut: '⌘Z', disabled: !canUndo },
|
|
283
|
+
{ id: 'redo', label: 'Rehacer', shortcut: '⇧⌘Z', disabled: !canRedo },
|
|
252
284
|
{
|
|
253
285
|
id: 'delete',
|
|
254
286
|
label: 'Borrar selección',
|
|
@@ -471,37 +503,193 @@
|
|
|
471
503
|
];
|
|
472
504
|
});
|
|
473
505
|
|
|
506
|
+
function pageSnap(doc: CanvasDocument, pageId: string): string {
|
|
507
|
+
const page = pagesOf(doc).find((item) => item.id === pageId) ?? pagesOf(doc)[0];
|
|
508
|
+
const snap: PageSnap = { width: doc.width, height: doc.height, page };
|
|
509
|
+
return JSON.stringify(snap);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function seedPageHistory(doc: CanvasDocument, pageId: string) {
|
|
513
|
+
if (!pageId || pageHistory[pageId]) return;
|
|
514
|
+
pageHistory = {
|
|
515
|
+
...pageHistory,
|
|
516
|
+
[pageId]: { past: [], future: [], last: pageSnap(doc, pageId) }
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function applyPageSnap(doc: CanvasDocument, raw: string): CanvasDocument {
|
|
521
|
+
const snap = JSON.parse(raw) as PageSnap;
|
|
522
|
+
return {
|
|
523
|
+
...writePage(doc, snap.page.id, snap.page),
|
|
524
|
+
width: snap.width,
|
|
525
|
+
height: snap.height
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
474
529
|
function emit(next: CanvasDocument) {
|
|
475
530
|
const migrated = migrateCanvasDocument(next);
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
531
|
+
if (editingWidgetId) {
|
|
532
|
+
if (!applyingHistory) {
|
|
533
|
+
history = pushCanvasHistory(history, migrated);
|
|
534
|
+
} else {
|
|
535
|
+
history = { ...history, last: JSON.stringify(migrated) };
|
|
536
|
+
}
|
|
537
|
+
value = migrated;
|
|
538
|
+
onchange?.(value);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
const pageId = resolvedPageId;
|
|
542
|
+
seedPageHistory(value, pageId);
|
|
543
|
+
const stored = {
|
|
544
|
+
...writePage(migrated, pageId, {
|
|
545
|
+
background: migrated.background,
|
|
546
|
+
layers: migrated.layers,
|
|
547
|
+
guides: migrated.guides,
|
|
548
|
+
guidesLocked: migrated.guidesLocked
|
|
549
|
+
}),
|
|
550
|
+
width: migrated.width,
|
|
551
|
+
height: migrated.height,
|
|
552
|
+
widgets: migrated.widgets ?? []
|
|
553
|
+
};
|
|
554
|
+
const snap = pageSnap(stored, pageId);
|
|
555
|
+
const hist = pageHistory[pageId] ?? { past: [], future: [], last: snap };
|
|
556
|
+
if (!applyingHistory && snap !== hist.last) {
|
|
557
|
+
pageHistory = {
|
|
558
|
+
...pageHistory,
|
|
559
|
+
[pageId]: {
|
|
560
|
+
past: [...hist.past, hist.last].slice(-80),
|
|
561
|
+
future: [],
|
|
562
|
+
last: snap
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
} else if (applyingHistory) {
|
|
566
|
+
pageHistory = {
|
|
567
|
+
...pageHistory,
|
|
568
|
+
[pageId]: { ...hist, last: snap }
|
|
569
|
+
};
|
|
480
570
|
}
|
|
481
|
-
value =
|
|
571
|
+
value = stored;
|
|
482
572
|
onchange?.(value);
|
|
483
573
|
}
|
|
484
574
|
|
|
485
575
|
function undo() {
|
|
486
|
-
|
|
487
|
-
|
|
576
|
+
if (editingWidgetId) {
|
|
577
|
+
const result = undoCanvasHistory(history);
|
|
578
|
+
if (!result) return;
|
|
579
|
+
applyingHistory = true;
|
|
580
|
+
history = result.state;
|
|
581
|
+
value = migrateCanvasDocument(result.doc);
|
|
582
|
+
applyingHistory = false;
|
|
583
|
+
onchange?.(value);
|
|
584
|
+
selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const pageId = resolvedPageId;
|
|
588
|
+
const hist = pageHistory[pageId];
|
|
589
|
+
if (!hist?.past.length) return;
|
|
590
|
+
const prev = hist.past[hist.past.length - 1];
|
|
488
591
|
applyingHistory = true;
|
|
489
|
-
|
|
490
|
-
|
|
592
|
+
pageHistory = {
|
|
593
|
+
...pageHistory,
|
|
594
|
+
[pageId]: {
|
|
595
|
+
past: hist.past.slice(0, -1),
|
|
596
|
+
future: [hist.last, ...hist.future].slice(0, 80),
|
|
597
|
+
last: prev
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
value = applyPageSnap(value, prev);
|
|
491
601
|
applyingHistory = false;
|
|
492
602
|
onchange?.(value);
|
|
493
|
-
selectedIds = selectedIds.filter((id) =>
|
|
603
|
+
selectedIds = selectedIds.filter((id) => value.layers.some((l) => l.id === id));
|
|
494
604
|
}
|
|
495
605
|
|
|
496
606
|
function redo() {
|
|
497
|
-
|
|
498
|
-
|
|
607
|
+
if (editingWidgetId) {
|
|
608
|
+
const result = redoCanvasHistory(history);
|
|
609
|
+
if (!result) return;
|
|
610
|
+
applyingHistory = true;
|
|
611
|
+
history = result.state;
|
|
612
|
+
value = migrateCanvasDocument(result.doc);
|
|
613
|
+
applyingHistory = false;
|
|
614
|
+
onchange?.(value);
|
|
615
|
+
selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const pageId = resolvedPageId;
|
|
619
|
+
const hist = pageHistory[pageId];
|
|
620
|
+
if (!hist?.future.length) return;
|
|
621
|
+
const next = hist.future[0];
|
|
499
622
|
applyingHistory = true;
|
|
500
|
-
|
|
501
|
-
|
|
623
|
+
pageHistory = {
|
|
624
|
+
...pageHistory,
|
|
625
|
+
[pageId]: {
|
|
626
|
+
past: [...hist.past, hist.last].slice(-80),
|
|
627
|
+
future: hist.future.slice(1),
|
|
628
|
+
last: next
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
value = applyPageSnap(value, next);
|
|
502
632
|
applyingHistory = false;
|
|
503
633
|
onchange?.(value);
|
|
504
|
-
selectedIds = selectedIds.filter((id) =>
|
|
634
|
+
selectedIds = selectedIds.filter((id) => value.layers.some((l) => l.id === id));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function showPage(pageId: string, pages = pagesOf(value)) {
|
|
638
|
+
activePageId = pageId;
|
|
639
|
+
const next = projectPage({ ...value, pages }, pageId);
|
|
640
|
+
seedPageHistory(next, pageId);
|
|
641
|
+
value = next;
|
|
642
|
+
selectedIds = [];
|
|
643
|
+
editingTextId = null;
|
|
644
|
+
onchange?.(value);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function addPage() {
|
|
648
|
+
const instagram =
|
|
649
|
+
value.width === INSTAGRAM_GRID.width && value.height === INSTAGRAM_GRID.height;
|
|
650
|
+
const page = blankCanvasPage({
|
|
651
|
+
name: `Hoja ${designPages.length + 1}`,
|
|
652
|
+
background: '#ffffff',
|
|
653
|
+
guides: instagram ? instagramGridGuides() : []
|
|
654
|
+
});
|
|
655
|
+
showPage(page.id, [...designPages, page]);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function duplicatePage(pageId: string) {
|
|
659
|
+
const source = designPages.find((page) => page.id === pageId);
|
|
660
|
+
if (!source) return;
|
|
661
|
+
const copy = blankCanvasPage({
|
|
662
|
+
name: `${source.name?.trim() || 'Hoja'} copia`,
|
|
663
|
+
background: source.background,
|
|
664
|
+
layers: cloneCanvasLayers(source.layers),
|
|
665
|
+
guides: (source.guides ?? []).map((guide) =>
|
|
666
|
+
createCanvasGuide(guide.orientation, guide.position, { locked: guide.locked })
|
|
667
|
+
),
|
|
668
|
+
guidesLocked: source.guidesLocked
|
|
669
|
+
});
|
|
670
|
+
const index = designPages.findIndex((page) => page.id === pageId);
|
|
671
|
+
const pages = [...designPages];
|
|
672
|
+
pages.splice(index + 1, 0, copy);
|
|
673
|
+
showPage(copy.id, pages);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function deletePage(pageId: string) {
|
|
677
|
+
if (designPages.length < 2) return;
|
|
678
|
+
const index = designPages.findIndex((page) => page.id === pageId);
|
|
679
|
+
const pages = designPages.filter((page) => page.id !== pageId);
|
|
680
|
+
const neighbor = pages[Math.min(index, pages.length - 1)];
|
|
681
|
+
showPage(neighbor.id, pages);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function movePage(pageId: string, direction: -1 | 1) {
|
|
685
|
+
const pages = [...designPages];
|
|
686
|
+
const index = pages.findIndex((page) => page.id === pageId);
|
|
687
|
+
const target = index + direction;
|
|
688
|
+
if (index < 0 || target < 0 || target >= pages.length) return;
|
|
689
|
+
const [item] = pages.splice(index, 1);
|
|
690
|
+
pages.splice(target, 0, item);
|
|
691
|
+
value = projectPage({ ...value, pages }, resolvedPageId);
|
|
692
|
+
onchange?.(value);
|
|
505
693
|
}
|
|
506
694
|
|
|
507
695
|
function emitStageLayers(layers: CanvasLayer[], extra?: Partial<CanvasDocument>) {
|
|
@@ -748,7 +936,7 @@
|
|
|
748
936
|
width: preset.width,
|
|
749
937
|
height: preset.height,
|
|
750
938
|
guides: instagramGridGuides(),
|
|
751
|
-
guidesLocked:
|
|
939
|
+
guidesLocked: false
|
|
752
940
|
});
|
|
753
941
|
zoom = 0.25;
|
|
754
942
|
return;
|
|
@@ -1129,8 +1317,8 @@
|
|
|
1129
1317
|
downloadBlob(blob, 'canvas-document.json');
|
|
1130
1318
|
return;
|
|
1131
1319
|
}
|
|
1132
|
-
const blob = await exportCanvasBlob(value, format);
|
|
1133
|
-
onexport?.({ format, document: value, blob });
|
|
1320
|
+
const blob = await exportCanvasBlob(projectPage(value, resolvedPageId), format);
|
|
1321
|
+
onexport?.({ format, document: projectPage(value, resolvedPageId), blob });
|
|
1134
1322
|
downloadBlob(blob, format === 'jpeg' ? 'canvas.jpg' : 'canvas.png');
|
|
1135
1323
|
} catch (err) {
|
|
1136
1324
|
console.error('Canvas export failed', err);
|
|
@@ -1239,7 +1427,7 @@
|
|
|
1239
1427
|
<Menubar items={menuItems} onselect={onMenu} />
|
|
1240
1428
|
{/if}
|
|
1241
1429
|
<header
|
|
1242
|
-
class="gap-3 border-border bg-
|
|
1430
|
+
class="gap-3 border-border bg-neutral-100 px-3 py-2 dark:bg-neutral-900 relative flex shrink-0 items-center border-b"
|
|
1243
1431
|
>
|
|
1244
1432
|
<div class="min-w-0 gap-2 flex items-center">
|
|
1245
1433
|
{#if editingWidget}
|
|
@@ -1291,10 +1479,10 @@
|
|
|
1291
1479
|
</div>
|
|
1292
1480
|
|
|
1293
1481
|
<div class="rounded-lg border-border bg-surface p-0.5 flex items-center border">
|
|
1294
|
-
<IconButton label="Undo" size="sm" disabled={!
|
|
1482
|
+
<IconButton label="Undo" size="sm" disabled={!canUndo} onclick={undo}>
|
|
1295
1483
|
<Undo2 class="h-3.5 w-3.5" />
|
|
1296
1484
|
</IconButton>
|
|
1297
|
-
<IconButton label="Redo" size="sm" disabled={!
|
|
1485
|
+
<IconButton label="Redo" size="sm" disabled={!canRedo} onclick={redo}>
|
|
1298
1486
|
<Redo2 class="h-3.5 w-3.5" />
|
|
1299
1487
|
</IconButton>
|
|
1300
1488
|
</div>
|
|
@@ -1309,7 +1497,7 @@
|
|
|
1309
1497
|
showGrid = !showGrid;
|
|
1310
1498
|
(e.currentTarget as HTMLButtonElement).blur();
|
|
1311
1499
|
}}
|
|
1312
|
-
class={showGrid ?
|
|
1500
|
+
class={showGrid ? toolOn : undefined}
|
|
1313
1501
|
>
|
|
1314
1502
|
<Grid3x3 class="h-3.5 w-3.5" />
|
|
1315
1503
|
</IconButton>
|
|
@@ -1335,7 +1523,7 @@
|
|
|
1335
1523
|
snap = !snap;
|
|
1336
1524
|
(e.currentTarget as HTMLButtonElement).blur();
|
|
1337
1525
|
}}
|
|
1338
|
-
class={snap ?
|
|
1526
|
+
class={snap ? toolOn : undefined}
|
|
1339
1527
|
>
|
|
1340
1528
|
<Magnet class="h-3.5 w-3.5" />
|
|
1341
1529
|
</IconButton>
|
|
@@ -1350,7 +1538,7 @@
|
|
|
1350
1538
|
label="Pen tool"
|
|
1351
1539
|
size="sm"
|
|
1352
1540
|
onclick={() => (drawMode = !drawMode)}
|
|
1353
|
-
class={drawMode ?
|
|
1541
|
+
class={drawMode ? toolOn : undefined}
|
|
1354
1542
|
>
|
|
1355
1543
|
<Pencil class="h-3.5 w-3.5" />
|
|
1356
1544
|
</IconButton>
|
|
@@ -1365,7 +1553,7 @@
|
|
|
1365
1553
|
label="Toggle guides"
|
|
1366
1554
|
size="sm"
|
|
1367
1555
|
onclick={() => (showGuides = !showGuides)}
|
|
1368
|
-
class={showGuides ?
|
|
1556
|
+
class={showGuides ? toolOn : undefined}
|
|
1369
1557
|
>
|
|
1370
1558
|
<Eye class="h-3.5 w-3.5" />
|
|
1371
1559
|
</IconButton>
|
|
@@ -1385,7 +1573,7 @@
|
|
|
1385
1573
|
label={value.guidesLocked ? 'Unlock guides' : 'Lock guides'}
|
|
1386
1574
|
size="sm"
|
|
1387
1575
|
onclick={toggleGuidesLocked}
|
|
1388
|
-
class={value.guidesLocked ?
|
|
1576
|
+
class={value.guidesLocked ? toolOn : undefined}
|
|
1389
1577
|
>
|
|
1390
1578
|
{#if value.guidesLocked}
|
|
1391
1579
|
<Lock class="h-3.5 w-3.5" />
|
|
@@ -1430,6 +1618,68 @@
|
|
|
1430
1618
|
</div>
|
|
1431
1619
|
{/if}
|
|
1432
1620
|
|
|
1621
|
+
<div
|
|
1622
|
+
class="pointer-events-none absolute inset-y-0 left-1/2 flex -translate-x-1/2 items-center"
|
|
1623
|
+
>
|
|
1624
|
+
<div
|
|
1625
|
+
class="border-border bg-neutral-50 p-0.5 dark:bg-neutral-800 pointer-events-auto flex items-center rounded-lg border"
|
|
1626
|
+
>
|
|
1627
|
+
<button
|
|
1628
|
+
type="button"
|
|
1629
|
+
class={[
|
|
1630
|
+
'rounded-md px-2.5 py-1 text-xs font-medium',
|
|
1631
|
+
stageFrame === 'edit' ? toolOn : 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
|
|
1632
|
+
]}
|
|
1633
|
+
aria-pressed={stageFrame === 'edit'}
|
|
1634
|
+
onclick={() => (stageFrame = 'edit')}
|
|
1635
|
+
>
|
|
1636
|
+
Lienzo
|
|
1637
|
+
</button>
|
|
1638
|
+
<button
|
|
1639
|
+
type="button"
|
|
1640
|
+
class={[
|
|
1641
|
+
'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
|
|
1642
|
+
stageFrame === 'desktop'
|
|
1643
|
+
? toolOn
|
|
1644
|
+
: 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
|
|
1645
|
+
]}
|
|
1646
|
+
aria-pressed={stageFrame === 'desktop'}
|
|
1647
|
+
onclick={() => (stageFrame = 'desktop')}
|
|
1648
|
+
>
|
|
1649
|
+
<Monitor class="h-3.5 w-3.5" />
|
|
1650
|
+
Escritorio
|
|
1651
|
+
</button>
|
|
1652
|
+
<button
|
|
1653
|
+
type="button"
|
|
1654
|
+
class={[
|
|
1655
|
+
'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
|
|
1656
|
+
stageFrame === 'tablet'
|
|
1657
|
+
? toolOn
|
|
1658
|
+
: 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
|
|
1659
|
+
]}
|
|
1660
|
+
aria-pressed={stageFrame === 'tablet'}
|
|
1661
|
+
onclick={() => (stageFrame = 'tablet')}
|
|
1662
|
+
>
|
|
1663
|
+
<Tablet class="h-3.5 w-3.5" />
|
|
1664
|
+
Tablet
|
|
1665
|
+
</button>
|
|
1666
|
+
<button
|
|
1667
|
+
type="button"
|
|
1668
|
+
class={[
|
|
1669
|
+
'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
|
|
1670
|
+
stageFrame === 'mobile'
|
|
1671
|
+
? toolOn
|
|
1672
|
+
: 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
|
|
1673
|
+
]}
|
|
1674
|
+
aria-pressed={stageFrame === 'mobile'}
|
|
1675
|
+
onclick={() => (stageFrame = 'mobile')}
|
|
1676
|
+
>
|
|
1677
|
+
<Smartphone class="h-3.5 w-3.5" />
|
|
1678
|
+
Móvil
|
|
1679
|
+
</button>
|
|
1680
|
+
</div>
|
|
1681
|
+
</div>
|
|
1682
|
+
|
|
1433
1683
|
<div class="gap-1 ml-auto flex items-center">
|
|
1434
1684
|
<IconButton
|
|
1435
1685
|
label="Toggle sidebar"
|
|
@@ -1694,7 +1944,8 @@
|
|
|
1694
1944
|
{/snippet}
|
|
1695
1945
|
|
|
1696
1946
|
{#snippet workspace()}
|
|
1697
|
-
<div class="min-h-0
|
|
1947
|
+
<div class="flex h-full min-h-0 flex-col">
|
|
1948
|
+
<div class="relative min-h-0 flex-1">
|
|
1698
1949
|
<MediaStage
|
|
1699
1950
|
document={stageDoc}
|
|
1700
1951
|
{selectedIds}
|
|
@@ -1746,46 +1997,31 @@
|
|
|
1746
1997
|
{editingTextId}
|
|
1747
1998
|
ontextcommit={commitText}
|
|
1748
1999
|
/>
|
|
1749
|
-
|
|
1750
|
-
<div class="pointer-events-
|
|
1751
|
-
<
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
>
|
|
1758
|
-
Lienzo
|
|
1759
|
-
</DockItem>
|
|
1760
|
-
<DockItem
|
|
1761
|
-
size="sm"
|
|
1762
|
-
active={stageFrame === 'desktop'}
|
|
1763
|
-
ariaLabel="Escritorio"
|
|
1764
|
-
onclick={() => (stageFrame = 'desktop')}
|
|
1765
|
-
>
|
|
1766
|
-
<Monitor class="h-3.5 w-3.5" />
|
|
1767
|
-
Escritorio
|
|
1768
|
-
</DockItem>
|
|
1769
|
-
<DockItem
|
|
1770
|
-
size="sm"
|
|
1771
|
-
active={stageFrame === 'tablet'}
|
|
1772
|
-
ariaLabel="Tablet"
|
|
1773
|
-
onclick={() => (stageFrame = 'tablet')}
|
|
1774
|
-
>
|
|
1775
|
-
<Tablet class="h-3.5 w-3.5" />
|
|
1776
|
-
Tablet
|
|
1777
|
-
</DockItem>
|
|
1778
|
-
<DockItem
|
|
1779
|
-
size="sm"
|
|
1780
|
-
active={stageFrame === 'mobile'}
|
|
1781
|
-
ariaLabel="Móvil"
|
|
1782
|
-
onclick={() => (stageFrame = 'mobile')}
|
|
1783
|
-
>
|
|
1784
|
-
<Smartphone class="h-3.5 w-3.5" />
|
|
1785
|
-
Móvil
|
|
1786
|
-
</DockItem>
|
|
1787
|
-
</Dock>
|
|
2000
|
+
{#if selectedLayer && mode !== 'frame'}
|
|
2001
|
+
<div class="inset-x-0 top-3 pointer-events-none absolute z-30 flex justify-center">
|
|
2002
|
+
<CanvasQuickDock
|
|
2003
|
+
layer={selectedLayer}
|
|
2004
|
+
onpatch={patchLayer}
|
|
2005
|
+
onduplicate={duplicateSelected}
|
|
2006
|
+
ondelete={deleteSelected}
|
|
2007
|
+
/>
|
|
1788
2008
|
</div>
|
|
2009
|
+
{/if}
|
|
2010
|
+
<div class="inset-x-0 bottom-3 pointer-events-none absolute z-20 flex justify-center">
|
|
2011
|
+
{#if mode !== 'frame' && !editingWidget}
|
|
2012
|
+
<div class="pointer-events-auto">
|
|
2013
|
+
<CanvasPageStrip
|
|
2014
|
+
pages={designPages}
|
|
2015
|
+
activeId={resolvedPageId}
|
|
2016
|
+
onselect={showPage}
|
|
2017
|
+
onduplicate={duplicatePage}
|
|
2018
|
+
ondelete={deletePage}
|
|
2019
|
+
onmove={movePage}
|
|
2020
|
+
onadd={addPage}
|
|
2021
|
+
/>
|
|
2022
|
+
</div>
|
|
2023
|
+
{/if}
|
|
2024
|
+
</div>
|
|
1789
2025
|
</div>
|
|
1790
2026
|
</div>
|
|
1791
2027
|
{/snippet}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import IconButton from '../../atoms/IconButton/IconButton.svelte';
|
|
3
|
+
import type { CanvasPage } from '../../../utils/canvasDocument.js';
|
|
4
|
+
import Plus from '@lucide/svelte/icons/plus';
|
|
5
|
+
import Copy from '@lucide/svelte/icons/copy';
|
|
6
|
+
import Trash2 from '@lucide/svelte/icons/trash-2';
|
|
7
|
+
import ChevronDown from '@lucide/svelte/icons/chevron-down';
|
|
8
|
+
import ChevronLeft from '@lucide/svelte/icons/chevron-left';
|
|
9
|
+
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
|
10
|
+
|
|
11
|
+
interface CanvasPageStripProps {
|
|
12
|
+
pages: CanvasPage[];
|
|
13
|
+
activeId: string;
|
|
14
|
+
onselect: (id: string) => void;
|
|
15
|
+
onadd: () => void;
|
|
16
|
+
onduplicate: (id: string) => void;
|
|
17
|
+
ondelete: (id: string) => void;
|
|
18
|
+
onmove: (id: string, direction: -1 | 1) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let { pages, activeId, onselect, onadd, onduplicate, ondelete, onmove }: CanvasPageStripProps =
|
|
22
|
+
$props();
|
|
23
|
+
|
|
24
|
+
let open = $state(false);
|
|
25
|
+
|
|
26
|
+
const activeIndex = $derived(Math.max(0, pages.findIndex((page) => page.id === activeId)));
|
|
27
|
+
const active = $derived(pages[activeIndex] ?? pages[0]);
|
|
28
|
+
|
|
29
|
+
function pick(id: string) {
|
|
30
|
+
onselect(id);
|
|
31
|
+
open = false;
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<div class="relative">
|
|
36
|
+
<div
|
|
37
|
+
class="border-border bg-neutral-100 dark:bg-neutral-900 gap-0.5 rounded-xl p-1 shadow-lg flex items-center border"
|
|
38
|
+
aria-label="Hojas"
|
|
39
|
+
>
|
|
40
|
+
<button
|
|
41
|
+
type="button"
|
|
42
|
+
class="rounded-md relative h-11 w-9 overflow-hidden border border-border"
|
|
43
|
+
style:background-color={active?.background ?? '#ffffff'}
|
|
44
|
+
aria-current="true"
|
|
45
|
+
aria-label={`${active?.name?.trim() || `Hoja ${activeIndex + 1}`}, ${activeIndex + 1} de ${pages.length}`}
|
|
46
|
+
onclick={() => (open = !open)}
|
|
47
|
+
>
|
|
48
|
+
<span
|
|
49
|
+
class="bottom-0.5 left-0.5 rounded-sm bg-white/90 px-0.5 text-[10px] font-semibold leading-none text-neutral-900 absolute"
|
|
50
|
+
>
|
|
51
|
+
{activeIndex + 1}
|
|
52
|
+
</span>
|
|
53
|
+
</button>
|
|
54
|
+
<span class="text-neutral-700 dark:text-neutral-200 px-1 text-[11px] font-medium tabular-nums">
|
|
55
|
+
{activeIndex + 1} de {pages.length}
|
|
56
|
+
</span>
|
|
57
|
+
<IconButton label="Añadir hoja" size="sm" onclick={onadd}>
|
|
58
|
+
<Plus class="h-4 w-4" />
|
|
59
|
+
</IconButton>
|
|
60
|
+
<IconButton
|
|
61
|
+
label={open ? 'Cerrar hojas' : 'Ver hojas'}
|
|
62
|
+
size="sm"
|
|
63
|
+
onclick={() => (open = !open)}
|
|
64
|
+
>
|
|
65
|
+
<ChevronDown class={['h-4 w-4 transition-transform', open && 'rotate-180']} />
|
|
66
|
+
</IconButton>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
{#if open}
|
|
70
|
+
<div
|
|
71
|
+
class="border-border bg-surface-elevated bottom-full rounded-xl p-2 shadow-lg absolute left-1/2 mb-2 w-72 -translate-x-1/2 border"
|
|
72
|
+
>
|
|
73
|
+
<div class="gap-2 flex overflow-x-auto pb-1">
|
|
74
|
+
{#each pages as page, index (page.id)}
|
|
75
|
+
{@const selected = page.id === activeId}
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
class={[
|
|
79
|
+
'rounded-md relative h-16 w-12 shrink-0 overflow-hidden border',
|
|
80
|
+
selected ? 'border-neutral-950 ring-2 ring-neutral-950 dark:border-neutral-50 dark:ring-neutral-50' : 'border-border'
|
|
81
|
+
]}
|
|
82
|
+
style:background-color={page.background}
|
|
83
|
+
aria-current={selected ? 'true' : undefined}
|
|
84
|
+
aria-label={page.name?.trim() || `Hoja ${index + 1}`}
|
|
85
|
+
onclick={() => pick(page.id)}
|
|
86
|
+
>
|
|
87
|
+
<span
|
|
88
|
+
class="bottom-0.5 left-0.5 rounded-sm bg-white/90 px-0.5 text-[10px] font-semibold leading-none text-neutral-900 absolute"
|
|
89
|
+
>
|
|
90
|
+
{index + 1}
|
|
91
|
+
</span>
|
|
92
|
+
</button>
|
|
93
|
+
{/each}
|
|
94
|
+
</div>
|
|
95
|
+
{#if active}
|
|
96
|
+
<div class="mt-1 flex items-center justify-between">
|
|
97
|
+
<span class="text-secondary min-w-0 truncate text-xs">
|
|
98
|
+
{active.name?.trim() || `Hoja ${activeIndex + 1}`}
|
|
99
|
+
<span class="text-muted">· {activeIndex + 1} de {pages.length}</span>
|
|
100
|
+
</span>
|
|
101
|
+
<div class="flex shrink-0">
|
|
102
|
+
<IconButton
|
|
103
|
+
label="Mover a la izquierda"
|
|
104
|
+
size="xs"
|
|
105
|
+
disabled={activeIndex === 0}
|
|
106
|
+
onclick={() => onmove(active.id, -1)}
|
|
107
|
+
>
|
|
108
|
+
<ChevronLeft class="h-3 w-3" />
|
|
109
|
+
</IconButton>
|
|
110
|
+
<IconButton
|
|
111
|
+
label="Mover a la derecha"
|
|
112
|
+
size="xs"
|
|
113
|
+
disabled={activeIndex >= pages.length - 1}
|
|
114
|
+
onclick={() => onmove(active.id, 1)}
|
|
115
|
+
>
|
|
116
|
+
<ChevronRight class="h-3 w-3" />
|
|
117
|
+
</IconButton>
|
|
118
|
+
<IconButton label="Duplicar hoja" size="xs" onclick={() => onduplicate(active.id)}>
|
|
119
|
+
<Copy class="h-3 w-3" />
|
|
120
|
+
</IconButton>
|
|
121
|
+
<IconButton
|
|
122
|
+
label="Eliminar hoja"
|
|
123
|
+
size="xs"
|
|
124
|
+
variant="destructive"
|
|
125
|
+
disabled={pages.length < 2}
|
|
126
|
+
onclick={() => ondelete(active.id)}
|
|
127
|
+
>
|
|
128
|
+
<Trash2 class="h-3 w-3" />
|
|
129
|
+
</IconButton>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
{/if}
|
|
133
|
+
</div>
|
|
134
|
+
{/if}
|
|
135
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CanvasPage } from '../../../utils/canvasDocument.js';
|
|
2
|
+
interface CanvasPageStripProps {
|
|
3
|
+
pages: CanvasPage[];
|
|
4
|
+
activeId: string;
|
|
5
|
+
onselect: (id: string) => void;
|
|
6
|
+
onadd: () => void;
|
|
7
|
+
onduplicate: (id: string) => void;
|
|
8
|
+
ondelete: (id: string) => void;
|
|
9
|
+
onmove: (id: string, direction: -1 | 1) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const CanvasPageStrip: import("svelte").Component<CanvasPageStripProps, {}, "">;
|
|
12
|
+
type CanvasPageStrip = ReturnType<typeof CanvasPageStrip>;
|
|
13
|
+
export default CanvasPageStrip;
|