@widgetic/editor 4.1.16 → 4.1.18
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/PreviewChromeControls.svelte +2 -2
- package/dist/components/WidgetPreview.svelte +2 -2
- package/dist/components/editors/EmbedEditor.svelte +2 -1
- package/dist/components/editors/PropsEditor.svelte +127 -28
- package/dist/components/ic/AngleInputController.svelte +10 -6
- package/dist/components/ic/BrowserInputController.svelte +25 -112
- package/dist/components/ic/ColorPickerInputController.svelte +120 -48
- package/dist/components/ic/DatePickerInputController.svelte +18 -10
- package/dist/components/ic/DropdownInputController.svelte +2 -12
- package/dist/components/ic/FixedPositionInputController.svelte +1 -1
- package/dist/components/ic/FontInputController.svelte +42 -55
- package/dist/components/ic/InputControllerHeader.svelte +1 -1
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte +7 -7
- package/dist/components/ic/NumberControls.svelte +92 -43
- package/dist/components/ic/NumberControls.svelte.d.ts +5 -1
- package/dist/components/ic/PositionInputController.svelte +24 -15
- package/dist/components/ic/RangeCalendarInputController.svelte +38 -18
- package/dist/components/ic/RoundedCornersInputController.svelte +2 -2
- package/dist/components/ic/SliderInputController.svelte +11 -4
- package/dist/components/ic/TextAreaInputController.svelte +40 -27
- package/dist/components/ic/TextAreaPreviewInputController.svelte +9 -8
- package/dist/components/ic/TextInputController.svelte +15 -2
- package/dist/components/ic/TimeInputController.svelte +1 -1
- package/dist/components/ic/VectorInputController.svelte +155 -27
- package/dist/components/ic/numberControlsSteps.d.ts +17 -0
- package/dist/components/ic/numberControlsSteps.js +23 -0
- package/dist/components/ic/shared/DropdownChevron.svelte +23 -0
- package/dist/components/ic/shared/DropdownChevron.svelte.d.ts +9 -0
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +132 -0
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +27 -0
- package/dist/components/ic/shared/ItemGrid.svelte +2 -2
- package/dist/components/ic/shared/RecentItemsSection.svelte +6 -6
- package/dist/components/ic/shared/editableFieldClasses.d.ts +15 -0
- package/dist/components/ic/shared/editableFieldClasses.js +15 -0
- package/dist/components/ic/shared/index.d.ts +1 -0
- package/dist/components/ic/shared/index.js +1 -0
- package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +41 -9
- package/dist/i18n/language.d.ts +260 -2
- package/dist/utils/angleMath.d.ts +2 -0
- package/dist/utils/angleMath.js +6 -0
- package/package.json +4 -4
|
@@ -54,12 +54,11 @@
|
|
|
54
54
|
IconButton
|
|
55
55
|
} from '@widgetic/design-system/components';
|
|
56
56
|
import {
|
|
57
|
-
IconArrowsDiagonalMinimize,
|
|
58
57
|
IconBold,
|
|
59
58
|
IconBrush,
|
|
60
59
|
IconCheck,
|
|
61
|
-
IconChevronDown,
|
|
62
60
|
IconChevronUp,
|
|
61
|
+
IconX,
|
|
63
62
|
IconH1,
|
|
64
63
|
IconH2,
|
|
65
64
|
IconH3,
|
|
@@ -85,6 +84,7 @@
|
|
|
85
84
|
|
|
86
85
|
// Add local ColorPickerInputController import
|
|
87
86
|
import ColorPickerInputController from './ColorPickerInputController.svelte';
|
|
87
|
+
import DropdownChevron from './shared/DropdownChevron.svelte';
|
|
88
88
|
|
|
89
89
|
// Looking things up and listening for scrolling in the tree the editor is in (a module has a shadow root)
|
|
90
90
|
import {
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
{ value: 'h3', messageKey: 'editor.textArea.heading3', icon: IconH3 }
|
|
167
167
|
];
|
|
168
168
|
|
|
169
|
-
const toolbarIconClass = 'size-4 shrink-0 stroke-
|
|
169
|
+
const toolbarIconClass = 'size-4 shrink-0 stroke-2';
|
|
170
170
|
|
|
171
171
|
/** The message of the style the toolbar button shows: the plain text's when the style is none of the options. */
|
|
172
172
|
let currentTextStyleMessageKey = $derived<EditorMessageKey>(
|
|
@@ -199,6 +199,20 @@
|
|
|
199
199
|
// Add these variables to track focus state
|
|
200
200
|
let editorHasFocus = $state(false);
|
|
201
201
|
let toolbarRef: HTMLDivElement;
|
|
202
|
+
let richTextPortalTarget: HTMLElement | null = $state(null);
|
|
203
|
+
|
|
204
|
+
function resolveRichTextPortalTarget(): HTMLElement | undefined {
|
|
205
|
+
const portalHost = queryInTreeOf(toolbarRef, '.text-area-portal');
|
|
206
|
+
if (portalHost instanceof HTMLElement) return portalHost;
|
|
207
|
+
if (typeof document !== 'undefined') {
|
|
208
|
+
return document.getElementById('editor-portal') ?? document.body;
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const toolbarPopoverPortalProps = $derived({
|
|
214
|
+
to: richTextPortalTarget ?? resolveRichTextPortalTarget() ?? undefined
|
|
215
|
+
});
|
|
202
216
|
|
|
203
217
|
// Static styles — avoid $derived so teardown does not leave inert derived reads.
|
|
204
218
|
const editorStyle = `
|
|
@@ -905,8 +919,10 @@
|
|
|
905
919
|
|
|
906
920
|
// If clicking toolbar elements or color picker, maintain expanded state
|
|
907
921
|
if (
|
|
908
|
-
target.matches('input, button, [role="button"], [tabindex="0"]') ||
|
|
909
|
-
target.closest(
|
|
922
|
+
target.matches('input, button, [role="button"], [role="combobox"], [tabindex="0"]') ||
|
|
923
|
+
target.closest(
|
|
924
|
+
'.color-picker-container, [data-radix-popper-content-wrapper], [data-state="open"]'
|
|
925
|
+
)
|
|
910
926
|
) {
|
|
911
927
|
// Keep toolbar enabled since we're interacting with it
|
|
912
928
|
editorHasFocus = true;
|
|
@@ -1060,6 +1076,7 @@
|
|
|
1060
1076
|
let stopListeningForScroll: () => void = () => {};
|
|
1061
1077
|
|
|
1062
1078
|
onMount(() => {
|
|
1079
|
+
richTextPortalTarget = resolveRichTextPortalTarget() ?? null;
|
|
1063
1080
|
stopListeningForScroll = listenForScroll(toolbarRef, handleScroll);
|
|
1064
1081
|
});
|
|
1065
1082
|
|
|
@@ -1086,8 +1103,10 @@
|
|
|
1086
1103
|
if (editorInstance) {
|
|
1087
1104
|
const target = e.target as HTMLElement;
|
|
1088
1105
|
const isInteractive =
|
|
1089
|
-
target.matches('button, input, [role="button"], [tabindex="0"]') ||
|
|
1090
|
-
target.closest(
|
|
1106
|
+
target.matches('button, input, [role="button"], [role="combobox"], [tabindex="0"]') ||
|
|
1107
|
+
target.closest(
|
|
1108
|
+
'button, input, [role="button"], [role="combobox"], [tabindex="0"], [data-radix-popper-content-wrapper]'
|
|
1109
|
+
);
|
|
1091
1110
|
|
|
1092
1111
|
if (!isInteractive) {
|
|
1093
1112
|
e.preventDefault();
|
|
@@ -1128,14 +1147,14 @@
|
|
|
1128
1147
|
|
|
1129
1148
|
<!-- Main editor container -->
|
|
1130
1149
|
<div
|
|
1131
|
-
class="main-editor-container group relative flex h-full w-full flex-col
|
|
1150
|
+
class="main-editor-container group relative flex h-full min-h-0 w-full flex-col overflow-hidden rounded-lg bg-accent px-4 pb-4 pt-4 [--editor-padding-top:0px]"
|
|
1132
1151
|
style={editorStyle}
|
|
1133
1152
|
on:mousedown={handleMouseDown}
|
|
1134
1153
|
>
|
|
1135
|
-
<!-- Toolbar at the top -->
|
|
1154
|
+
<!-- Toolbar at the top: the 36 row of buttons has 16 above it (the padding of the card) and 16 below it, then the line (1) and 16 of text space. -->
|
|
1136
1155
|
<div
|
|
1137
1156
|
bind:this={toolbarRef}
|
|
1138
|
-
class="toolbar-container sticky top-0 z-
|
|
1157
|
+
class="toolbar-container sticky top-0 z-20 mb-4 h-[calc(2.25rem+1rem+1px)] shrink-0 select-none overflow-visible border-b border-border bg-transparent pb-4"
|
|
1139
1158
|
on:mousedown={handleToolbarInteraction}
|
|
1140
1159
|
on:click={handleToolbarInteraction}
|
|
1141
1160
|
on:keydown={handleToolbarKeyDown}
|
|
@@ -1144,7 +1163,7 @@
|
|
|
1144
1163
|
tabindex="-1"
|
|
1145
1164
|
>
|
|
1146
1165
|
<div
|
|
1147
|
-
class="toolbar-items-row relative flex h-full w-full
|
|
1166
|
+
class="toolbar-items-row relative flex h-full w-full min-w-0 items-center justify-between gap-2"
|
|
1148
1167
|
>
|
|
1149
1168
|
<!-- Format cluster centered; close stays on the right -->
|
|
1150
1169
|
<div
|
|
@@ -1245,19 +1264,16 @@
|
|
|
1245
1264
|
<span class="text-label-small">{$t(currentTextStyleMessageKey)}</span>
|
|
1246
1265
|
{/if}
|
|
1247
1266
|
{/if}
|
|
1248
|
-
{
|
|
1249
|
-
<IconChevronUp class={toolbarIconClass} />
|
|
1250
|
-
{:else}
|
|
1251
|
-
<IconChevronDown class={toolbarIconClass} />
|
|
1252
|
-
{/if}
|
|
1267
|
+
<DropdownChevron open={textStyleDropdownOpen} class={toolbarIconClass} />
|
|
1253
1268
|
</div>
|
|
1254
1269
|
</Button>
|
|
1255
1270
|
</Popover.Trigger>
|
|
1256
1271
|
|
|
1257
1272
|
<Popover.Content
|
|
1258
|
-
class="w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
|
|
1273
|
+
class="richtext-toolbar-popover z-[60] w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
|
|
1259
1274
|
align="end"
|
|
1260
1275
|
sideOffset={8}
|
|
1276
|
+
portalProps={toolbarPopoverPortalProps}
|
|
1261
1277
|
>
|
|
1262
1278
|
<Command.Root>
|
|
1263
1279
|
<Command.List
|
|
@@ -1335,19 +1351,16 @@
|
|
|
1335
1351
|
{:else}
|
|
1336
1352
|
<IconList class={toolbarIconClass} />
|
|
1337
1353
|
{/if}
|
|
1338
|
-
{
|
|
1339
|
-
<IconChevronUp class={toolbarIconClass} />
|
|
1340
|
-
{:else}
|
|
1341
|
-
<IconChevronDown class={toolbarIconClass} />
|
|
1342
|
-
{/if}
|
|
1354
|
+
<DropdownChevron open={listStyleDropdownOpen} class={toolbarIconClass} />
|
|
1343
1355
|
</div>
|
|
1344
1356
|
</Button>
|
|
1345
1357
|
</Popover.Trigger>
|
|
1346
1358
|
|
|
1347
1359
|
<Popover.Content
|
|
1348
|
-
class="
|
|
1360
|
+
class="richtext-toolbar-popover z-[60] w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
|
|
1349
1361
|
align="end"
|
|
1350
1362
|
sideOffset={8}
|
|
1363
|
+
portalProps={toolbarPopoverPortalProps}
|
|
1351
1364
|
>
|
|
1352
1365
|
<Command.Root>
|
|
1353
1366
|
<Command.List
|
|
@@ -1390,11 +1403,11 @@
|
|
|
1390
1403
|
</div>
|
|
1391
1404
|
</div>
|
|
1392
1405
|
|
|
1393
|
-
{#if onClose
|
|
1406
|
+
{#if onClose}
|
|
1394
1407
|
<IconButton
|
|
1395
1408
|
variant="ghost"
|
|
1396
|
-
size="
|
|
1397
|
-
class="toolbar-close-button z-
|
|
1409
|
+
size="sm"
|
|
1410
|
+
class="toolbar-close-button z-30 ms-auto shrink-0"
|
|
1398
1411
|
label={$t('editor.textArea.closePanel')}
|
|
1399
1412
|
onclick={(e) => {
|
|
1400
1413
|
e.stopPropagation();
|
|
@@ -1402,7 +1415,7 @@
|
|
|
1402
1415
|
onClose();
|
|
1403
1416
|
}}
|
|
1404
1417
|
>
|
|
1405
|
-
<
|
|
1418
|
+
<IconX class={toolbarIconClass} />
|
|
1406
1419
|
</IconButton>
|
|
1407
1420
|
{/if}
|
|
1408
1421
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<script lang="ts">
|
|
17
17
|
import { Portal } from '@widgetic/design-system/components';
|
|
18
|
-
import { IconArrowsDiagonal } from '@widgetic/design-system/icons';
|
|
18
|
+
import { IconArrowsDiagonal, IconX } from '@widgetic/design-system/icons';
|
|
19
19
|
import {
|
|
20
20
|
dirForUserText,
|
|
21
21
|
useTextDirection
|
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
aria-hidden="true"
|
|
211
211
|
>
|
|
212
212
|
<IconArrowsDiagonal
|
|
213
|
-
class="size-4 stroke-
|
|
213
|
+
class="size-4 stroke-2 text-muted-foreground transition-colors duration-fast group-hover:text-foreground"
|
|
214
214
|
/>
|
|
215
215
|
</div>
|
|
216
216
|
</div>
|
|
@@ -223,21 +223,22 @@
|
|
|
223
223
|
|
|
224
224
|
<!-- Text Area Input Controller in Portal -->
|
|
225
225
|
{#if isShowingTextArea}
|
|
226
|
-
<Portal target={portalTarget} class="text-area-portal absolute
|
|
227
|
-
<!-- Blocking overlay -->
|
|
226
|
+
<Portal target={portalTarget} class="text-area-portal absolute inset-0 z-50 flex max-h-full min-h-0 flex-col overflow-hidden">
|
|
227
|
+
<!-- Blocking overlay: clicks pass through to portalled popovers; only the editor card receives pointer events. -->
|
|
228
228
|
<div
|
|
229
|
-
class="absolute inset-0 bg-background {isClosing
|
|
229
|
+
class="text-area-portal-overlay pointer-events-auto absolute inset-0 z-0 bg-background {isClosing
|
|
230
230
|
? 'fade-out-animation'
|
|
231
231
|
: 'fade-in-animation'}"
|
|
232
|
-
style="
|
|
232
|
+
style="transform: translateZ(0); backface-visibility: hidden;"
|
|
233
|
+
role="presentation"
|
|
233
234
|
></div>
|
|
234
235
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
235
236
|
<div
|
|
236
237
|
bind:this={portalContentRef}
|
|
237
|
-
class="text-area-portal-content absolute
|
|
238
|
+
class="text-area-portal-content pointer-events-auto absolute z-10 mx-6 mb-6 mt-4 flex min-h-0 max-h-[calc(100%-2rem)] flex-1 flex-col inset-x-0 bottom-0 top-4 {isClosing
|
|
238
239
|
? 'scale-out-animation'
|
|
239
240
|
: 'scale-in-animation'}"
|
|
240
|
-
style="
|
|
241
|
+
style="transform: translateZ(0); backface-visibility: hidden;"
|
|
241
242
|
on:mouseenter={handlePortalMouseEnter}
|
|
242
243
|
on:mouseleave={handlePortalMouseLeave}
|
|
243
244
|
>
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
import { useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
22
22
|
import { directionOfFieldValue } from '../../utils/fieldDirection';
|
|
23
23
|
import InputControllerRow from './InputControllerRow.svelte';
|
|
24
|
+
import {
|
|
25
|
+
editableFieldSurfaceClass,
|
|
26
|
+
editableFieldSurfacePadding,
|
|
27
|
+
embeddedInputClass
|
|
28
|
+
} from './shared/editableFieldClasses';
|
|
24
29
|
|
|
25
30
|
// Component props
|
|
26
31
|
import type { InputControllerConfig } from './index';
|
|
@@ -67,9 +72,17 @@
|
|
|
67
72
|
</script>
|
|
68
73
|
|
|
69
74
|
<InputControllerRow {label} {description}>
|
|
75
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
76
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
70
77
|
<div
|
|
71
|
-
class="
|
|
78
|
+
class="{editableFieldSurfaceClass} {editableFieldSurfacePadding}"
|
|
72
79
|
onfocusin={onFocus}
|
|
80
|
+
onclick={(e) => {
|
|
81
|
+
const target = e.currentTarget.querySelector('input');
|
|
82
|
+
if (target instanceof HTMLInputElement && e.target !== target) {
|
|
83
|
+
target.focus();
|
|
84
|
+
}
|
|
85
|
+
}}
|
|
73
86
|
>
|
|
74
87
|
<Input
|
|
75
88
|
id="text-input"
|
|
@@ -85,7 +98,7 @@
|
|
|
85
98
|
onChange(newValue);
|
|
86
99
|
}
|
|
87
100
|
}}
|
|
88
|
-
class=
|
|
101
|
+
class={embeddedInputClass}
|
|
89
102
|
/>
|
|
90
103
|
</div>
|
|
91
104
|
</InputControllerRow>
|
|
@@ -417,7 +417,7 @@
|
|
|
417
417
|
>
|
|
418
418
|
<span class="flex size-4 shrink-0 items-center justify-center">
|
|
419
419
|
{#if timeOption === value}
|
|
420
|
-
<IconCheck class="size-4 stroke-
|
|
420
|
+
<IconCheck class="size-4 stroke-2" aria-hidden="true" />
|
|
421
421
|
{/if}
|
|
422
422
|
</span>
|
|
423
423
|
<span class="min-w-0 flex-1 truncate">{timeOption}</span>
|
|
@@ -43,11 +43,10 @@
|
|
|
43
43
|
/** COMPONENTS IMPORTS */
|
|
44
44
|
// Shadcn UI components imports from design-system
|
|
45
45
|
import { Popover, EmptyState, IconButton } from '@widgetic/design-system/components';
|
|
46
|
+
import { useEditorPickFile } from '../../pickFileContext';
|
|
46
47
|
|
|
47
48
|
import {
|
|
48
49
|
IconCloudUpload,
|
|
49
|
-
IconChevronDown,
|
|
50
|
-
IconChevronUp,
|
|
51
50
|
IconAlertTriangle
|
|
52
51
|
} from '@widgetic/design-system/icons';
|
|
53
52
|
|
|
@@ -57,12 +56,15 @@
|
|
|
57
56
|
// import { SearchInput } from './shared';
|
|
58
57
|
import { SearchInput } from '@widgetic/design-system/components';
|
|
59
58
|
import CategoryTabs from './shared/CategoryTabs.svelte';
|
|
59
|
+
import DropdownChevron from './shared/DropdownChevron.svelte';
|
|
60
|
+
import EditorFileBrowserOverlay from './shared/EditorFileBrowserOverlay.svelte';
|
|
60
61
|
import { RecentItemsSection, ItemGrid } from './shared';
|
|
61
62
|
import { useEditorLanguage } from '../../i18n/language';
|
|
62
63
|
import { categoryLabel } from '../../i18n/labels';
|
|
63
64
|
|
|
64
65
|
// The words of the editor in the language of the page.
|
|
65
66
|
const { t } = useEditorLanguage();
|
|
67
|
+
const getEditorPickFile = useEditorPickFile();
|
|
66
68
|
|
|
67
69
|
$: vectorLoadFailedLabel = $t('editor.vector.loadFailed');
|
|
68
70
|
|
|
@@ -126,6 +128,31 @@
|
|
|
126
128
|
let controllerElement: HTMLDivElement | undefined;
|
|
127
129
|
let vectorObserver = new IntersectionObserver(() => {});
|
|
128
130
|
|
|
131
|
+
// The picker is as tall as the room around its trigger allows (560px at most) and opens on the side that has more room,
|
|
132
|
+
// so that its header (the title and the upload button) is never cut off by the top or the bottom of the window.
|
|
133
|
+
let vectorTriggerBox: HTMLDivElement | undefined;
|
|
134
|
+
let vectorPopoverSide: 'top' | 'bottom' = 'bottom';
|
|
135
|
+
let vectorPopoverStyle = '';
|
|
136
|
+
|
|
137
|
+
function updateVectorPopoverBox() {
|
|
138
|
+
try {
|
|
139
|
+
if (!vectorTriggerBox || typeof window === 'undefined') return;
|
|
140
|
+
const triggerRect = vectorTriggerBox.getBoundingClientRect();
|
|
141
|
+
const collisionPadding = 12;
|
|
142
|
+
const sideOffset = 8;
|
|
143
|
+
const viewportHeight = window.visualViewport?.height ?? window.innerHeight;
|
|
144
|
+
const roomBelow = viewportHeight - triggerRect.bottom - collisionPadding - sideOffset;
|
|
145
|
+
const roomAbove = triggerRect.top - collisionPadding - sideOffset;
|
|
146
|
+
const opensAbove = roomAbove > roomBelow;
|
|
147
|
+
vectorPopoverSide = opensAbove ? 'top' : 'bottom';
|
|
148
|
+
const availableHeight = Math.max(0, opensAbove ? roomAbove : roomBelow);
|
|
149
|
+
const desiredHeight = Math.min(560, availableHeight);
|
|
150
|
+
vectorPopoverStyle = `height: ${desiredHeight}px; max-height: ${desiredHeight}px;`;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('❌ [VectorInput] Could not measure the room around the picker:', error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
129
156
|
// Initialize VectorManager instance
|
|
130
157
|
let vectorManagerInstance: VectorManager;
|
|
131
158
|
let buttonWidth = 0;
|
|
@@ -887,6 +914,9 @@
|
|
|
887
914
|
// vector: vectorValue
|
|
888
915
|
// });
|
|
889
916
|
}
|
|
917
|
+
if ($openDropdowns?.has(controllerId)) {
|
|
918
|
+
toggleDropdown(controllerId);
|
|
919
|
+
}
|
|
890
920
|
}
|
|
891
921
|
|
|
892
922
|
/**
|
|
@@ -999,6 +1029,54 @@
|
|
|
999
1029
|
}
|
|
1000
1030
|
}
|
|
1001
1031
|
|
|
1032
|
+
// True while `fillVectorListUntilItScrolls` is asking for more vectors, so that two fills never run together
|
|
1033
|
+
let isFillingVectorList = false;
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* The first batch is eight vectors, which do not fill the list: the list cannot scroll, the scroll handler never asks
|
|
1037
|
+
* for more, and the user sees eight icons and never reaches the emoji faces. This asks for more, a batch at a time,
|
|
1038
|
+
* until the list is taller than its window (or there is nothing more to show).
|
|
1039
|
+
*/
|
|
1040
|
+
async function fillVectorListUntilItScrolls() {
|
|
1041
|
+
if (isFillingVectorList) return;
|
|
1042
|
+
isFillingVectorList = true;
|
|
1043
|
+
try {
|
|
1044
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
1045
|
+
await tick();
|
|
1046
|
+
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
|
|
1047
|
+
const listWindow = vectorListContainer;
|
|
1048
|
+
if (!listWindow || !$openDropdowns?.has(controllerId)) return;
|
|
1049
|
+
if (listWindow.scrollHeight > listWindow.clientHeight + 1) return;
|
|
1050
|
+
|
|
1051
|
+
if (searchTerm && currentSearchResults.length > 0) {
|
|
1052
|
+
const nextSearchBatch = currentSearchResults.slice(
|
|
1053
|
+
filteredVectors.length,
|
|
1054
|
+
filteredVectors.length + SEARCH_BATCH_SIZE
|
|
1055
|
+
);
|
|
1056
|
+
if (nextSearchBatch.length === 0) return;
|
|
1057
|
+
filteredVectors = [...filteredVectors, ...nextSearchBatch];
|
|
1058
|
+
} else if (
|
|
1059
|
+
!searchTerm &&
|
|
1060
|
+
!isLoadingBatch &&
|
|
1061
|
+
vectorManagerInstance?.hasMoreVectors(controllerId, currentFilter)
|
|
1062
|
+
) {
|
|
1063
|
+
await loadNextBatch();
|
|
1064
|
+
} else {
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
} catch (error) {
|
|
1069
|
+
console.error('❌ [VectorInput] Could not fill the vector list:', error);
|
|
1070
|
+
} finally {
|
|
1071
|
+
isFillingVectorList = false;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// Whenever the open list changes (a category, a search, a new batch) check that it is still tall enough to scroll
|
|
1076
|
+
$: if ($openDropdowns?.has(controllerId) && filteredVectors.length > 0) {
|
|
1077
|
+
void fillVectorListUntilItScrolls();
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1002
1080
|
onDestroy(() => {
|
|
1003
1081
|
stopListeningForScroll();
|
|
1004
1082
|
|
|
@@ -1021,28 +1099,63 @@
|
|
|
1021
1099
|
* Opens the file browser for vector selection
|
|
1022
1100
|
*/
|
|
1023
1101
|
async function openFileBrowser() {
|
|
1024
|
-
//
|
|
1102
|
+
// The picker gives way to the file browser: two layers of choices must never be open on top of each other.
|
|
1103
|
+
if ($openDropdowns?.has(controllerId)) {
|
|
1104
|
+
toggleDropdown(controllerId);
|
|
1105
|
+
}
|
|
1106
|
+
const pickFile = getEditorPickFile();
|
|
1107
|
+
if (pickFile) {
|
|
1108
|
+
try {
|
|
1109
|
+
const picked = await pickFile({
|
|
1110
|
+
accept: ['image/svg+xml', '.svg'],
|
|
1111
|
+
multiple: false,
|
|
1112
|
+
signal: new AbortController().signal
|
|
1113
|
+
});
|
|
1114
|
+
const selectedFile = picked?.[0];
|
|
1115
|
+
if (selectedFile && onChange) {
|
|
1116
|
+
onChange({
|
|
1117
|
+
name: selectedFile.name.replace(/\.svg$/i, '') || selectedFile.name,
|
|
1118
|
+
category: 'Mine',
|
|
1119
|
+
url: selectedFile.url
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
} catch (error) {
|
|
1123
|
+
console.error('❌ [VectorInput] pickFile failed:', error);
|
|
1124
|
+
}
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1025
1127
|
|
|
1026
1128
|
try {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
? vectorManagerInstance
|
|
1030
|
-
?.getCachedVectorList()
|
|
1031
|
-
.find((v) => v.name === value.name && v.category === 'Mine')?.name
|
|
1032
|
-
: undefined;
|
|
1033
|
-
|
|
1034
|
-
// console.log('🔍 [VectorInput] Opening file browser:', {
|
|
1035
|
-
// fileTypes: ['svg'],
|
|
1036
|
-
// selectedId
|
|
1037
|
-
// });
|
|
1038
|
-
|
|
1039
|
-
// TODO: Implement file browser functionality
|
|
1040
|
-
// This will be similar to FontInputController but for SVG files
|
|
1129
|
+
showVectorModal = true;
|
|
1130
|
+
await tick();
|
|
1041
1131
|
} catch (error) {
|
|
1042
1132
|
console.error('❌ [VectorInput] Error opening file browser:', error);
|
|
1043
1133
|
}
|
|
1044
1134
|
}
|
|
1045
1135
|
|
|
1136
|
+
function closeVectorFileBrowser() {
|
|
1137
|
+
showVectorModal = false;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
async function handleVectorFileBrowserSelect(
|
|
1141
|
+
event: CustomEvent<{ files?: Array<{ id: string; name?: string; file?: string; url: string }> }>
|
|
1142
|
+
) {
|
|
1143
|
+
try {
|
|
1144
|
+
const selectedFile = event.detail?.files?.[0];
|
|
1145
|
+
if (!selectedFile?.url || !onChange) return;
|
|
1146
|
+
const displayName =
|
|
1147
|
+
selectedFile.name || selectedFile.file || selectedFile.url.split('/').pop() || 'Custom';
|
|
1148
|
+
onChange({
|
|
1149
|
+
name: displayName.replace(/\.svg$/i, ''),
|
|
1150
|
+
category: 'Mine',
|
|
1151
|
+
url: selectedFile.url
|
|
1152
|
+
});
|
|
1153
|
+
closeVectorFileBrowser();
|
|
1154
|
+
} catch (error) {
|
|
1155
|
+
console.error('❌ [VectorInput] File browser selection failed:', error);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1046
1159
|
/**
|
|
1047
1160
|
* Handles category filter changes
|
|
1048
1161
|
*/
|
|
@@ -1413,7 +1526,10 @@
|
|
|
1413
1526
|
}
|
|
1414
1527
|
|
|
1415
1528
|
function isVectorSelected(vector: VectorItem) {
|
|
1416
|
-
return Boolean(
|
|
1529
|
+
return Boolean(
|
|
1530
|
+
value?.name === vector.name &&
|
|
1531
|
+
(value?.url ? value.url === vector.url : true)
|
|
1532
|
+
);
|
|
1417
1533
|
}
|
|
1418
1534
|
|
|
1419
1535
|
function isCustomVector(vector: VectorItem) {
|
|
@@ -1529,12 +1645,13 @@
|
|
|
1529
1645
|
|
|
1530
1646
|
<div bind:this={controllerElement} class="vector-ic flex w-full flex-col">
|
|
1531
1647
|
<InputControllerRow {label} helpText={description}>
|
|
1532
|
-
<div class="vector-input-ct w-full" onfocusin={onFocus}>
|
|
1648
|
+
<div bind:this={vectorTriggerBox} class="vector-input-ct w-full" onfocusin={onFocus}>
|
|
1533
1649
|
<Popover.Root
|
|
1534
1650
|
open={$openDropdowns?.has(controllerId)}
|
|
1535
1651
|
onOpenChange={(isOpen) => {
|
|
1536
1652
|
if (isOpen !== $openDropdowns?.has(controllerId)) {
|
|
1537
1653
|
if (isOpen) {
|
|
1654
|
+
updateVectorPopoverBox();
|
|
1538
1655
|
// Check if the selected vector image is valid
|
|
1539
1656
|
if (value?.name && value.url) {
|
|
1540
1657
|
// Create a temporary image to test if it loads
|
|
@@ -1592,7 +1709,7 @@
|
|
|
1592
1709
|
<div class="flex min-w-0 flex-1 items-center gap-2 truncate">
|
|
1593
1710
|
{#if value?.url}
|
|
1594
1711
|
{#if hasSvgLoadError(value.name)}
|
|
1595
|
-
<IconAlertTriangle class="size-4 shrink-0 stroke-
|
|
1712
|
+
<IconAlertTriangle class="size-4 shrink-0 stroke-2 text-destructive" />
|
|
1596
1713
|
<span class="truncate text-start text-body text-foreground">
|
|
1597
1714
|
{value?.name || $t('editor.vector.select')}
|
|
1598
1715
|
</span>
|
|
@@ -1613,17 +1730,16 @@
|
|
|
1613
1730
|
</span>
|
|
1614
1731
|
{/if}
|
|
1615
1732
|
</div>
|
|
1616
|
-
{
|
|
1617
|
-
<IconChevronUp class="size-4 shrink-0 stroke-[1.333] text-muted-foreground" />
|
|
1618
|
-
{:else}
|
|
1619
|
-
<IconChevronDown class="size-4 shrink-0 stroke-[1.333] text-muted-foreground" />
|
|
1620
|
-
{/if}
|
|
1733
|
+
<DropdownChevron open={$openDropdowns?.has(controllerId)} />
|
|
1621
1734
|
</Popover.Trigger>
|
|
1622
1735
|
|
|
1623
1736
|
<Popover.Content
|
|
1737
|
+
collisionPadding={12}
|
|
1738
|
+
side={vectorPopoverSide}
|
|
1624
1739
|
align="end"
|
|
1625
1740
|
sideOffset={8}
|
|
1626
|
-
class="vector-input-popover z-50 flex h-[560px] w-picker flex-col overflow-hidden rounded-xl border border-border bg-popover p-0 text-popover-foreground outline-none"
|
|
1741
|
+
class="vector-input-popover z-50 flex h-[560px] w-picker max-w-[calc(100vw-16px)] flex-col overflow-hidden rounded-xl border border-border bg-popover p-0 text-popover-foreground outline-none"
|
|
1742
|
+
style={vectorPopoverStyle}
|
|
1627
1743
|
>
|
|
1628
1744
|
<div class="vector-popover-content flex h-full min-h-0 flex-col">
|
|
1629
1745
|
<div class="flex shrink-0 flex-col gap-3 px-4 pt-4 pb-3">
|
|
@@ -1643,7 +1759,7 @@
|
|
|
1643
1759
|
}
|
|
1644
1760
|
}}
|
|
1645
1761
|
>
|
|
1646
|
-
<IconCloudUpload class="size-4 stroke-
|
|
1762
|
+
<IconCloudUpload class="size-4 stroke-2" />
|
|
1647
1763
|
</IconButton>
|
|
1648
1764
|
</div>
|
|
1649
1765
|
<!-- Search input -->
|
|
@@ -1832,6 +1948,18 @@
|
|
|
1832
1948
|
</InputControllerRow>
|
|
1833
1949
|
</div>
|
|
1834
1950
|
|
|
1951
|
+
{#if showVectorModal}
|
|
1952
|
+
<!-- The browser of the editor (shared with the other file fields); the vector field takes SVG files only. -->
|
|
1953
|
+
<EditorFileBrowserOverlay
|
|
1954
|
+
portalTarget="props-editor-file-browser-portal"
|
|
1955
|
+
fileFilter="svg"
|
|
1956
|
+
instanceId={`vector-input-${controllerId}`}
|
|
1957
|
+
addToEditorLabel={$t('editor.file.useFile')}
|
|
1958
|
+
onClose={closeVectorFileBrowser}
|
|
1959
|
+
on:select={handleVectorFileBrowserSelect}
|
|
1960
|
+
/>
|
|
1961
|
+
{/if}
|
|
1962
|
+
|
|
1835
1963
|
<style>
|
|
1836
1964
|
:global(.transition-border) {
|
|
1837
1965
|
transition: border-color 0.2s ease-in-out;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of the number stepper (`NumberControls.svelte`), kept apart from the component so Node can test it.
|
|
3
|
+
*/
|
|
4
|
+
export interface NumberStepLimits {
|
|
5
|
+
/** The lowest value; no limit when left out. */
|
|
6
|
+
min?: number;
|
|
7
|
+
/** The highest value; no limit when left out. */
|
|
8
|
+
max?: number;
|
|
9
|
+
/** An angle: a step past 360 comes back round to 0, and a step below 0 to 360, instead of stopping at a limit. */
|
|
10
|
+
wrapAround?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, then kept inside
|
|
14
|
+
* the limits, or brought back round for an angle. At a limit the result is `currentValue` itself, which tells the caller
|
|
15
|
+
* that there is nothing to apply (and nothing to repeat).
|
|
16
|
+
*/
|
|
17
|
+
export declare function steppedNumber(currentValue: number, adjustment: number, { min, max, wrapAround }?: NumberStepLimits): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of the number stepper (`NumberControls.svelte`), kept apart from the component so Node can test it.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, then kept inside
|
|
6
|
+
* the limits, or brought back round for an angle. At a limit the result is `currentValue` itself, which tells the caller
|
|
7
|
+
* that there is nothing to apply (and nothing to repeat).
|
|
8
|
+
*/
|
|
9
|
+
export function steppedNumber(currentValue, adjustment, { min, max, wrapAround = false } = {}) {
|
|
10
|
+
let steppedValue = currentValue + adjustment;
|
|
11
|
+
if (wrapAround) {
|
|
12
|
+
if (steppedValue >= 360)
|
|
13
|
+
steppedValue -= 360;
|
|
14
|
+
if (steppedValue < 0)
|
|
15
|
+
steppedValue += 360;
|
|
16
|
+
return steppedValue;
|
|
17
|
+
}
|
|
18
|
+
if (min !== undefined && steppedValue < min)
|
|
19
|
+
steppedValue = min;
|
|
20
|
+
if (max !== undefined && steppedValue > max)
|
|
21
|
+
steppedValue = max;
|
|
22
|
+
return steppedValue;
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The arrow of a dropdown trigger (Figma IC Dropdown, Select Trigger): ONE chevron that turns half a turn while the list is open.
|
|
3
|
+
It used to be two icons swapped on open (chevron down, chevron up), so it jumped from one to the other. The accordion turns
|
|
4
|
+
one arrow with `transition-transform duration-base`, and so does this one: the same 160 ms, the same ease.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { IconChevronDown } from '@widgetic/design-system/icons';
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
open = false,
|
|
11
|
+
class: className = 'size-3.5 shrink-0 stroke-[2.286] text-muted-foreground'
|
|
12
|
+
}: {
|
|
13
|
+
/** True while the list the trigger opens is open: the arrow points up. */
|
|
14
|
+
open?: boolean;
|
|
15
|
+
/** The size and colour of the arrow. The default is the Figma one: 14 px, drawn with the 1.333 px stroke of every icon (`stroke-[2.286]` in the 24-unit viewBox). */
|
|
16
|
+
class?: string;
|
|
17
|
+
} = $props();
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<IconChevronDown
|
|
21
|
+
class="{className} transition-transform duration-base {open ? 'rotate-180' : ''}"
|
|
22
|
+
aria-hidden="true"
|
|
23
|
+
/>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
/** True while the list the trigger opens is open: the arrow points up. */
|
|
3
|
+
open?: boolean;
|
|
4
|
+
/** The size and colour of the arrow. The default is the Figma one: 14 px, drawn with the 1.333 px stroke of every icon (`stroke-[2.286]` in the 24-unit viewBox). */
|
|
5
|
+
class?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const DropdownChevron: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type DropdownChevron = ReturnType<typeof DropdownChevron>;
|
|
9
|
+
export default DropdownChevron;
|