@widgetic/creator 0.3.81 → 0.4.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/README.md +157 -0
- package/dist/CreatorApp.svelte +1103 -612
- package/dist/CreatorApp.svelte.d.ts +22 -0
- package/dist/components/BrandKitPanel.svelte +48 -40
- package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
- package/dist/components/DesignQuickEdit.svelte +13 -4
- package/dist/components/EditableName.svelte +13 -8
- package/dist/components/EditableName.svelte.d.ts +2 -2
- package/dist/components/FileUrlSourceControl.svelte +21 -8
- package/dist/components/HoverTooltip.svelte +1 -1
- package/dist/components/SelectorDropdown.svelte +19 -15
- package/dist/components/SelectorDropdown.svelte.d.ts +2 -2
- package/dist/components/VersionDropdownRow.svelte +14 -11
- package/dist/components/WidgetDetails.svelte +118 -92
- package/dist/components/WidgetShapeLivePreviews.svelte +105 -46
- package/dist/creator-types.d.ts +96 -0
- package/dist/host/creatorHost.d.ts +176 -0
- package/dist/host/creatorHost.js +242 -0
- package/dist/host/limitRefusal.d.ts +64 -0
- package/dist/host/limitRefusal.js +109 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/i18n/index.js +5 -0
- package/dist/i18n/labels.d.ts +14 -0
- package/dist/i18n/labels.js +39 -0
- package/dist/i18n/language.d.ts +559 -0
- package/dist/i18n/language.js +47 -0
- package/dist/i18n/languageKit.d.ts +52 -0
- package/dist/i18n/languageKit.js +45 -0
- package/dist/i18n/messages.d.ts +526 -0
- package/dist/i18n/messages.js +548 -0
- package/dist/i18n/slots.d.ts +22 -0
- package/dist/i18n/slots.js +42 -0
- package/dist/i18n/statusText.d.ts +22 -0
- package/dist/i18n/statusText.js +223 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/stores/userSession.d.ts +8 -1
- package/dist/stores/userSession.js +18 -25
- package/dist/stores/websocketStore.d.ts +6 -0
- package/dist/stores/websocketStore.js +39 -4
- package/dist/utils/designIntentTelemetry.d.ts +8 -0
- package/dist/utils/designIntentTelemetry.js +52 -34
- package/dist/utils/directionPlacement.d.ts +51 -0
- package/dist/utils/directionPlacement.js +55 -0
- package/dist/utils/embedCode.d.ts +0 -1
- package/dist/utils/embedCode.js +0 -4
- package/dist/utils/nativeScrollbarPadding.js +1 -1
- package/dist/utils/pickedFile.d.ts +15 -0
- package/dist/utils/pickedFile.js +21 -0
- package/dist/utils/widgeticChatUpload.d.ts +9 -0
- package/dist/utils/widgeticChatUpload.js +24 -2
- package/package.json +5 -3
- package/dist/retiredSurface.test.d.ts +0 -1
- package/dist/retiredSurface.test.js +0 -113
- package/dist/utils/designIntentResolver.test.d.ts +0 -1
- package/dist/utils/designIntentResolver.test.js +0 -246
- package/dist/utils/designIntentTelemetry.test.d.ts +0 -1
- package/dist/utils/designIntentTelemetry.test.js +0 -385
- package/dist/utils/designQuickEditValues.test.d.ts +0 -1
- package/dist/utils/designQuickEditValues.test.js +0 -100
- package/dist/utils/widgeticChatUpload.test.d.ts +0 -1
- package/dist/utils/widgeticChatUpload.test.js +0 -257
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
import { Portal } from '@widgetic/design-system';
|
|
9
9
|
import HoverTooltip from './HoverTooltip.svelte';
|
|
10
10
|
import VersionDropdownRow from './VersionDropdownRow.svelte';
|
|
11
|
+
import { errorLabel, useCreatorLanguage } from '../i18n/index.js';
|
|
12
|
+
|
|
13
|
+
const { t } = useCreatorLanguage();
|
|
11
14
|
|
|
12
15
|
interface VersionOption {
|
|
13
16
|
id: string;
|
|
@@ -165,6 +168,11 @@
|
|
|
165
168
|
// Pass the existing element to DS Portal: its string-target ancestor guard
|
|
166
169
|
// otherwise creates a second floating-panels-overlay on document.body.
|
|
167
170
|
let portalHost = $state<HTMLElement | null>(null);
|
|
171
|
+
/**
|
|
172
|
+
* An empty marker in this component's own spot of the page. Where it is tells which tree the component lives in:
|
|
173
|
+
* the document (the Widgetic site, the standalone app) or the shadow root of a partner's page.
|
|
174
|
+
*/
|
|
175
|
+
let layerAnchor = $state<HTMLElement | null>(null);
|
|
168
176
|
let draggingWidgetId = $state<string | null>(null);
|
|
169
177
|
let resizingWidgetId = $state<string | null>(null);
|
|
170
178
|
/** Per-widget cache-bust tokens for Refresh (iframe reload only). */
|
|
@@ -319,6 +327,19 @@
|
|
|
319
327
|
}
|
|
320
328
|
}
|
|
321
329
|
|
|
330
|
+
/**
|
|
331
|
+
* The element that gets "no text selection" and the grabbing cursor while a shape is dragged: the page's <body> where
|
|
332
|
+
* the creator owns the page, the creator's own root where it sits in a shadow root (the <body> is the partner's
|
|
333
|
+
* then, and the creator leaves its inline style alone).
|
|
334
|
+
*/
|
|
335
|
+
function getDragStyleTarget(): HTMLElement {
|
|
336
|
+
if (layerAnchor?.getRootNode() instanceof ShadowRoot) {
|
|
337
|
+
const creatorRoot = layerAnchor.closest('.widget-creator-root-page-ct');
|
|
338
|
+
if (creatorRoot instanceof HTMLElement) return creatorRoot;
|
|
339
|
+
}
|
|
340
|
+
return document.body;
|
|
341
|
+
}
|
|
342
|
+
|
|
322
343
|
function startShapeDrag(event: PointerEvent, widgetId: string) {
|
|
323
344
|
if (event.button !== 0 || draggingWidgetId || resizingWidgetId) return;
|
|
324
345
|
const target = event.target as HTMLElement | null;
|
|
@@ -327,6 +348,8 @@
|
|
|
327
348
|
event.stopPropagation();
|
|
328
349
|
onSelectShape?.(widgetId);
|
|
329
350
|
draggingWidgetId = widgetId;
|
|
351
|
+
// Where the cursor and the no-selection style go for this drag, and are taken from again when it ends.
|
|
352
|
+
const dragStyleTarget = getDragStyleTarget();
|
|
330
353
|
let lastX = event.clientX;
|
|
331
354
|
let lastY = event.clientY;
|
|
332
355
|
let pendingDx = 0;
|
|
@@ -359,15 +382,15 @@
|
|
|
359
382
|
document.removeEventListener('pointermove', onMove);
|
|
360
383
|
document.removeEventListener('pointerup', endDrag);
|
|
361
384
|
document.removeEventListener('pointercancel', endDrag);
|
|
362
|
-
|
|
363
|
-
|
|
385
|
+
dragStyleTarget.style.removeProperty('user-select');
|
|
386
|
+
dragStyleTarget.style.removeProperty('cursor');
|
|
364
387
|
onTranslateEnd?.(widgetId);
|
|
365
388
|
onOverlayDragChange?.(false);
|
|
366
389
|
console.log('[WidgetShapeLivePreviews] Drag end', widgetId.substring(0, 8));
|
|
367
390
|
}
|
|
368
391
|
|
|
369
|
-
|
|
370
|
-
|
|
392
|
+
dragStyleTarget.style.userSelect = 'none';
|
|
393
|
+
dragStyleTarget.style.cursor = 'grabbing';
|
|
371
394
|
onOverlayDragChange?.(true);
|
|
372
395
|
document.addEventListener('pointermove', onMove);
|
|
373
396
|
document.addEventListener('pointerup', endDrag);
|
|
@@ -580,7 +603,10 @@
|
|
|
580
603
|
function checkFocus() {
|
|
581
604
|
clearTimeout(focusTimer);
|
|
582
605
|
focusTimer = setTimeout(() => {
|
|
583
|
-
|
|
606
|
+
// The focused element of the tree the iframe is in: inside a shadow root `document.activeElement` is
|
|
607
|
+
// the shadow's host, never the iframe.
|
|
608
|
+
const focusRoot = iframe.getRootNode() as Document | ShadowRoot;
|
|
609
|
+
if (focusRoot.activeElement === iframe) select();
|
|
584
610
|
}, 0);
|
|
585
611
|
}
|
|
586
612
|
window.addEventListener('pointerdown', onWindowPointerDown, true);
|
|
@@ -603,11 +629,41 @@
|
|
|
603
629
|
|
|
604
630
|
function handleDocumentPointerDown(event: PointerEvent) {
|
|
605
631
|
if (!openVersionMenuWidgetId) return;
|
|
606
|
-
|
|
632
|
+
// Where the press really started: seen from the document, an event that began in a shadow root has the shadow's
|
|
633
|
+
// host as its target, which is never inside the menu (the menu then closed under the visitor's click).
|
|
634
|
+
const origin = event.composedPath()[0];
|
|
635
|
+
const target = (origin instanceof Element ? origin : event.target) as HTMLElement | null;
|
|
607
636
|
if (target?.closest?.(`[data-version-menu-for="${openVersionMenuWidgetId}"]`)) return;
|
|
608
637
|
openVersionMenuWidgetId = null;
|
|
609
638
|
}
|
|
610
639
|
|
|
640
|
+
/**
|
|
641
|
+
* The element the previews are drawn into: the creator's layer for floating panels.
|
|
642
|
+
*
|
|
643
|
+
* Looked up in the tree this component lives in. Where the creator owns its page that is the document, as it always
|
|
644
|
+
* was. In a partner's page the creator is inside a shadow root, which `document` cannot see into: the old lookup
|
|
645
|
+
* found nothing there, so no preview was ever drawn, or found an element of the partner's page that happens to carry
|
|
646
|
+
* the same class name and drew the creator's previews into the partner's page.
|
|
647
|
+
*/
|
|
648
|
+
function findPortalHost(): HTMLElement | null {
|
|
649
|
+
const layerName = portalTarget.replace(/^#/, '');
|
|
650
|
+
if (!layerName) return null;
|
|
651
|
+
// The creator's own layer is the nearest one around this component (an ancestor never leaves the shadow root).
|
|
652
|
+
for (let ancestor = layerAnchor?.parentElement ?? null; ancestor; ancestor = ancestor.parentElement) {
|
|
653
|
+
if (ancestor.classList.contains(layerName) || ancestor.id === layerName) return ancestor;
|
|
654
|
+
}
|
|
655
|
+
// Not around it: look in the tree it is in, and never past the shadow root it may be in.
|
|
656
|
+
const treeRoot = layerAnchor?.getRootNode();
|
|
657
|
+
const searchRoot: Document | ShadowRoot = treeRoot instanceof ShadowRoot ? treeRoot : document;
|
|
658
|
+
try {
|
|
659
|
+
const found = searchRoot.querySelector(`.${layerName}`) ?? searchRoot.getElementById(layerName);
|
|
660
|
+
return found instanceof HTMLElement ? found : null;
|
|
661
|
+
} catch (error) {
|
|
662
|
+
console.warn('[WidgetShapeLivePreviews] Could not look the preview layer up', layerName, error);
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
611
667
|
function handleDocumentKeydown(event: KeyboardEvent) {
|
|
612
668
|
if (event.key === 'Escape' && openVersionMenuWidgetId) {
|
|
613
669
|
openVersionMenuWidgetId = null;
|
|
@@ -615,9 +671,7 @@
|
|
|
615
671
|
}
|
|
616
672
|
|
|
617
673
|
onMount(() => {
|
|
618
|
-
|
|
619
|
-
|| document.getElementById(portalTarget.replace(/^#/, ''));
|
|
620
|
-
portalHost = existingHost instanceof HTMLElement ? existingHost : null;
|
|
674
|
+
portalHost = findPortalHost();
|
|
621
675
|
// A child-only HMR remount does not trigger Fabric after:render. Bootstrap
|
|
622
676
|
// once after parent bindings/layout settle; subsequent updates stay event-driven.
|
|
623
677
|
const initialSyncFrame = requestAnimationFrame(() => {
|
|
@@ -644,9 +698,14 @@
|
|
|
644
698
|
});
|
|
645
699
|
</script>
|
|
646
700
|
|
|
701
|
+
<!-- Takes no room and shows nothing: it only tells onMount which tree (document or shadow root) this component is in. -->
|
|
702
|
+
<span bind:this={layerAnchor} class="widget-shape-live-previews-anchor" style="display: none;" aria-hidden="true"></span>
|
|
703
|
+
|
|
647
704
|
{#if enabled && overlays.length > 0 && portalHost}
|
|
648
705
|
<Portal target={portalHost} class="widget-shape-units-portal" style="display: contents;">
|
|
649
|
-
|
|
706
|
+
<!-- The live previews stay left to right on a right to left screen, with the board they are laid over: each is put in pixels
|
|
707
|
+
from the left edge of the board and its bar, its title and its version list are drawn the way they are on the preview. -->
|
|
708
|
+
<div class="widget-shape-live-previews-ct pointer-events-none {className}" dir="ltr" {style}>
|
|
650
709
|
{#each overlays as overlay (overlay.widgetId)}
|
|
651
710
|
{@const isSelected = selectedWidgetId === overlay.widgetId}
|
|
652
711
|
{@const isDragging = draggingWidgetId === overlay.widgetId}
|
|
@@ -691,21 +750,21 @@
|
|
|
691
750
|
class="widget-shape-live-chrome-ct fixed pointer-events-none"
|
|
692
751
|
data-widget-id={overlay.widgetId}
|
|
693
752
|
class:opacity-0={!chromeVisible}
|
|
694
|
-
style="left: {overlay.left}px; top: {chromeTop}px; width: {chromeWidth}px; height: {DRAG_BAR_H}px; z-index: {chromeZIndex}; pointer-events: none; transition: opacity 120ms ease;"
|
|
753
|
+
style="left: {overlay.left}px; /* rtl-ok: laid over the preview, where it is on the screen */ top: {chromeTop}px; width: {chromeWidth}px; height: {DRAG_BAR_H}px; z-index: {chromeZIndex}; pointer-events: none; transition: opacity 120ms ease;"
|
|
695
754
|
>
|
|
696
755
|
<!-- Attached horizontal chrome wins hits where its own rotation stem overlaps. -->
|
|
697
756
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
698
757
|
<div
|
|
699
|
-
class="widget-shape-drag-bar pointer-events-auto absolute
|
|
758
|
+
class="widget-shape-drag-bar pointer-events-auto absolute start-0 end-0 top-0 z-10 flex items-center gap-1 rounded-t-md border border-b-0 px-1.5 shadow-sm select-none [&_button:focus]:outline-none [&_button:focus]:shadow-none [&_button:focus-visible]:outline-none [&_button:focus-visible]:shadow-none
|
|
700
759
|
{isPrimary ? 'bg-red-100' : 'bg-white'} {isSelected ? 'border-blue-400' : 'border-gray-300'}"
|
|
701
760
|
style="height: {DRAG_BAR_H}px; cursor: grab; min-width: {showExpandedChrome ? MIN_EXPANDED_CHROME_WIDTH : 0}px;"
|
|
702
|
-
title=
|
|
761
|
+
title={$t('creator.livePreviews.dragWidget')}
|
|
703
762
|
onpointerdown={(e) => startShapeDrag(e, overlay.widgetId)}
|
|
704
763
|
>
|
|
705
764
|
{#if isPrimary}
|
|
706
765
|
<div
|
|
707
766
|
class="widget-shape-primary-stroke pointer-events-none absolute z-20 bg-[#DC2626]"
|
|
708
|
-
style="left: 0; width: {overlay.width}px; top: {DRAG_BAR_H - IFRAME_INSET_PX - 1}px; height: 2px;"
|
|
767
|
+
style="left: 0; /* rtl-ok: the line under the bar starts at the left edge of the preview */ width: {overlay.width}px; top: {DRAG_BAR_H - IFRAME_INSET_PX - 1}px; height: 2px;"
|
|
709
768
|
></div>
|
|
710
769
|
{/if}
|
|
711
770
|
<span class="widget-shape-drag-grip shrink-0 text-xs leading-none text-gray-400" aria-hidden="true">⠿</span>
|
|
@@ -716,11 +775,11 @@
|
|
|
716
775
|
title={titleText}
|
|
717
776
|
>{titleText}</span>
|
|
718
777
|
|
|
719
|
-
<HoverTooltip text={isPrimary ? '
|
|
778
|
+
<HoverTooltip text={isPrimary ? $t('creator.livePreviews.primaryWidget') : $t('creator.livePreviews.setPrimary')} class="inline-flex shrink-0">
|
|
720
779
|
<button
|
|
721
780
|
type="button"
|
|
722
781
|
class="widget-shape-set-primary-btn flex h-6 w-6 shrink-0 items-center justify-center rounded text-red-700 enabled:hover:bg-red-200 enabled:hover:text-red-800 disabled:text-red-700/40 disabled:pointer-events-none disabled:cursor-default cursor-pointer"
|
|
723
|
-
aria-label={isPrimary ? '
|
|
782
|
+
aria-label={isPrimary ? $t('creator.livePreviews.primaryWidget') : $t('creator.livePreviews.setPrimary')}
|
|
724
783
|
disabled={isPrimary || !onSetPrimary}
|
|
725
784
|
onpointerdown={(event) => event.stopPropagation()}
|
|
726
785
|
onclick={(event) => { event.stopPropagation(); onSetPrimary?.(overlay.widgetId); }}
|
|
@@ -732,7 +791,7 @@
|
|
|
732
791
|
data-version-menu-for={overlay.widgetId}
|
|
733
792
|
>
|
|
734
793
|
<HoverTooltip
|
|
735
|
-
text=
|
|
794
|
+
text={$t('creator.common.switchVersion')}
|
|
736
795
|
maxWidth={120}
|
|
737
796
|
class="inline-flex shrink-0"
|
|
738
797
|
>
|
|
@@ -750,7 +809,7 @@
|
|
|
750
809
|
</HoverTooltip>
|
|
751
810
|
{#if canPublish && !selectedVersion}
|
|
752
811
|
<HoverTooltip
|
|
753
|
-
text=
|
|
812
|
+
text={$t('creator.livePreviews.publishLatest')}
|
|
754
813
|
maxWidth={120}
|
|
755
814
|
class="inline-flex shrink-0"
|
|
756
815
|
>
|
|
@@ -763,21 +822,21 @@
|
|
|
763
822
|
onPublish?.(overlay.widgetId);
|
|
764
823
|
}}
|
|
765
824
|
onpointerdown={(e) => e.stopPropagation()}
|
|
766
|
-
>{isPublishing ? '...' : '
|
|
825
|
+
>{isPublishing ? '...' : $t('creator.common.publish')}</button>
|
|
767
826
|
</HoverTooltip>
|
|
768
827
|
{:else if selectedVersion?.isLive}
|
|
769
828
|
<HoverTooltip
|
|
770
|
-
text=
|
|
829
|
+
text={$t('creator.livePreviews.currentlyLive')}
|
|
771
830
|
maxWidth={120}
|
|
772
831
|
class="inline-flex shrink-0"
|
|
773
832
|
>
|
|
774
833
|
<span
|
|
775
834
|
class="widget-shape-live-btn shrink-0 inline-flex items-center justify-center min-w-[4.75rem] w-[4.75rem] rounded bg-emerald-100 px-1 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-emerald-600 opacity-80"
|
|
776
|
-
>
|
|
835
|
+
>{$t('creator.common.live')}</span>
|
|
777
836
|
</HoverTooltip>
|
|
778
837
|
{:else if selectedVersion && onSetLive && !isDraftVersion(selectedVersion)}
|
|
779
838
|
<HoverTooltip
|
|
780
|
-
text=
|
|
839
|
+
text={$t('creator.livePreviews.makeThisVersionLive')}
|
|
781
840
|
maxWidth={130}
|
|
782
841
|
class="inline-flex shrink-0"
|
|
783
842
|
>
|
|
@@ -787,12 +846,12 @@
|
|
|
787
846
|
disabled={settingLiveVersion === Number(selectedVersion.id.slice(2))}
|
|
788
847
|
onclick={(e) => handleSetLiveClick(e, overlay.widgetId, selectedVersion.id)}
|
|
789
848
|
onpointerdown={(e) => e.stopPropagation()}
|
|
790
|
-
>{settingLiveVersion === Number(selectedVersion.id.slice(2)) ? '...' : '
|
|
849
|
+
>{settingLiveVersion === Number(selectedVersion.id.slice(2)) ? '...' : $t('creator.common.setLive')}</button>
|
|
791
850
|
</HoverTooltip>
|
|
792
851
|
{:else if selectedVersion && isDraftVersion(selectedVersion)}
|
|
793
852
|
{#if onPublishDraft}
|
|
794
853
|
<HoverTooltip
|
|
795
|
-
text=
|
|
854
|
+
text={$t('creator.livePreviews.publishThisDraft')}
|
|
796
855
|
maxWidth={130}
|
|
797
856
|
class="inline-flex shrink-0"
|
|
798
857
|
>
|
|
@@ -802,17 +861,17 @@
|
|
|
802
861
|
disabled={isPublishing || selectedPreviewBlocked || !resolveCanPublishDraft?.(overlay.widgetId, Number(selectedVersion.id.slice(2))) || !!resolvePublishDisabled?.(overlay.widgetId, Number(selectedVersion.id.slice(2)))}
|
|
803
862
|
onclick={(e) => handlePublishDraftClick(e, overlay.widgetId, selectedVersion.id)}
|
|
804
863
|
onpointerdown={(e) => e.stopPropagation()}
|
|
805
|
-
>{isPublishing ? '...' : '
|
|
864
|
+
>{isPublishing ? '...' : $t('creator.common.publish')}</button>
|
|
806
865
|
</HoverTooltip>
|
|
807
866
|
{:else}
|
|
808
867
|
<HoverTooltip
|
|
809
|
-
text=
|
|
868
|
+
text={$t('creator.livePreviews.noCommitToPublish')}
|
|
810
869
|
maxWidth={130}
|
|
811
870
|
class="inline-flex shrink-0"
|
|
812
871
|
>
|
|
813
872
|
<span
|
|
814
873
|
class="widget-shape-draft-badge shrink-0 inline-flex items-center justify-center min-w-[4.75rem] w-[4.75rem] rounded bg-amber-100 px-1 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-amber-700"
|
|
815
|
-
>
|
|
874
|
+
>{$t('creator.common.draft')}</span>
|
|
816
875
|
</HoverTooltip>
|
|
817
876
|
{/if}
|
|
818
877
|
{/if}
|
|
@@ -820,21 +879,21 @@
|
|
|
820
879
|
{:else if versionTriggerText && versionTriggerText !== '—'}
|
|
821
880
|
<span
|
|
822
881
|
class="widget-shape-version-label shrink-0 rounded bg-gray-100 px-1.5 py-0.5 text-[10px] font-medium text-gray-500"
|
|
823
|
-
title=
|
|
882
|
+
title={$t('creator.livePreviews.currentVersion')}
|
|
824
883
|
>{versionTriggerText}</span>
|
|
825
884
|
{/if}
|
|
826
885
|
{:else if isSelected}
|
|
827
886
|
<span
|
|
828
887
|
class="widget-shape-edit-mode-badge shrink-0 rounded-full bg-amber-200 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-amber-900"
|
|
829
|
-
>
|
|
888
|
+
>{$t('creator.livePreviews.editMode')}</span>
|
|
830
889
|
{/if}
|
|
831
890
|
|
|
832
|
-
<div class="widget-shape-drag-bar-actions
|
|
833
|
-
<HoverTooltip text=
|
|
891
|
+
<div class="widget-shape-drag-bar-actions ms-auto flex shrink-0 items-center gap-0.5">
|
|
892
|
+
<HoverTooltip text={$t('creator.livePreviews.refreshPreview')} class="inline-flex shrink-0">
|
|
834
893
|
<button
|
|
835
894
|
type="button"
|
|
836
895
|
class="widget-shape-refresh-btn flex h-6 w-6 items-center justify-center rounded text-gray-500 hover:bg-gray-100 hover:text-forest-green cursor-pointer"
|
|
837
|
-
aria-label=
|
|
896
|
+
aria-label={$t('creator.livePreviews.refreshPreview')}
|
|
838
897
|
onclick={(e) => handleRefreshClick(e, overlay.widgetId)}
|
|
839
898
|
onpointerdown={(e) => e.stopPropagation()}
|
|
840
899
|
>
|
|
@@ -842,14 +901,14 @@
|
|
|
842
901
|
<polyline points="23 4 23 10 17 10"/>
|
|
843
902
|
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
|
|
844
903
|
</svg>
|
|
845
|
-
<span class="sr-only">
|
|
904
|
+
<span class="sr-only">{$t('creator.livePreviews.refresh')}</span>
|
|
846
905
|
</button>
|
|
847
906
|
</HoverTooltip>
|
|
848
|
-
<HoverTooltip text=
|
|
907
|
+
<HoverTooltip text={$t('creator.livePreviews.openChat')} maxWidth={100} class="inline-flex shrink-0">
|
|
849
908
|
<button
|
|
850
909
|
type="button"
|
|
851
910
|
class="widget-shape-open-chat-btn flex h-6 w-6 items-center justify-center rounded text-gray-500 hover:bg-gray-100 hover:text-forest-green cursor-pointer"
|
|
852
|
-
aria-label=
|
|
911
|
+
aria-label={$t('creator.livePreviews.openChat')}
|
|
853
912
|
onclick={(e) => handleOpenChat(e, overlay.widgetId)}
|
|
854
913
|
onpointerdown={(e) => e.stopPropagation()}
|
|
855
914
|
>
|
|
@@ -865,7 +924,7 @@
|
|
|
865
924
|
>
|
|
866
925
|
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
867
926
|
</svg>
|
|
868
|
-
<span class="sr-only">
|
|
927
|
+
<span class="sr-only">{$t('creator.livePreviews.chat')}</span>
|
|
869
928
|
</button>
|
|
870
929
|
</HoverTooltip>
|
|
871
930
|
</div>
|
|
@@ -873,8 +932,8 @@
|
|
|
873
932
|
|
|
874
933
|
</div>
|
|
875
934
|
|
|
876
|
-
|
|
877
|
-
|
|
935
|
+
<!-- rtl-ok: the frame sits at the top left corner of the screen and is moved and turned by its matrix -->
|
|
936
|
+
<div class="widget-shape-live-preview-frame pointer-events-none fixed left-0 top-0 origin-top-left overflow-visible"
|
|
878
937
|
data-widget-id={overlay.widgetId}
|
|
879
938
|
style="height: {frameHeight}px; width: {frameWidth}px; transform: matrix({frameCos}, {frameSin}, {-frameSin}, {frameCos}, {bodyMatrix[4]}, {bodyMatrix[5]}); z-index: {isSelected ? 60 : 1};"
|
|
880
939
|
>
|
|
@@ -888,8 +947,8 @@
|
|
|
888
947
|
class="widget-shape-live-preview-iframe pointer-events-auto absolute border-0 bg-white"
|
|
889
948
|
class:pointer-events-none={blockIframePointer || selectedPreviewBlocked}
|
|
890
949
|
class:opacity-0={selectedPreviewBlocked}
|
|
891
|
-
style="left: {IFRAME_INSET_PX}px; top: {IFRAME_INSET_PX}px; right: {IFRAME_INSET_PX}px; bottom: {IFRAME_INSET_PX}px; width: calc(100% - {IFRAME_INSET_PX * 2}px); height: calc(100% - {IFRAME_INSET_PX * 2}px);"
|
|
892
|
-
title=
|
|
950
|
+
style="left: {IFRAME_INSET_PX}px; top: {IFRAME_INSET_PX}px; right: {IFRAME_INSET_PX}px; /* rtl-ok: the same inset on both sides of the frame */ bottom: {IFRAME_INSET_PX}px; width: calc(100% - {IFRAME_INSET_PX * 2}px); height: calc(100% - {IFRAME_INSET_PX * 2}px);"
|
|
951
|
+
title={$t('creator.livePreviews.liveWidgetPreview')}
|
|
893
952
|
src={buildIframeSrc(overlay.src, overlay.widgetId)}
|
|
894
953
|
data-widget-id={overlay.widgetId}
|
|
895
954
|
tabindex="-1"
|
|
@@ -902,11 +961,11 @@
|
|
|
902
961
|
{/if}
|
|
903
962
|
{#if previewState?.error && !previewState.loading}
|
|
904
963
|
<div class="widget-shape-preview-error pointer-events-auto absolute inset-0 flex flex-col items-center justify-center gap-2 overflow-auto bg-white p-4 text-center text-xs text-red-600 [scrollbar-color:rgba(0,0,0,0.2)_transparent]" role="alert">
|
|
905
|
-
<span>{previewState.error}</span>
|
|
964
|
+
<span>{errorLabel(previewState.error, $t)}</span>
|
|
906
965
|
{#if onRetryPreview}
|
|
907
966
|
<button type="button" class="widget-shape-preview-retry pointer-events-auto cursor-pointer rounded border border-gray-300 bg-white px-3 py-1.5 text-gray-700 hover:bg-gray-100 focus:outline-none focus-visible:outline-none focus-visible:bg-gray-100"
|
|
908
967
|
onpointerdown={(event) => event.stopPropagation()}
|
|
909
|
-
onclick={(event) => { event.stopPropagation(); onRetryPreview?.(overlay.widgetId); }}>
|
|
968
|
+
onclick={(event) => { event.stopPropagation(); onRetryPreview?.(overlay.widgetId); }}>{$t('creator.common.retry')}</button>
|
|
910
969
|
{/if}
|
|
911
970
|
</div>
|
|
912
971
|
{:else if selectedPreviewBlocked}
|
|
@@ -916,7 +975,7 @@
|
|
|
916
975
|
aria-live="polite"
|
|
917
976
|
>
|
|
918
977
|
<div class="widget-shape-preview-spinner h-6 w-6 animate-spin rounded-full border-2 border-gray-300 border-t-emerald-600" aria-hidden="true"></div>
|
|
919
|
-
<span class="widget-shape-preview-loading-label text-xs text-gray-600">{previewState?.loading ? '
|
|
978
|
+
<span class="widget-shape-preview-loading-label text-xs text-gray-600">{previewState?.loading ? $t('creator.livePreviews.building') : $t('creator.common.loading')}</span>
|
|
920
979
|
</div>
|
|
921
980
|
{/if}
|
|
922
981
|
{#if blockIframePointer}
|
|
@@ -932,12 +991,12 @@
|
|
|
932
991
|
<div
|
|
933
992
|
class="widget-shape-version-menu pointer-events-auto fixed z-[400] w-max rounded-md border border-emerald-200 bg-white p-1 shadow-lg"
|
|
934
993
|
data-version-menu-for={overlay.widgetId}
|
|
935
|
-
style="top: {versionMenuBox.top}px; right: {versionMenuBox.right}px;"
|
|
994
|
+
style="top: {versionMenuBox.top}px; right: {versionMenuBox.right}px; /* rtl-ok: lined up with the right edge of the version button on the preview's bar, which is a left to right island */"
|
|
936
995
|
role="listbox"
|
|
937
996
|
>
|
|
938
997
|
<div
|
|
939
998
|
class="widget-shape-version-scroll flex flex-col gap-1 overflow-x-hidden {hasScroll ? 'overflow-y-auto' : 'overflow-y-visible'}"
|
|
940
|
-
style="{hasScroll ? 'max-height: 185px; margin-
|
|
999
|
+
style="{hasScroll ? 'max-height: 185px; margin-inline-end: -4px; padding-inline-end: 4px;' : 'max-height: none;'} scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.2) transparent;"
|
|
941
1000
|
>
|
|
942
1001
|
{#each versionOptions as option (option.id)}
|
|
943
1002
|
{@const optionVersion = Number(option.id.slice(2))}
|
|
@@ -954,7 +1013,7 @@
|
|
|
954
1013
|
selected={selectedVersion?.id === option.id}
|
|
955
1014
|
busy={optionBusy}
|
|
956
1015
|
publishDisabled={optionPublishDisabled}
|
|
957
|
-
publishDisabledReason={optionPublishReason || '
|
|
1016
|
+
publishDisabledReason={optionPublishReason || $t('creator.common.buildThisDraftVersionAnd')}
|
|
958
1017
|
setLiveDisabled={settingLiveVersion === optionVersion}
|
|
959
1018
|
onselect={() => selectVersionFromMenu(overlay.widgetId, option.id)}
|
|
960
1019
|
onpublish={() => handlePublishDraftClickFromMenu(overlay.widgetId, option.id)}
|
package/dist/creator-types.d.ts
CHANGED
|
@@ -1,4 +1,100 @@
|
|
|
1
|
+
import type { MediaLibraryProvider } from '@widgetic/file-browser';
|
|
2
|
+
import type { TextDirection } from '@widgetic/design-system/components/textDirection';
|
|
3
|
+
/** Why the creator asks the page for a token. */
|
|
4
|
+
export type CreatorTokenReason =
|
|
5
|
+
/** It wants the token to use now (the page keeps it fresh), or is starting. */
|
|
6
|
+
'initial'
|
|
7
|
+
/** The API has just refused the token it used (`refusedToken`): it wants a replacement. */
|
|
8
|
+
| 'expired';
|
|
1
9
|
export interface CreatorAppProps {
|
|
10
|
+
/**
|
|
11
|
+
* Hands the creator the token it calls the API with: an editor session token, which lets one managed user work on
|
|
12
|
+
* their own canvases and widgets and nothing else. Giving this function puts the creator in **partner mode**:
|
|
13
|
+
*
|
|
14
|
+
* - it takes its sign-in only from here, never from the browser's storage (the site's `session`, `jwt`, `user`);
|
|
15
|
+
* - it keeps what it remembers in memory, so nothing is written to the page's origin and the next visitor of the
|
|
16
|
+
* same browser sees nothing of the last one;
|
|
17
|
+
* - it leaves the page's address bar alone, never reloads or navigates the page, and tells the page instead
|
|
18
|
+
* (`onReloadRequested`, `onSessionEnded`, `onLimitReached`);
|
|
19
|
+
* - it opens no realtime socket (generation reaches it through the operations stream), asks for no account billing
|
|
20
|
+
* and shows no sign-in screen or trial counter.
|
|
21
|
+
*
|
|
22
|
+
* Called with `'initial'` whenever the creator wants the token to use (cheap: the page returns the one it holds and
|
|
23
|
+
* keeps it fresh), and with `'expired'` plus the refused token when the API turned the token down.
|
|
24
|
+
*/
|
|
25
|
+
getAccessToken?: (reason: CreatorTokenReason, refusedToken?: string) => Promise<string> | string;
|
|
26
|
+
/** Partner mode: the session cannot go on and the creator cannot get another from `getAccessToken`. */
|
|
27
|
+
onSessionEnded?: (detail: {
|
|
28
|
+
message: string;
|
|
29
|
+
code?: string;
|
|
30
|
+
}) => void;
|
|
31
|
+
/** Partner mode: the creator would reload the page to recover; the page decides how to start over. */
|
|
32
|
+
onReloadRequested?: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Partner mode: the visitor ran into a limit (credits used up, a cap reached, the storage full). The creator tells the
|
|
35
|
+
* page by itself when the API refuses a request because of a limit, and the visitor sees a plain sentence on the
|
|
36
|
+
* creator's own screen. `message` is a sentence that names no limit (the page knows what its limits are); `code` is
|
|
37
|
+
* what the API said: `BILLING_INSUFFICIENT_CREDITS`, `AUTHZ_PLAN_RESTRICTION`, `QUOTA_STORAGE_EXCEEDED` or
|
|
38
|
+
* `COST_LIMIT_EXCEEDED`, or `LIMIT_REACHED` when the visitor pressed an "Upgrade" button. A page is told once per
|
|
39
|
+
* code in half a minute. Ordinary rate limiting is not a limit and is not reported: the creator asks the visitor to
|
|
40
|
+
* wait. The creator never opens a window or an address for an "upgrade"; the page decides what that means.
|
|
41
|
+
*/
|
|
42
|
+
onLimitReached?: (detail: {
|
|
43
|
+
message: string;
|
|
44
|
+
code?: string;
|
|
45
|
+
}) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Partner mode: the canvas the page named (`canvasId`) cannot be opened by this visitor: the API answers as if it did
|
|
48
|
+
* not exist (it is not theirs, or it is gone). The creator says so on its own screen, stops asking for the canvas,
|
|
49
|
+
* and does not report itself ready; the page decides what to open instead (usually by mounting the creator again
|
|
50
|
+
* without a `canvasId`).
|
|
51
|
+
*/
|
|
52
|
+
onCanvasUnavailable?: (detail: {
|
|
53
|
+
canvasId: string | null;
|
|
54
|
+
message: string;
|
|
55
|
+
code?: string;
|
|
56
|
+
}) => void;
|
|
57
|
+
/**
|
|
58
|
+
* The canvas the creator has open changed (it opened one, or made a new one). A partner's page keeps this id and
|
|
59
|
+
* gives it back as `canvasId` the next time, since the creator leaves the address bar and the storage alone.
|
|
60
|
+
*/
|
|
61
|
+
onCanvasChanged?: (detail: {
|
|
62
|
+
canvasId: string;
|
|
63
|
+
}) => void;
|
|
64
|
+
/**
|
|
65
|
+
* The first canvas has loaded and the creator is ready to be used. Called once; `canvasId` is the canvas that is
|
|
66
|
+
* open then (`null` when the visitor starts from nothing and none exists yet).
|
|
67
|
+
*/
|
|
68
|
+
onReady?: (detail: {
|
|
69
|
+
canvasId: string | null;
|
|
70
|
+
}) => void;
|
|
71
|
+
/**
|
|
72
|
+
* The page's own media library for the file pickers of the editor (the image, video and file settings of a widget):
|
|
73
|
+
* their files are listed, uploaded, renamed and deleted through these functions instead of the visitor's Widgetic
|
|
74
|
+
* uploads. Dropping an image on the canvas and the chat's attachments are not covered: they keep using Widgetic's
|
|
75
|
+
* storage.
|
|
76
|
+
*/
|
|
77
|
+
mediaLibrary?: MediaLibraryProvider;
|
|
78
|
+
/**
|
|
79
|
+
* The language of the creator: a BCP 47 tag (`"de"`, `"pt-BR"`) that sets the plural rules and how numbers, dates and
|
|
80
|
+
* lists are written. English when left out or when this browser does not know the tag. Set again while the creator
|
|
81
|
+
* is open, the words on the screen change.
|
|
82
|
+
*/
|
|
83
|
+
locale?: string | null;
|
|
84
|
+
/**
|
|
85
|
+
* The page's own words, as ONE flat object: any key of `ALL_CREATOR_MESSAGES` (the creator's own words and those of the
|
|
86
|
+
* editor, the File Browser, the chat and the canvas it draws) with the text to show instead. A key the page leaves out
|
|
87
|
+
* keeps its English text. A message is a sentence with places for values (`{name}`) and plurals
|
|
88
|
+
* (`{count, plural, one {# file} other {# files}}`). `checkCreatorMessages(messages)` says what in it would not be used.
|
|
89
|
+
*/
|
|
90
|
+
messages?: Readonly<Record<string, unknown>> | null;
|
|
91
|
+
/**
|
|
92
|
+
* The direction of the creator's screen: `"rtl"` turns everything around (panels, toolbars, menus, dialogs, the chat and the
|
|
93
|
+
* editor), `"ltr"` keeps it as it is. Left out, the creator takes the direction of the screen it stands in (the `dir` of a
|
|
94
|
+
* creator or another part of the design system above it) and is left to right when nothing above it says. The canvas board,
|
|
95
|
+
* the live previews of the widgets and code stay left to right either way. A module sets it from `locale`.
|
|
96
|
+
*/
|
|
97
|
+
dir?: TextDirection;
|
|
2
98
|
canvasId?: string | null;
|
|
3
99
|
projectId?: string | null;
|
|
4
100
|
workspaceType?: 'personal' | 'organization';
|