@r2digisolutions/components 0.24.3 → 0.24.5
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/MediaLayerItem/MediaLayerItem.svelte +1 -0
- package/dist/components/molecules/MediaStage/MediaStage.svelte +27 -30
- package/dist/components/molecules/PropertyField/PropertyField.svelte +14 -22
- package/dist/components/molecules/Stepper/Stepper.svelte +2 -0
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +25 -6
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +330 -78
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte.d.ts +9 -1
- 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/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 +44 -0
- package/dist/utils/canvasDocument.js +139 -5
- 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
|
|
@@ -22,19 +24,28 @@
|
|
|
22
24
|
} from '../../molecules/DropdownMenu/DropdownMenu.svelte';
|
|
23
25
|
import {
|
|
24
26
|
CANVAS_PRESETS,
|
|
27
|
+
INSTAGRAM_GRID_PRESET_ID,
|
|
25
28
|
alignLayerRect,
|
|
26
29
|
applyTextAutoSize,
|
|
30
|
+
blankCanvasPage,
|
|
31
|
+
cloneCanvasLayers,
|
|
27
32
|
createCanvasGuide,
|
|
28
33
|
createCanvasLayer,
|
|
29
34
|
createPathFromDocPoints,
|
|
30
35
|
defaultSlotFromRect,
|
|
36
|
+
documentWithPages,
|
|
31
37
|
emptyCanvasDocument,
|
|
38
|
+
instagramGridGuides,
|
|
32
39
|
migrateCanvasDocument,
|
|
40
|
+
pagesOf,
|
|
33
41
|
presetIdForSize,
|
|
42
|
+
projectPage,
|
|
43
|
+
writePage,
|
|
34
44
|
type CanvasAlign,
|
|
35
45
|
type CanvasDocument,
|
|
36
46
|
type CanvasLayer,
|
|
37
|
-
type CanvasLayerKind
|
|
47
|
+
type CanvasLayerKind,
|
|
48
|
+
type CanvasPage
|
|
38
49
|
} from '../../../utils/canvasDocument.js';
|
|
39
50
|
import {
|
|
40
51
|
deleteSubtree,
|
|
@@ -135,6 +146,14 @@
|
|
|
135
146
|
* `edit` is the full canvas: panels, menu and component search.
|
|
136
147
|
*/
|
|
137
148
|
mode?: 'edit' | 'frame';
|
|
149
|
+
/** Hide the built-in menu when the host already has one. */
|
|
150
|
+
showMenu?: boolean;
|
|
151
|
+
showGrid?: boolean;
|
|
152
|
+
showGuides?: boolean;
|
|
153
|
+
snap?: boolean;
|
|
154
|
+
showSidebar?: boolean;
|
|
155
|
+
showInspector?: boolean;
|
|
156
|
+
stageFrame?: 'edit' | 'desktop' | 'tablet' | 'mobile';
|
|
138
157
|
class?: string;
|
|
139
158
|
onchange?: (doc: CanvasDocument) => void;
|
|
140
159
|
onassetschange?: (assets: MediaAsset[]) => void;
|
|
@@ -150,30 +169,34 @@
|
|
|
150
169
|
assets = $bindable<MediaAsset[]>([]),
|
|
151
170
|
zoom = $bindable(1),
|
|
152
171
|
mode = 'edit',
|
|
172
|
+
showMenu = true,
|
|
173
|
+
showGrid = $bindable(false),
|
|
174
|
+
showGuides = $bindable(true),
|
|
175
|
+
snap = $bindable(true),
|
|
176
|
+
showSidebar = $bindable(true),
|
|
177
|
+
showInspector = $bindable(true),
|
|
178
|
+
stageFrame = $bindable<'edit' | 'desktop' | 'tablet' | 'mobile'>('edit'),
|
|
153
179
|
class: className = '',
|
|
154
180
|
onchange,
|
|
155
181
|
onassetschange,
|
|
156
182
|
onexport
|
|
157
183
|
}: CanvasEditorProps = $props();
|
|
158
184
|
|
|
159
|
-
// Ensure v2 document shape
|
|
185
|
+
// Ensure v2 document shape and a page list (older files are one sheet).
|
|
160
186
|
$effect.pre(() => {
|
|
161
187
|
if (value.version !== 2 || !value.widgets) {
|
|
162
188
|
value = migrateCanvasDocument(value);
|
|
163
189
|
}
|
|
190
|
+
if (!value.pages?.length) {
|
|
191
|
+
value = documentWithPages(value);
|
|
192
|
+
}
|
|
164
193
|
});
|
|
165
194
|
|
|
166
195
|
let selectedIds = $state<string[]>([]);
|
|
167
196
|
let editingTextId = $state<string | null>(null);
|
|
168
197
|
let frameBoot = false;
|
|
169
|
-
let showSidebar = $state(true);
|
|
170
|
-
let showInspector = $state(true);
|
|
171
198
|
let assetsSize = $state(58);
|
|
172
199
|
let sidebarTab = $state<'elements' | 'uploads' | 'widgets'>('elements');
|
|
173
|
-
let showGrid = $state(false);
|
|
174
|
-
let stageFrame = $state<'edit' | 'desktop' | 'tablet' | 'mobile'>('edit');
|
|
175
|
-
let showGuides = $state(true);
|
|
176
|
-
let snap = $state(true);
|
|
177
200
|
let cellSize = $state(8);
|
|
178
201
|
let drawMode = $state(false);
|
|
179
202
|
let ctxOpen = $state(false);
|
|
@@ -184,7 +207,12 @@
|
|
|
184
207
|
let editingWidgetId = $state<string | null>(null);
|
|
185
208
|
let history = $state<CanvasHistoryState>(createCanvasHistory(value));
|
|
186
209
|
let applyingHistory = false;
|
|
210
|
+
let activePageId = $state('');
|
|
211
|
+
type PageSnap = { width: number; height: number; page: CanvasPage };
|
|
212
|
+
type PageHist = { past: string[]; future: string[]; last: string };
|
|
213
|
+
let pageHistory = $state<Record<string, PageHist>>({});
|
|
187
214
|
let syncInstanceSizes = $state(true);
|
|
215
|
+
const toolOn = 'bg-neutral-200 text-neutral-950 dark:bg-neutral-700 dark:text-neutral-50';
|
|
188
216
|
|
|
189
217
|
const gridSizeOptions = [
|
|
190
218
|
{ value: '4', label: '4px' },
|
|
@@ -199,8 +227,22 @@
|
|
|
199
227
|
editingWidgetId ? ((value.widgets ?? []).find((w) => w.id === editingWidgetId) ?? null) : null
|
|
200
228
|
);
|
|
201
229
|
|
|
230
|
+
const designPages = $derived(pagesOf(value));
|
|
231
|
+
const resolvedPageId = $derived(
|
|
232
|
+
designPages.some((page) => page.id === activePageId)
|
|
233
|
+
? activePageId
|
|
234
|
+
: (designPages[0]?.id ?? '')
|
|
235
|
+
);
|
|
236
|
+
const activePageHist = $derived(pageHistory[resolvedPageId]);
|
|
237
|
+
const canUndo = $derived(
|
|
238
|
+
editingWidgetId ? history.past.length > 0 : (activePageHist?.past.length ?? 0) > 0
|
|
239
|
+
);
|
|
240
|
+
const canRedo = $derived(
|
|
241
|
+
editingWidgetId ? history.future.length > 0 : (activePageHist?.future.length ?? 0) > 0
|
|
242
|
+
);
|
|
243
|
+
|
|
202
244
|
const stageDoc = $derived.by((): CanvasDocument => {
|
|
203
|
-
if (!editingWidget) return value;
|
|
245
|
+
if (!editingWidget) return projectPage(value, resolvedPageId);
|
|
204
246
|
return {
|
|
205
247
|
...value,
|
|
206
248
|
width: editingWidget.width,
|
|
@@ -236,8 +278,8 @@
|
|
|
236
278
|
id: 'edit',
|
|
237
279
|
label: 'Edición',
|
|
238
280
|
items: [
|
|
239
|
-
{ id: 'undo', label: 'Deshacer', shortcut: '⌘Z', disabled:
|
|
240
|
-
{ id: 'redo', label: 'Rehacer', shortcut: '⇧⌘Z', disabled:
|
|
281
|
+
{ id: 'undo', label: 'Deshacer', shortcut: '⌘Z', disabled: !canUndo },
|
|
282
|
+
{ id: 'redo', label: 'Rehacer', shortcut: '⇧⌘Z', disabled: !canRedo },
|
|
241
283
|
{
|
|
242
284
|
id: 'delete',
|
|
243
285
|
label: 'Borrar selección',
|
|
@@ -460,37 +502,187 @@
|
|
|
460
502
|
];
|
|
461
503
|
});
|
|
462
504
|
|
|
505
|
+
function pageSnap(doc: CanvasDocument, pageId: string): string {
|
|
506
|
+
const page = pagesOf(doc).find((item) => item.id === pageId) ?? pagesOf(doc)[0];
|
|
507
|
+
const snap: PageSnap = { width: doc.width, height: doc.height, page };
|
|
508
|
+
return JSON.stringify(snap);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function seedPageHistory(doc: CanvasDocument, pageId: string) {
|
|
512
|
+
if (!pageId || pageHistory[pageId]) return;
|
|
513
|
+
pageHistory = {
|
|
514
|
+
...pageHistory,
|
|
515
|
+
[pageId]: { past: [], future: [], last: pageSnap(doc, pageId) }
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function applyPageSnap(doc: CanvasDocument, raw: string): CanvasDocument {
|
|
520
|
+
const snap = JSON.parse(raw) as PageSnap;
|
|
521
|
+
return {
|
|
522
|
+
...writePage(doc, snap.page.id, snap.page),
|
|
523
|
+
width: snap.width,
|
|
524
|
+
height: snap.height
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
463
528
|
function emit(next: CanvasDocument) {
|
|
464
529
|
const migrated = migrateCanvasDocument(next);
|
|
465
|
-
if (
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
530
|
+
if (editingWidgetId) {
|
|
531
|
+
if (!applyingHistory) {
|
|
532
|
+
history = pushCanvasHistory(history, migrated);
|
|
533
|
+
} else {
|
|
534
|
+
history = { ...history, last: JSON.stringify(migrated) };
|
|
535
|
+
}
|
|
536
|
+
value = migrated;
|
|
537
|
+
onchange?.(value);
|
|
538
|
+
return;
|
|
469
539
|
}
|
|
470
|
-
|
|
540
|
+
const pageId = resolvedPageId;
|
|
541
|
+
seedPageHistory(value, pageId);
|
|
542
|
+
const stored = {
|
|
543
|
+
...writePage(migrated, pageId, {
|
|
544
|
+
background: migrated.background,
|
|
545
|
+
layers: migrated.layers,
|
|
546
|
+
guides: migrated.guides,
|
|
547
|
+
guidesLocked: migrated.guidesLocked
|
|
548
|
+
}),
|
|
549
|
+
width: migrated.width,
|
|
550
|
+
height: migrated.height,
|
|
551
|
+
widgets: migrated.widgets ?? []
|
|
552
|
+
};
|
|
553
|
+
const snap = pageSnap(stored, pageId);
|
|
554
|
+
const hist = pageHistory[pageId] ?? { past: [], future: [], last: snap };
|
|
555
|
+
if (!applyingHistory && snap !== hist.last) {
|
|
556
|
+
pageHistory = {
|
|
557
|
+
...pageHistory,
|
|
558
|
+
[pageId]: {
|
|
559
|
+
past: [...hist.past, hist.last].slice(-80),
|
|
560
|
+
future: [],
|
|
561
|
+
last: snap
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
} else if (applyingHistory) {
|
|
565
|
+
pageHistory = {
|
|
566
|
+
...pageHistory,
|
|
567
|
+
[pageId]: { ...hist, last: snap }
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
value = stored;
|
|
471
571
|
onchange?.(value);
|
|
472
572
|
}
|
|
473
573
|
|
|
474
574
|
function undo() {
|
|
475
|
-
|
|
476
|
-
|
|
575
|
+
if (editingWidgetId) {
|
|
576
|
+
const result = undoCanvasHistory(history);
|
|
577
|
+
if (!result) return;
|
|
578
|
+
applyingHistory = true;
|
|
579
|
+
history = result.state;
|
|
580
|
+
value = migrateCanvasDocument(result.doc);
|
|
581
|
+
applyingHistory = false;
|
|
582
|
+
onchange?.(value);
|
|
583
|
+
selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const pageId = resolvedPageId;
|
|
587
|
+
const hist = pageHistory[pageId];
|
|
588
|
+
if (!hist?.past.length) return;
|
|
589
|
+
const prev = hist.past[hist.past.length - 1];
|
|
477
590
|
applyingHistory = true;
|
|
478
|
-
|
|
479
|
-
|
|
591
|
+
pageHistory = {
|
|
592
|
+
...pageHistory,
|
|
593
|
+
[pageId]: {
|
|
594
|
+
past: hist.past.slice(0, -1),
|
|
595
|
+
future: [hist.last, ...hist.future].slice(0, 80),
|
|
596
|
+
last: prev
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
value = applyPageSnap(value, prev);
|
|
480
600
|
applyingHistory = false;
|
|
481
601
|
onchange?.(value);
|
|
482
|
-
selectedIds = selectedIds.filter((id) =>
|
|
602
|
+
selectedIds = selectedIds.filter((id) => value.layers.some((l) => l.id === id));
|
|
483
603
|
}
|
|
484
604
|
|
|
485
605
|
function redo() {
|
|
486
|
-
|
|
487
|
-
|
|
606
|
+
if (editingWidgetId) {
|
|
607
|
+
const result = redoCanvasHistory(history);
|
|
608
|
+
if (!result) return;
|
|
609
|
+
applyingHistory = true;
|
|
610
|
+
history = result.state;
|
|
611
|
+
value = migrateCanvasDocument(result.doc);
|
|
612
|
+
applyingHistory = false;
|
|
613
|
+
onchange?.(value);
|
|
614
|
+
selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const pageId = resolvedPageId;
|
|
618
|
+
const hist = pageHistory[pageId];
|
|
619
|
+
if (!hist?.future.length) return;
|
|
620
|
+
const next = hist.future[0];
|
|
488
621
|
applyingHistory = true;
|
|
489
|
-
|
|
490
|
-
|
|
622
|
+
pageHistory = {
|
|
623
|
+
...pageHistory,
|
|
624
|
+
[pageId]: {
|
|
625
|
+
past: [...hist.past, hist.last].slice(-80),
|
|
626
|
+
future: hist.future.slice(1),
|
|
627
|
+
last: next
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
value = applyPageSnap(value, next);
|
|
491
631
|
applyingHistory = false;
|
|
492
632
|
onchange?.(value);
|
|
493
|
-
selectedIds = selectedIds.filter((id) =>
|
|
633
|
+
selectedIds = selectedIds.filter((id) => value.layers.some((l) => l.id === id));
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function showPage(pageId: string, pages = pagesOf(value)) {
|
|
637
|
+
activePageId = pageId;
|
|
638
|
+
const next = projectPage({ ...value, pages }, pageId);
|
|
639
|
+
seedPageHistory(next, pageId);
|
|
640
|
+
value = next;
|
|
641
|
+
selectedIds = [];
|
|
642
|
+
editingTextId = null;
|
|
643
|
+
onchange?.(value);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function addPage() {
|
|
647
|
+
const page = blankCanvasPage({ name: `Hoja ${designPages.length + 1}` });
|
|
648
|
+
showPage(page.id, [...designPages, page]);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function duplicatePage(pageId: string) {
|
|
652
|
+
const source = designPages.find((page) => page.id === pageId);
|
|
653
|
+
if (!source) return;
|
|
654
|
+
const copy = blankCanvasPage({
|
|
655
|
+
name: `${source.name?.trim() || 'Hoja'} copia`,
|
|
656
|
+
background: source.background,
|
|
657
|
+
layers: cloneCanvasLayers(source.layers),
|
|
658
|
+
guides: (source.guides ?? []).map((guide) =>
|
|
659
|
+
createCanvasGuide(guide.orientation, guide.position, { locked: guide.locked })
|
|
660
|
+
),
|
|
661
|
+
guidesLocked: source.guidesLocked
|
|
662
|
+
});
|
|
663
|
+
const index = designPages.findIndex((page) => page.id === pageId);
|
|
664
|
+
const pages = [...designPages];
|
|
665
|
+
pages.splice(index + 1, 0, copy);
|
|
666
|
+
showPage(copy.id, pages);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function deletePage(pageId: string) {
|
|
670
|
+
if (designPages.length < 2) return;
|
|
671
|
+
const index = designPages.findIndex((page) => page.id === pageId);
|
|
672
|
+
const pages = designPages.filter((page) => page.id !== pageId);
|
|
673
|
+
const neighbor = pages[Math.min(index, pages.length - 1)];
|
|
674
|
+
showPage(neighbor.id, pages);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function movePage(pageId: string, direction: -1 | 1) {
|
|
678
|
+
const pages = [...designPages];
|
|
679
|
+
const index = pages.findIndex((page) => page.id === pageId);
|
|
680
|
+
const target = index + direction;
|
|
681
|
+
if (index < 0 || target < 0 || target >= pages.length) return;
|
|
682
|
+
const [item] = pages.splice(index, 1);
|
|
683
|
+
pages.splice(target, 0, item);
|
|
684
|
+
value = projectPage({ ...value, pages }, resolvedPageId);
|
|
685
|
+
onchange?.(value);
|
|
494
686
|
}
|
|
495
687
|
|
|
496
688
|
function emitStageLayers(layers: CanvasLayer[], extra?: Partial<CanvasDocument>) {
|
|
@@ -731,6 +923,17 @@
|
|
|
731
923
|
if (editingWidgetId) return;
|
|
732
924
|
const preset = CANVAS_PRESETS.find((p) => p.id === id);
|
|
733
925
|
if (!preset) return;
|
|
926
|
+
if (id === INSTAGRAM_GRID_PRESET_ID) {
|
|
927
|
+
emit({
|
|
928
|
+
...value,
|
|
929
|
+
width: preset.width,
|
|
930
|
+
height: preset.height,
|
|
931
|
+
guides: instagramGridGuides(),
|
|
932
|
+
guidesLocked: true
|
|
933
|
+
});
|
|
934
|
+
zoom = 0.25;
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
734
937
|
emit({ ...value, width: preset.width, height: preset.height });
|
|
735
938
|
zoom = 1;
|
|
736
939
|
}
|
|
@@ -1107,8 +1310,8 @@
|
|
|
1107
1310
|
downloadBlob(blob, 'canvas-document.json');
|
|
1108
1311
|
return;
|
|
1109
1312
|
}
|
|
1110
|
-
const blob = await exportCanvasBlob(value, format);
|
|
1111
|
-
onexport?.({ format, document: value, blob });
|
|
1313
|
+
const blob = await exportCanvasBlob(projectPage(value, resolvedPageId), format);
|
|
1314
|
+
onexport?.({ format, document: projectPage(value, resolvedPageId), blob });
|
|
1112
1315
|
downloadBlob(blob, format === 'jpeg' ? 'canvas.jpg' : 'canvas.png');
|
|
1113
1316
|
} catch (err) {
|
|
1114
1317
|
console.error('Canvas export failed', err);
|
|
@@ -1213,11 +1416,11 @@
|
|
|
1213
1416
|
<svelte:window onkeydowncapture={handleKeydown} />
|
|
1214
1417
|
|
|
1215
1418
|
<div class={['min-h-0 relative flex h-full flex-col', className]}>
|
|
1216
|
-
{#if mode !== 'frame'}
|
|
1419
|
+
{#if mode !== 'frame' && showMenu}
|
|
1217
1420
|
<Menubar items={menuItems} onselect={onMenu} />
|
|
1218
1421
|
{/if}
|
|
1219
1422
|
<header
|
|
1220
|
-
class="gap-3 border-border bg-
|
|
1423
|
+
class="gap-3 border-border bg-neutral-100 px-3 py-2 dark:bg-neutral-900 relative flex shrink-0 items-center border-b"
|
|
1221
1424
|
>
|
|
1222
1425
|
<div class="min-w-0 gap-2 flex items-center">
|
|
1223
1426
|
{#if editingWidget}
|
|
@@ -1238,7 +1441,8 @@
|
|
|
1238
1441
|
<span class="text-sm font-semibold text-primary sm:inline hidden">Canvas</span>
|
|
1239
1442
|
<Select
|
|
1240
1443
|
size="sm"
|
|
1241
|
-
class="w-
|
|
1444
|
+
class="min-w-72"
|
|
1445
|
+
listboxMinWidth={320}
|
|
1242
1446
|
options={presetOptions}
|
|
1243
1447
|
value={presetValue}
|
|
1244
1448
|
onchange={(id) => {
|
|
@@ -1268,10 +1472,10 @@
|
|
|
1268
1472
|
</div>
|
|
1269
1473
|
|
|
1270
1474
|
<div class="rounded-lg border-border bg-surface p-0.5 flex items-center border">
|
|
1271
|
-
<IconButton label="Undo" size="sm" disabled={!
|
|
1475
|
+
<IconButton label="Undo" size="sm" disabled={!canUndo} onclick={undo}>
|
|
1272
1476
|
<Undo2 class="h-3.5 w-3.5" />
|
|
1273
1477
|
</IconButton>
|
|
1274
|
-
<IconButton label="Redo" size="sm" disabled={!
|
|
1478
|
+
<IconButton label="Redo" size="sm" disabled={!canRedo} onclick={redo}>
|
|
1275
1479
|
<Redo2 class="h-3.5 w-3.5" />
|
|
1276
1480
|
</IconButton>
|
|
1277
1481
|
</div>
|
|
@@ -1286,7 +1490,7 @@
|
|
|
1286
1490
|
showGrid = !showGrid;
|
|
1287
1491
|
(e.currentTarget as HTMLButtonElement).blur();
|
|
1288
1492
|
}}
|
|
1289
|
-
class={showGrid ?
|
|
1493
|
+
class={showGrid ? toolOn : undefined}
|
|
1290
1494
|
>
|
|
1291
1495
|
<Grid3x3 class="h-3.5 w-3.5" />
|
|
1292
1496
|
</IconButton>
|
|
@@ -1312,7 +1516,7 @@
|
|
|
1312
1516
|
snap = !snap;
|
|
1313
1517
|
(e.currentTarget as HTMLButtonElement).blur();
|
|
1314
1518
|
}}
|
|
1315
|
-
class={snap ?
|
|
1519
|
+
class={snap ? toolOn : undefined}
|
|
1316
1520
|
>
|
|
1317
1521
|
<Magnet class="h-3.5 w-3.5" />
|
|
1318
1522
|
</IconButton>
|
|
@@ -1327,7 +1531,7 @@
|
|
|
1327
1531
|
label="Pen tool"
|
|
1328
1532
|
size="sm"
|
|
1329
1533
|
onclick={() => (drawMode = !drawMode)}
|
|
1330
|
-
class={drawMode ?
|
|
1534
|
+
class={drawMode ? toolOn : undefined}
|
|
1331
1535
|
>
|
|
1332
1536
|
<Pencil class="h-3.5 w-3.5" />
|
|
1333
1537
|
</IconButton>
|
|
@@ -1342,7 +1546,7 @@
|
|
|
1342
1546
|
label="Toggle guides"
|
|
1343
1547
|
size="sm"
|
|
1344
1548
|
onclick={() => (showGuides = !showGuides)}
|
|
1345
|
-
class={showGuides ?
|
|
1549
|
+
class={showGuides ? toolOn : undefined}
|
|
1346
1550
|
>
|
|
1347
1551
|
<Eye class="h-3.5 w-3.5" />
|
|
1348
1552
|
</IconButton>
|
|
@@ -1362,7 +1566,7 @@
|
|
|
1362
1566
|
label={value.guidesLocked ? 'Unlock guides' : 'Lock guides'}
|
|
1363
1567
|
size="sm"
|
|
1364
1568
|
onclick={toggleGuidesLocked}
|
|
1365
|
-
class={value.guidesLocked ?
|
|
1569
|
+
class={value.guidesLocked ? toolOn : undefined}
|
|
1366
1570
|
>
|
|
1367
1571
|
{#if value.guidesLocked}
|
|
1368
1572
|
<Lock class="h-3.5 w-3.5" />
|
|
@@ -1407,6 +1611,68 @@
|
|
|
1407
1611
|
</div>
|
|
1408
1612
|
{/if}
|
|
1409
1613
|
|
|
1614
|
+
<div
|
|
1615
|
+
class="pointer-events-none absolute inset-y-0 left-1/2 flex -translate-x-1/2 items-center"
|
|
1616
|
+
>
|
|
1617
|
+
<div
|
|
1618
|
+
class="border-border bg-neutral-50 p-0.5 dark:bg-neutral-800 pointer-events-auto flex items-center rounded-lg border"
|
|
1619
|
+
>
|
|
1620
|
+
<button
|
|
1621
|
+
type="button"
|
|
1622
|
+
class={[
|
|
1623
|
+
'rounded-md px-2.5 py-1 text-xs font-medium',
|
|
1624
|
+
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'
|
|
1625
|
+
]}
|
|
1626
|
+
aria-pressed={stageFrame === 'edit'}
|
|
1627
|
+
onclick={() => (stageFrame = 'edit')}
|
|
1628
|
+
>
|
|
1629
|
+
Lienzo
|
|
1630
|
+
</button>
|
|
1631
|
+
<button
|
|
1632
|
+
type="button"
|
|
1633
|
+
class={[
|
|
1634
|
+
'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
|
|
1635
|
+
stageFrame === 'desktop'
|
|
1636
|
+
? toolOn
|
|
1637
|
+
: 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
|
|
1638
|
+
]}
|
|
1639
|
+
aria-pressed={stageFrame === 'desktop'}
|
|
1640
|
+
onclick={() => (stageFrame = 'desktop')}
|
|
1641
|
+
>
|
|
1642
|
+
<Monitor class="h-3.5 w-3.5" />
|
|
1643
|
+
Escritorio
|
|
1644
|
+
</button>
|
|
1645
|
+
<button
|
|
1646
|
+
type="button"
|
|
1647
|
+
class={[
|
|
1648
|
+
'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
|
|
1649
|
+
stageFrame === 'tablet'
|
|
1650
|
+
? toolOn
|
|
1651
|
+
: 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
|
|
1652
|
+
]}
|
|
1653
|
+
aria-pressed={stageFrame === 'tablet'}
|
|
1654
|
+
onclick={() => (stageFrame = 'tablet')}
|
|
1655
|
+
>
|
|
1656
|
+
<Tablet class="h-3.5 w-3.5" />
|
|
1657
|
+
Tablet
|
|
1658
|
+
</button>
|
|
1659
|
+
<button
|
|
1660
|
+
type="button"
|
|
1661
|
+
class={[
|
|
1662
|
+
'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
|
|
1663
|
+
stageFrame === 'mobile'
|
|
1664
|
+
? toolOn
|
|
1665
|
+
: 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
|
|
1666
|
+
]}
|
|
1667
|
+
aria-pressed={stageFrame === 'mobile'}
|
|
1668
|
+
onclick={() => (stageFrame = 'mobile')}
|
|
1669
|
+
>
|
|
1670
|
+
<Smartphone class="h-3.5 w-3.5" />
|
|
1671
|
+
Móvil
|
|
1672
|
+
</button>
|
|
1673
|
+
</div>
|
|
1674
|
+
</div>
|
|
1675
|
+
|
|
1410
1676
|
<div class="gap-1 ml-auto flex items-center">
|
|
1411
1677
|
<IconButton
|
|
1412
1678
|
label="Toggle sidebar"
|
|
@@ -1671,7 +1937,8 @@
|
|
|
1671
1937
|
{/snippet}
|
|
1672
1938
|
|
|
1673
1939
|
{#snippet workspace()}
|
|
1674
|
-
<div class="min-h-0
|
|
1940
|
+
<div class="flex h-full min-h-0 flex-col">
|
|
1941
|
+
<div class="relative min-h-0 flex-1">
|
|
1675
1942
|
<MediaStage
|
|
1676
1943
|
document={stageDoc}
|
|
1677
1944
|
{selectedIds}
|
|
@@ -1723,46 +1990,31 @@
|
|
|
1723
1990
|
{editingTextId}
|
|
1724
1991
|
ontextcommit={commitText}
|
|
1725
1992
|
/>
|
|
1726
|
-
|
|
1727
|
-
<div class="pointer-events-
|
|
1728
|
-
<
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
>
|
|
1735
|
-
Lienzo
|
|
1736
|
-
</DockItem>
|
|
1737
|
-
<DockItem
|
|
1738
|
-
size="sm"
|
|
1739
|
-
active={stageFrame === 'desktop'}
|
|
1740
|
-
ariaLabel="Escritorio"
|
|
1741
|
-
onclick={() => (stageFrame = 'desktop')}
|
|
1742
|
-
>
|
|
1743
|
-
<Monitor class="h-3.5 w-3.5" />
|
|
1744
|
-
Escritorio
|
|
1745
|
-
</DockItem>
|
|
1746
|
-
<DockItem
|
|
1747
|
-
size="sm"
|
|
1748
|
-
active={stageFrame === 'tablet'}
|
|
1749
|
-
ariaLabel="Tablet"
|
|
1750
|
-
onclick={() => (stageFrame = 'tablet')}
|
|
1751
|
-
>
|
|
1752
|
-
<Tablet class="h-3.5 w-3.5" />
|
|
1753
|
-
Tablet
|
|
1754
|
-
</DockItem>
|
|
1755
|
-
<DockItem
|
|
1756
|
-
size="sm"
|
|
1757
|
-
active={stageFrame === 'mobile'}
|
|
1758
|
-
ariaLabel="Móvil"
|
|
1759
|
-
onclick={() => (stageFrame = 'mobile')}
|
|
1760
|
-
>
|
|
1761
|
-
<Smartphone class="h-3.5 w-3.5" />
|
|
1762
|
-
Móvil
|
|
1763
|
-
</DockItem>
|
|
1764
|
-
</Dock>
|
|
1993
|
+
{#if selectedLayer && mode !== 'frame'}
|
|
1994
|
+
<div class="inset-x-0 top-3 pointer-events-none absolute z-30 flex justify-center">
|
|
1995
|
+
<CanvasQuickDock
|
|
1996
|
+
layer={selectedLayer}
|
|
1997
|
+
onpatch={patchLayer}
|
|
1998
|
+
onduplicate={duplicateSelected}
|
|
1999
|
+
ondelete={deleteSelected}
|
|
2000
|
+
/>
|
|
1765
2001
|
</div>
|
|
2002
|
+
{/if}
|
|
2003
|
+
<div class="inset-x-0 bottom-3 pointer-events-none absolute z-20 flex justify-center">
|
|
2004
|
+
{#if mode !== 'frame' && !editingWidget}
|
|
2005
|
+
<div class="pointer-events-auto">
|
|
2006
|
+
<CanvasPageStrip
|
|
2007
|
+
pages={designPages}
|
|
2008
|
+
activeId={resolvedPageId}
|
|
2009
|
+
onselect={showPage}
|
|
2010
|
+
onduplicate={duplicatePage}
|
|
2011
|
+
ondelete={deletePage}
|
|
2012
|
+
onmove={movePage}
|
|
2013
|
+
onadd={addPage}
|
|
2014
|
+
/>
|
|
2015
|
+
</div>
|
|
2016
|
+
{/if}
|
|
2017
|
+
</div>
|
|
1766
2018
|
</div>
|
|
1767
2019
|
</div>
|
|
1768
2020
|
{/snippet}
|
|
@@ -10,6 +10,14 @@ interface CanvasEditorProps {
|
|
|
10
10
|
* `edit` is the full canvas: panels, menu and component search.
|
|
11
11
|
*/
|
|
12
12
|
mode?: 'edit' | 'frame';
|
|
13
|
+
/** Hide the built-in menu when the host already has one. */
|
|
14
|
+
showMenu?: boolean;
|
|
15
|
+
showGrid?: boolean;
|
|
16
|
+
showGuides?: boolean;
|
|
17
|
+
snap?: boolean;
|
|
18
|
+
showSidebar?: boolean;
|
|
19
|
+
showInspector?: boolean;
|
|
20
|
+
stageFrame?: 'edit' | 'desktop' | 'tablet' | 'mobile';
|
|
13
21
|
class?: string;
|
|
14
22
|
onchange?: (doc: CanvasDocument) => void;
|
|
15
23
|
onassetschange?: (assets: MediaAsset[]) => void;
|
|
@@ -19,6 +27,6 @@ interface CanvasEditorProps {
|
|
|
19
27
|
blob?: Blob;
|
|
20
28
|
}) => void;
|
|
21
29
|
}
|
|
22
|
-
declare const CanvasEditor: import("svelte").Component<CanvasEditorProps, {}, "value" | "zoom" | "assets">;
|
|
30
|
+
declare const CanvasEditor: import("svelte").Component<CanvasEditorProps, {}, "value" | "zoom" | "showGrid" | "snap" | "assets" | "showGuides" | "showSidebar" | "showInspector" | "stageFrame">;
|
|
23
31
|
type CanvasEditor = ReturnType<typeof CanvasEditor>;
|
|
24
32
|
export default CanvasEditor;
|