@vev/silke 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +86 -86
- package/CHANGELOG.md +8 -0
- package/dist/index.js +42 -45
- package/dist/index.js.LEGAL.txt +2 -1
- package/dist/index.js.map +4 -4
- package/dist/styles.css +192 -166
- package/dist/types/components/silke-action-box/silke-action-box.d.ts +1 -1
- package/dist/types/components/silke-alert-banner/silke-alert-banner.d.ts +1 -1
- package/dist/types/components/silke-autocomplete-field/autocomplete-item.d.ts +1 -1
- package/dist/types/components/silke-autocomplete-field/autocomplete-tags.d.ts +2 -1
- package/dist/types/components/silke-autocomplete-field/silke-autocomplete-field-native.d.ts +1 -1
- package/dist/types/components/silke-autocomplete-field/silke-autocomplete-field.d.ts +1 -1
- package/dist/types/components/silke-autocomplete-field/silke-autocomplete-popup-native.d.ts +2 -2
- package/dist/types/components/silke-autocomplete-field/silke-autocomplete-popup.d.ts +2 -2
- package/dist/types/components/silke-box/silke-box.d.ts +1 -1
- package/dist/types/components/silke-breadcrumbs/silke-breadcrumb.d.ts +1 -1
- package/dist/types/components/silke-breadcrumbs/silke-breadcrumbs.d.ts +2 -1
- package/dist/types/components/silke-button/context.d.ts +1 -1
- package/dist/types/components/silke-button/silke-big-button.d.ts +1 -1
- package/dist/types/components/silke-button/silke-button-set.d.ts +1 -1
- package/dist/types/components/silke-button/silke-confirmation-button.d.ts +1 -1
- package/dist/types/components/silke-button/silke-dropdown-button.d.ts +2 -1
- package/dist/types/components/silke-button/silke-file-select-button.d.ts +2 -1
- package/dist/types/components/silke-card/silke-card-grid.d.ts +1 -1
- package/dist/types/components/silke-card/silke-card.spec.d.ts +1 -0
- package/dist/types/components/silke-checkbox/silke-checkbox.d.ts +1 -1
- package/dist/types/components/silke-code-editor/index.d.ts +2 -1
- package/dist/types/components/silke-code-editor/silke-code-editor.d.ts +2 -1
- package/dist/types/components/silke-code-snippet/silke-code-snippet.d.ts +1 -1
- package/dist/types/components/silke-color-palettes/silke-color-palette.d.ts +2 -1
- package/dist/types/components/silke-color-palettes/silke-color-palettes.d.ts +2 -1
- package/dist/types/components/silke-color-picker/silke-color-info.d.ts +2 -1
- package/dist/types/components/silke-color-picker/silke-color-picker-button.d.ts +1 -1
- package/dist/types/components/silke-color-picker/silke-color-picker.d.ts +2 -1
- package/dist/types/components/silke-color-picker/silke-color-space.d.ts +2 -1
- package/dist/types/components/silke-color-picker/silke-hue-slider.d.ts +2 -1
- package/dist/types/components/silke-color-picker/silke-opacity-slider.d.ts +2 -1
- package/dist/types/components/silke-color-swatches/silke-swatches.d.ts +2 -1
- package/dist/types/components/silke-command-text-field/attachment-chip.d.ts +2 -1
- package/dist/types/components/silke-command-text-field/attachment-list.d.ts +2 -0
- package/dist/types/components/silke-command-text-field/file-utils.d.ts +21 -1
- package/dist/types/components/silke-command-text-field/index.d.ts +1 -1
- package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +2 -0
- package/dist/types/components/silke-conditions-input/silke-conditions-input-options.d.ts +2 -1
- package/dist/types/components/silke-conditions-input/silke-conditions-input.d.ts +2 -1
- package/dist/types/components/silke-conditions-input/silke-conditions-tag.d.ts +2 -1
- package/dist/types/components/silke-content-column/silke-content-column.d.ts +2 -1
- package/dist/types/components/silke-context-menu/silke-context-menu-item.d.ts +1 -1
- package/dist/types/components/silke-context-menu/silke-context-menu.d.ts +1 -1
- package/dist/types/components/silke-css-number-field/silke-css-context.d.ts +1 -1
- package/dist/types/components/silke-css-number-field/silke-css-number-field.d.ts +1 -1
- package/dist/types/components/silke-divider/silke-divider.d.ts +2 -1
- package/dist/types/components/silke-drawer/silke-drawer.d.ts +1 -1
- package/dist/types/components/silke-expression-input/silke-expression-input-tag.d.ts +2 -1
- package/dist/types/components/silke-form/form-context.d.ts +1 -1
- package/dist/types/components/silke-form/silke-form.d.ts +2 -2
- package/dist/types/components/silke-form-schema/fields/array-field-inline.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/array-field-modal.d.ts +2 -2
- package/dist/types/components/silke-form-schema/fields/array-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/audio-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/color-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/event-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/group-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/icon-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/image-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/layout-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/link-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/number-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/object-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/popover-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/select-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/string-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/toggle-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/upload-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/video-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/silke-extended-fields-context.d.ts +3 -3
- package/dist/types/components/silke-form-schema/silke-form-schema.d.ts +5 -2
- package/dist/types/components/silke-form-schema/silke-schema-context.d.ts +2 -2
- package/dist/types/components/silke-form-schema/silke-schema-decorator.d.ts +14 -3
- package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/silke-schema-fields.d.ts +2 -1
- package/dist/types/components/silke-gradient-picker/silke-gradient-picker.d.ts +2 -1
- package/dist/types/components/silke-gradient-picker/silke-gradient-position.d.ts +2 -1
- package/dist/types/components/silke-gradient-picker/silke-gradient-slider.d.ts +2 -1
- package/dist/types/components/silke-icon/silke-icon.d.ts +1 -1
- package/dist/types/components/silke-icon/silke-shape.d.ts +2 -1
- package/dist/types/components/silke-icon/silke-stacked-icon.d.ts +2 -1
- package/dist/types/components/silke-icon-picker/color-swatch-section.d.ts +2 -1
- package/dist/types/components/silke-icon-picker/emoji-tab.d.ts +2 -1
- package/dist/types/components/silke-icon-picker/icons-tab.d.ts +2 -1
- package/dist/types/components/silke-icon-picker/silke-icon-picker.d.ts +2 -1
- package/dist/types/components/silke-icon-picker/upload-tab.d.ts +2 -1
- package/dist/types/components/silke-iframe-portal/silke-iframe-portal.d.ts +1 -1
- package/dist/types/components/silke-image/silke-image-color-backdrop.d.ts +2 -1
- package/dist/types/components/silke-image/silke-image.d.ts +2 -1
- package/dist/types/components/silke-link/silke-link.d.ts +1 -1
- package/dist/types/components/silke-list/silke-list-item.d.ts +1 -1
- package/dist/types/components/silke-list/silke-list.d.ts +2 -1
- package/dist/types/components/silke-loader/silke-loader-overlay.d.ts +1 -1
- package/dist/types/components/silke-loader/silke-loader.d.ts +2 -2
- package/dist/types/components/silke-modal/silke-confirmation-modal.d.ts +2 -1
- package/dist/types/components/silke-modal/silke-modal.d.ts +3 -3
- package/dist/types/components/silke-object-field/silke-object-field.d.ts +1 -1
- package/dist/types/components/silke-overflow-menu/silke-overflow-menu.d.ts +1 -1
- package/dist/types/components/silke-popover/popover-context.d.ts +1 -1
- package/dist/types/components/silke-popover/silke-popover.d.ts +2 -2
- package/dist/types/components/silke-popover-native/silke-popover-native.d.ts +1 -1
- package/dist/types/components/silke-popover-native/types.d.ts +1 -1
- package/dist/types/components/silke-popover-native/use-popover-positioning.d.ts +1 -1
- package/dist/types/components/silke-progress-indicator/silke-progress-indicator.d.ts +1 -1
- package/dist/types/components/silke-progress-indicator/silke-progress-step.d.ts +2 -1
- package/dist/types/components/silke-radio-button/silke-radio-button-group.d.ts +1 -1
- package/dist/types/components/silke-radio-button/silke-radio-button.d.ts +1 -1
- package/dist/types/components/silke-rich-text-field/blockquote.d.ts +3 -18
- package/dist/types/components/silke-rich-text-field/floating-layer.d.ts +5 -1
- package/dist/types/components/silke-rich-text-field/floating-layer.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/formatting-toolbar.d.ts +2 -1
- package/dist/types/components/silke-rich-text-field/link-menu.d.ts +1 -1
- package/dist/types/components/silke-rich-text-field/link-tooltip.d.ts +2 -1
- package/dist/types/components/silke-rich-text-field/silke-rich-text-field.d.ts +1 -1
- package/dist/types/components/silke-rich-text-field/slash-menu.d.ts +5 -4
- package/dist/types/components/silke-rich-text-field/slash-menu.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/table-toolbar.d.ts +2 -1
- package/dist/types/components/silke-rich-text-field/use-link-hover.d.ts +1 -1
- package/dist/types/components/silke-rich-text-field/utils.d.ts +29 -1
- package/dist/types/components/silke-rich-text-field/utils.spec.d.ts +1 -0
- package/dist/types/components/silke-search-field/silke-search-field.d.ts +2 -1
- package/dist/types/components/silke-select-field/silke-select-field-native.d.ts +2 -1
- package/dist/types/components/silke-select-field/silke-select-field.d.ts +2 -1
- package/dist/types/components/silke-shortcut-button/silke-shortcut-button.d.ts +1 -1
- package/dist/types/components/silke-skeleton/silke-skeleton.d.ts +1 -1
- package/dist/types/components/silke-slider/silke-slider-point.d.ts +1 -1
- package/dist/types/components/silke-slider/silke-slider.d.ts +1 -1
- package/dist/types/components/silke-slider/slider-track.d.ts +1 -1
- package/dist/types/components/silke-sortable-list/silke-nested-sortable-item.d.ts +1 -1
- package/dist/types/components/silke-sortable-list/silke-nested-sortable-list.d.ts +1 -1
- package/dist/types/components/silke-sortable-list/silke-sortable-item-wrapper.d.ts +1 -1
- package/dist/types/components/silke-sortable-list/silke-sortable-list.d.ts +1 -1
- package/dist/types/components/silke-table/silke-table.d.ts +1 -1
- package/dist/types/components/silke-table/table-row.d.ts +2 -1
- package/dist/types/components/silke-tabs/silke-tab.d.ts +1 -1
- package/dist/types/components/silke-tabs/silke-tabs.d.ts +1 -1
- package/dist/types/components/silke-tag/silke-tag.d.ts +6 -6
- package/dist/types/components/silke-text/silke-text.d.ts +27 -13
- package/dist/types/components/silke-text/silke-title.d.ts +2 -1
- package/dist/types/components/silke-text-field/text-field-context.d.ts +1 -1
- package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +2 -1
- package/dist/types/components/silke-theme-editor/silke-theme-editor.d.ts +2 -1
- package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +2 -1
- package/dist/types/components/silke-tile/silke-tile.d.ts +2 -2
- package/dist/types/components/silke-toast-notification/silke-toast-notification.d.ts +1 -1
- package/dist/types/components/silke-toggle/silke-toggle.d.ts +1 -1
- package/dist/types/components/silke-toolbar/silke-toolbar.d.ts +2 -1
- package/dist/types/components/silke-tooltip/silke-definition-tooltip.d.ts +1 -1
- package/dist/types/components/silke-tooltip/silke-icon-tooltip.d.ts +1 -1
- package/dist/types/components/silke-tooltip/silke-interactive-tooltip.d.ts +1 -1
- package/dist/types/components/silke-tooltip/silke-shortcuts.d.ts +2 -1
- package/dist/types/components/silke-tooltip/silke-tooltip.d.ts +1 -1
- package/dist/types/components/silke-upload-field/silke-upload-field.d.ts +1 -1
- package/dist/types/components/silke-variables-wrapper/silke-variables-wrapper-form.d.ts +2 -2
- package/dist/types/components/silke-variables-wrapper/silke-variables-wrapper.d.ts +1 -1
- package/dist/types/components/silke-virtual/silke-virtual-grid.d.ts +1 -1
- package/dist/types/components/silke-virtual/silke-virtual-row.d.ts +1 -1
- package/dist/types/hooks/use-drop-zone.d.ts +1 -1
- package/dist/types/hooks/use-mouse.d.ts +1 -1
- package/dist/types/hooks/use-parent-scroll.d.ts +1 -1
- package/dist/types/hooks/use-size.d.ts +1 -1
- package/dist/types/icons.d.ts +33 -32
- package/dist/types/silke-theme-provider.d.ts +1 -1
- package/package.json +18 -16
- package/src/@types/declarations.d.ts +1 -1
- package/src/components/silke-alert-banner/silke-alert-banner.tsx +1 -1
- package/src/components/silke-autocomplete-field/silke-autocomplete-field-native.tsx +3 -3
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +4 -4
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +6 -6
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup.tsx +6 -6
- package/src/components/silke-card/silke-card.scss +30 -3
- package/src/components/silke-card/silke-card.spec.tsx +32 -0
- package/src/components/silke-card/silke-card.tsx +62 -34
- package/src/components/silke-command-text-field/attachment-list.tsx +6 -7
- package/src/components/silke-command-text-field/file-utils.ts +103 -23
- package/src/components/silke-command-text-field/index.ts +3 -0
- package/src/components/silke-command-text-field/silke-command-text-field.mdx +5 -1
- package/src/components/silke-command-text-field/silke-command-text-field.tsx +26 -29
- package/src/components/silke-conditions-input/silke-conditions-input-options.tsx +1 -1
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +4 -4
- package/src/components/silke-drawer/silke-drawer.tsx +1 -1
- package/src/components/silke-form-schema/safe-eval/iframe-script.raw.js +1 -0
- package/src/components/silke-form-schema/schema-utils.ts +29 -2
- package/src/components/silke-form-schema/silke-extended-fields-context.tsx +1 -1
- package/src/components/silke-form-schema/silke-form-schema.tsx +9 -2
- package/src/components/silke-form-schema/silke-schema-decorator.tsx +22 -1
- package/src/components/silke-form-schema/silke-schema-field.tsx +13 -2
- package/src/components/silke-icon/silke-icon.tsx +1 -1
- package/src/components/silke-list/silke-list.tsx +15 -8
- package/src/components/silke-object-field/silke-object-field.tsx +1 -1
- package/src/components/silke-popover/silke-popover.tsx +14 -10
- package/src/components/silke-popover-native/types.ts +1 -1
- package/src/components/silke-popover-native/use-popover-positioning.ts +1 -1
- package/src/components/silke-rich-text-field/blockquote.spec.ts +118 -25
- package/src/components/silke-rich-text-field/blockquote.ts +46 -53
- package/src/components/silke-rich-text-field/floating-layer.spec.tsx +20 -0
- package/src/components/silke-rich-text-field/floating-layer.tsx +16 -1
- package/src/components/silke-rich-text-field/plugins.ts +1 -2
- package/src/components/silke-rich-text-field/silke-rich-text-field.scss +10 -0
- package/src/components/silke-rich-text-field/silke-rich-text-field.tsx +9 -4
- package/src/components/silke-rich-text-field/slash-menu-items.ts +1 -4
- package/src/components/silke-rich-text-field/slash-menu.spec.tsx +52 -0
- package/src/components/silke-rich-text-field/slash-menu.tsx +28 -14
- package/src/components/silke-rich-text-field/utils.spec.ts +115 -0
- package/src/components/silke-rich-text-field/utils.ts +76 -2
- package/src/components/silke-tag/silke-tag.tsx +1 -1
- package/src/components/silke-text-field/silke-text-field.tsx +2 -2
- package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +11 -6
- package/src/components/silke-toast-notification/confetti.tsx +1 -1
- package/src/components/silke-toast-notification/silke-toast-notification.tsx +1 -1
- package/src/components/silke-upload-field/silke-upload-field.tsx +2 -2
- package/src/components/silke-variables-wrapper/silke-variables-wrapper-form.tsx +1 -1
- package/src/components/silke-variables-wrapper/silke-variables-wrapper.tsx +9 -3
- package/src/hooks/form/use-form-field.ts +2 -2
- package/src/hooks/use-drop-zone.ts +1 -1
- package/src/hooks/use-html-element.ts +1 -1
- package/src/hooks/use-mouse.ts +1 -1
- package/src/hooks/use-parent-scroll.ts +1 -1
- package/src/hooks/use-size.ts +1 -1
|
@@ -16,9 +16,10 @@ import {
|
|
|
16
16
|
import { AttachmentList, AttachmentListHandle } from './attachment-list';
|
|
17
17
|
import {
|
|
18
18
|
SilkeFileCategory,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
filesToAttachmentValues,
|
|
20
|
+
getFilesFromClipboard,
|
|
21
|
+
getFilesFromDragEvent,
|
|
22
|
+
resolveFileAccept,
|
|
22
23
|
resolveFileCategories,
|
|
23
24
|
} from './file-utils';
|
|
24
25
|
import { parseTextToSilkeCommands } from './silke-command-parser';
|
|
@@ -49,6 +50,7 @@ export type SilkeCommandTextFieldProps = SilkeTextFieldOutlineProps & {
|
|
|
49
50
|
* File type categories to accept as attachments.
|
|
50
51
|
* - `'image'` — all image types (png, jpeg, gif, etc.)
|
|
51
52
|
* - `'text'` — documents and text files (PDF, Word, Excel, CSV, TXT, JSON, etc.)
|
|
53
|
+
* - `'document'` — documents AI models can read (PDF, TXT, Markdown, CSV, JSON)
|
|
52
54
|
* Defaults to `[]` (no files accepted).
|
|
53
55
|
*/
|
|
54
56
|
acceptedFileTypes?: SilkeFileCategory[];
|
|
@@ -127,6 +129,7 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
127
129
|
() => resolveFileCategories(acceptedFileTypes ?? []),
|
|
128
130
|
[acceptedFileTypes],
|
|
129
131
|
);
|
|
132
|
+
const fileAccept = useMemo(() => resolveFileAccept(acceptedFileTypes ?? []), [acceptedFileTypes]);
|
|
130
133
|
|
|
131
134
|
const filesDisabled = effectiveAcceptedTypes.length === 0;
|
|
132
135
|
|
|
@@ -393,11 +396,7 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
393
396
|
);
|
|
394
397
|
|
|
395
398
|
const handleCharacterInput = useCallback(
|
|
396
|
-
(
|
|
397
|
-
e: React.KeyboardEvent,
|
|
398
|
-
commandIndex: number,
|
|
399
|
-
currentValue: SilkeCommandTextFieldValue[],
|
|
400
|
-
) => {
|
|
399
|
+
(e: React.KeyboardEvent, commandIndex: number, currentValue: SilkeCommandTextFieldValue[]) => {
|
|
401
400
|
const element = inputRef.current;
|
|
402
401
|
if (!element) return;
|
|
403
402
|
|
|
@@ -514,15 +513,6 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
514
513
|
[disabled, handleArrowNavigation, handleCharacterInput, handleDelete, onKeyDown],
|
|
515
514
|
);
|
|
516
515
|
|
|
517
|
-
const addAttachment = useCallback(
|
|
518
|
-
(attachmentValue: SilkeImageValue | SilkeFileValue) => {
|
|
519
|
-
const newValue = [...valueRef.current, attachmentValue];
|
|
520
|
-
onChange(newValue);
|
|
521
|
-
inputRef.current?.focus();
|
|
522
|
-
},
|
|
523
|
-
[onChange],
|
|
524
|
-
);
|
|
525
|
-
|
|
526
516
|
const removeAttachment = useCallback(
|
|
527
517
|
(index: number) => {
|
|
528
518
|
// Find the nth attachment in the value array and remove it
|
|
@@ -550,15 +540,23 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
550
540
|
[onChange],
|
|
551
541
|
);
|
|
552
542
|
|
|
543
|
+
// Read pasted or dropped files and add them in one change, so several arrive at once
|
|
544
|
+
const addFiles = useCallback(
|
|
545
|
+
(files: File[]) => {
|
|
546
|
+
filesToAttachmentValues(files, effectiveAcceptedTypes).then((attachmentValues) => {
|
|
547
|
+
if (attachmentValues.length > 0) addMultipleAttachments(attachmentValues);
|
|
548
|
+
});
|
|
549
|
+
},
|
|
550
|
+
[addMultipleAttachments, effectiveAcceptedTypes],
|
|
551
|
+
);
|
|
552
|
+
|
|
553
553
|
const handlePaste = useCallback(
|
|
554
554
|
(e: React.ClipboardEvent<HTMLDivElement>) => {
|
|
555
555
|
if (!filesDisabled) {
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
556
|
+
const files = getFilesFromClipboard(e, effectiveAcceptedTypes);
|
|
557
|
+
if (files.length > 0) {
|
|
558
558
|
e.preventDefault();
|
|
559
|
-
|
|
560
|
-
if (attachmentValue) addAttachment(attachmentValue);
|
|
561
|
-
});
|
|
559
|
+
addFiles(files);
|
|
562
560
|
return;
|
|
563
561
|
}
|
|
564
562
|
}
|
|
@@ -587,7 +585,7 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
587
585
|
// execCommand fires `input`, the manual path does not, so re-parse from the DOM either way.
|
|
588
586
|
handleInput({ currentTarget: e.currentTarget } as React.FormEvent<HTMLDivElement>);
|
|
589
587
|
},
|
|
590
|
-
[
|
|
588
|
+
[addFiles, effectiveAcceptedTypes, filesDisabled, handleInput],
|
|
591
589
|
);
|
|
592
590
|
|
|
593
591
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
@@ -596,14 +594,12 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
596
594
|
(e: DragEvent) => {
|
|
597
595
|
if (filesDisabled) return;
|
|
598
596
|
|
|
599
|
-
const
|
|
600
|
-
if (
|
|
597
|
+
const files = getFilesFromDragEvent(e, effectiveAcceptedTypes);
|
|
598
|
+
if (files.length === 0) return;
|
|
601
599
|
|
|
602
|
-
|
|
603
|
-
if (attachmentValue) addAttachment(attachmentValue);
|
|
604
|
-
});
|
|
600
|
+
addFiles(files);
|
|
605
601
|
},
|
|
606
|
-
[
|
|
602
|
+
[addFiles, effectiveAcceptedTypes, filesDisabled],
|
|
607
603
|
);
|
|
608
604
|
|
|
609
605
|
useDropZone(containerRef, handleDrop);
|
|
@@ -618,6 +614,7 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
618
614
|
{!filesDisabled && (
|
|
619
615
|
<AttachmentList
|
|
620
616
|
ref={attachmentListRef}
|
|
617
|
+
accept={fileAccept}
|
|
621
618
|
acceptedTypes={effectiveAcceptedTypes}
|
|
622
619
|
attachments={attachments}
|
|
623
620
|
disabled={disabled}
|
|
@@ -13,7 +13,7 @@ export type SilkeConditionsInputProps = {
|
|
|
13
13
|
|
|
14
14
|
export function SilkeConditionsInputOptions(props: SilkeConditionsInputProps) {
|
|
15
15
|
const { suggestions, highlightedItem, onSelect } = props;
|
|
16
|
-
const dropdownRef = useRef<HTMLElement>();
|
|
16
|
+
const dropdownRef = useRef<HTMLElement>(null);
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
if (highlightedItem !== undefined) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCSSNumberFormat } from '@vev/utils';
|
|
1
|
+
import { getCSSNumberFormat, hasProps } from '@vev/utils';
|
|
2
2
|
import { get, isNumber, isString } from 'lodash';
|
|
3
3
|
import React, { Children, ReactNode, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
4
4
|
import { useCallbackRef, useFormField } from '../../hooks';
|
|
@@ -88,8 +88,8 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
88
88
|
} = useFormField(props);
|
|
89
89
|
|
|
90
90
|
const [openFormat, setFormatOpen] = useState(false);
|
|
91
|
-
const rootRef = useRef<HTMLDivElement>(null);
|
|
92
|
-
const numberRef = useRef<HTMLDivElement>(null);
|
|
91
|
+
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
92
|
+
const numberRef = useRef<HTMLDivElement | null>(null);
|
|
93
93
|
const context = useSilkeCSSContext();
|
|
94
94
|
const textFieldContext = useTextFieldContext();
|
|
95
95
|
const isNotDefined = value === undefined || value === null;
|
|
@@ -272,7 +272,7 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
272
272
|
const before: ReactNode[] = [];
|
|
273
273
|
const after: ReactNode[] = [];
|
|
274
274
|
Children.forEach(children, (child) => {
|
|
275
|
-
if (
|
|
275
|
+
if (hasProps(child, ['before']) && child.type === SilkeTextFieldItem) {
|
|
276
276
|
before.push(child);
|
|
277
277
|
} else {
|
|
278
278
|
after.push(child);
|
|
@@ -30,7 +30,7 @@ export const SilkeDrawer = ({
|
|
|
30
30
|
displayFader,
|
|
31
31
|
}: React.PropsWithChildren<SilkeDrawerProps>) => {
|
|
32
32
|
const [shouldRender, setShouldRender] = useState(false);
|
|
33
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
33
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
34
34
|
|
|
35
35
|
useKeyUp('Escape', () => {
|
|
36
36
|
if (open) {
|
|
@@ -3,6 +3,7 @@ let listeners = {};
|
|
|
3
3
|
const isVevMessage = (data) => Array.isArray(data) && data[0] === 'vev-iframe';
|
|
4
4
|
|
|
5
5
|
window.addEventListener('message', async ({ data, source }) => {
|
|
6
|
+
if (source !== window.parent) return;
|
|
6
7
|
if (isVevMessage(data)) {
|
|
7
8
|
const { type, messageId, responseId, value } = data[1];
|
|
8
9
|
|
|
@@ -10,19 +10,40 @@ export function isEvalCallback(value: any): value is EvalCallback {
|
|
|
10
10
|
|
|
11
11
|
type InitialValue = { [key: string]: any };
|
|
12
12
|
|
|
13
|
+
/** Field types that render their children into the parent value, without nesting. */
|
|
14
|
+
const TRANSPARENT_TYPES = ['layout', 'group', 'popover'];
|
|
15
|
+
|
|
16
|
+
/** The fields of a layout, group or popover, which are values of the level it sits in. */
|
|
17
|
+
function getTransparentFields(field: VevProps): VevProps[] | null {
|
|
18
|
+
if (!TRANSPARENT_TYPES.includes(field.type)) return null;
|
|
19
|
+
const { fields } = field as { fields?: VevProps[] };
|
|
20
|
+
return Array.isArray(fields) ? fields : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** `0`, `false` and `''` are defaults too: only a missing value is no default. */
|
|
24
|
+
function hasInitialValue(field: VevProps): boolean {
|
|
25
|
+
return field.initialValue !== undefined && field.initialValue !== null;
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
export async function getSchemaInitialValue<T extends InitialValue>(
|
|
14
29
|
schema: Schema,
|
|
15
30
|
context: Omit<SchemaContextModel, 'actions'>,
|
|
16
31
|
): Promise<InitialValue> {
|
|
17
32
|
const res: InitialValue = {};
|
|
18
33
|
for (const field of schema) {
|
|
34
|
+
const transparentFields = field && getTransparentFields(field);
|
|
35
|
+
if (transparentFields) {
|
|
36
|
+
Object.assign(res, await getSchemaInitialValue<T>(transparentFields, context));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
if (field.name && field.type) {
|
|
20
41
|
if (field.type === 'object') {
|
|
21
42
|
res[field.name] = await getSchemaInitialValue<T>(field.fields, context);
|
|
22
43
|
continue;
|
|
23
44
|
}
|
|
24
45
|
|
|
25
|
-
if (field
|
|
46
|
+
if (hasInitialValue(field)) {
|
|
26
47
|
if (isEvalCallback(field.initialValue)) {
|
|
27
48
|
res[field.name] = await safeEvalFunction(field.initialValue.value, context);
|
|
28
49
|
} else if (isFunction(field.initialValue)) {
|
|
@@ -45,6 +66,12 @@ export function getSchemaDefaultValue(schema: VevProps | VevProps[]): InitialVal
|
|
|
45
66
|
const fields = Array.isArray(schema) ? schema : [schema];
|
|
46
67
|
const res: InitialValue = {};
|
|
47
68
|
for (const field of fields) {
|
|
69
|
+
const transparentFields = field && getTransparentFields(field);
|
|
70
|
+
if (transparentFields) {
|
|
71
|
+
Object.assign(res, getSchemaDefaultValue(transparentFields));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
48
75
|
if (field.name && field.type) {
|
|
49
76
|
if (field.type === 'object') {
|
|
50
77
|
res[field.name] = getSchemaDefaultValue(field.fields);
|
|
@@ -52,7 +79,7 @@ export function getSchemaDefaultValue(schema: VevProps | VevProps[]): InitialVal
|
|
|
52
79
|
}
|
|
53
80
|
|
|
54
81
|
if (
|
|
55
|
-
field
|
|
82
|
+
hasInitialValue(field) &&
|
|
56
83
|
!isEvalCallback(field.initialValue) &&
|
|
57
84
|
!isFunction(field.initialValue)
|
|
58
85
|
) {
|
|
@@ -3,7 +3,11 @@ import React from 'react';
|
|
|
3
3
|
import { SilkeForm, SilkeFormProps } from '../silke-form';
|
|
4
4
|
import TextFieldContext from '../silke-text-field/text-field-context';
|
|
5
5
|
import { SilkeSchemaContext } from './silke-schema-context';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
SilkeSchemaDecoratorProvider,
|
|
8
|
+
SilkeSchemaFieldDecorator,
|
|
9
|
+
SilkeSchemaFieldEvents,
|
|
10
|
+
} from './silke-schema-decorator';
|
|
7
11
|
import { SilkeSchemaFields } from './silke-schema-fields';
|
|
8
12
|
import { SilkeTextFieldOutlineProps } from '../silke-text-field/silke-text-field-outline';
|
|
9
13
|
|
|
@@ -18,6 +22,8 @@ type SilkeFormSchemaProps<T extends { [key: string]: any }> = {
|
|
|
18
22
|
variables?: LocalVariable[];
|
|
19
23
|
/** Renders extra UI beside every field, eg a per-breakpoint status dot. */
|
|
20
24
|
fieldDecorator?: SilkeSchemaFieldDecorator;
|
|
25
|
+
/** Told as the pointer or the focus enters and leaves a field's row. */
|
|
26
|
+
fieldEvents?: SilkeSchemaFieldEvents;
|
|
21
27
|
} & SilkeFormProps<T>;
|
|
22
28
|
|
|
23
29
|
// pages?: { title: string; key: string; path?: string }[];
|
|
@@ -29,11 +35,12 @@ export function SilkeFormSchema<T extends { [key: string]: any }>({
|
|
|
29
35
|
context,
|
|
30
36
|
inline = false,
|
|
31
37
|
fieldDecorator,
|
|
38
|
+
fieldEvents,
|
|
32
39
|
...rest
|
|
33
40
|
}: SilkeFormSchemaProps<T>) {
|
|
34
41
|
return (
|
|
35
42
|
<SilkeSchemaContext context={{ ...context, value: context.value ?? value }}>
|
|
36
|
-
<SilkeSchemaDecoratorProvider decorator={fieldDecorator}>
|
|
43
|
+
<SilkeSchemaDecoratorProvider decorator={fieldDecorator} events={fieldEvents}>
|
|
37
44
|
<SilkeForm {...rest} value={value}>
|
|
38
45
|
<TextFieldContext size="s" kind="default" inline={inline}>
|
|
39
46
|
<SilkeSchemaFields schema={schema} value={value} {...rest} />
|
|
@@ -10,22 +10,43 @@ import React, { createContext, ReactNode, useContext } from 'react';
|
|
|
10
10
|
*/
|
|
11
11
|
export type SilkeSchemaFieldDecorator = (field: VevProps, path?: string) => ReactNode;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Told when the pointer enters or leaves a field's row, and when focus enters or leaves it, with
|
|
15
|
+
* the field and its path, so the host can point at what the field edits (eg on a canvas). Rows
|
|
16
|
+
* of a layout, group, popover or divider hold other rows, which report themselves.
|
|
17
|
+
*/
|
|
18
|
+
export interface SilkeSchemaFieldEvents {
|
|
19
|
+
onHover?: (field: VevProps, path: string | undefined, isOver: boolean) => void;
|
|
20
|
+
onFocus?: (field: VevProps, path: string | undefined, isFocused: boolean) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
const DecoratorContext = createContext<SilkeSchemaFieldDecorator | undefined>(undefined);
|
|
24
|
+
const EventsContext = createContext<SilkeSchemaFieldEvents | undefined>(undefined);
|
|
14
25
|
|
|
15
26
|
export function SilkeSchemaDecoratorProvider({
|
|
16
27
|
decorator,
|
|
28
|
+
events,
|
|
17
29
|
children,
|
|
18
30
|
}: {
|
|
19
31
|
decorator?: SilkeSchemaFieldDecorator;
|
|
32
|
+
events?: SilkeSchemaFieldEvents;
|
|
20
33
|
children: ReactNode;
|
|
21
34
|
}) {
|
|
22
|
-
return
|
|
35
|
+
return (
|
|
36
|
+
<DecoratorContext.Provider value={decorator}>
|
|
37
|
+
<EventsContext.Provider value={events}>{children}</EventsContext.Provider>
|
|
38
|
+
</DecoratorContext.Provider>
|
|
39
|
+
);
|
|
23
40
|
}
|
|
24
41
|
|
|
25
42
|
export function useSchemaFieldDecorator(): SilkeSchemaFieldDecorator | undefined {
|
|
26
43
|
return useContext(DecoratorContext);
|
|
27
44
|
}
|
|
28
45
|
|
|
46
|
+
export function useSchemaFieldEvents(): SilkeSchemaFieldEvents | undefined {
|
|
47
|
+
return useContext(EventsContext);
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
/** Joins a parent path with a field name or an array index. */
|
|
30
51
|
export function joinSchemaPath(path: string | undefined, segment: string | number): string {
|
|
31
52
|
return path === undefined ? String(segment) : `${path}.${segment}`;
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { safeEvalFunction } from './safe-eval';
|
|
12
12
|
import { isEvalCallback } from './schema-utils';
|
|
13
13
|
import { useSchemaContext } from './silke-schema-context';
|
|
14
|
-
import { useSchemaFieldDecorator } from './silke-schema-decorator';
|
|
14
|
+
import { useSchemaFieldDecorator, useSchemaFieldEvents } from './silke-schema-decorator';
|
|
15
15
|
import { SilkeDivider } from '../silke-divider';
|
|
16
16
|
|
|
17
17
|
import ArrayField from './fields/array-field';
|
|
@@ -43,6 +43,9 @@ type SilkeSchemaFieldProps = {
|
|
|
43
43
|
path?: string;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
/** Field types with no name of their own: their fields are the ones with rows. */
|
|
47
|
+
const UNNAMED_TYPES = ['layout', 'divider', 'group', 'popover'];
|
|
48
|
+
|
|
46
49
|
const SCHEMA_FIELD_COMPONENTS: Partial<SchemaFieldComponents> = {
|
|
47
50
|
string: StringField,
|
|
48
51
|
color: ColorField,
|
|
@@ -75,6 +78,7 @@ export function SilkeSchemaField({
|
|
|
75
78
|
}: SilkeSchemaFieldProps) {
|
|
76
79
|
const extendedFields = useExtendedFields();
|
|
77
80
|
const decorator = useSchemaFieldDecorator();
|
|
81
|
+
const events = useSchemaFieldEvents();
|
|
78
82
|
|
|
79
83
|
const { value, onChange } = useFormField({ name: field?.name, value: fieldValue });
|
|
80
84
|
|
|
@@ -89,7 +93,7 @@ export function SilkeSchemaField({
|
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
if (!field?.name && !
|
|
96
|
+
if (!field?.name && !UNNAMED_TYPES.includes(field?.type))
|
|
93
97
|
return (
|
|
94
98
|
<SilkeAlertBanner
|
|
95
99
|
kind="error"
|
|
@@ -113,6 +117,9 @@ export function SilkeSchemaField({
|
|
|
113
117
|
};
|
|
114
118
|
|
|
115
119
|
const decoration = decorator?.(field, path);
|
|
120
|
+
// Rows of unnamed fields hold other rows, which report themselves.
|
|
121
|
+
const reportedEvents = field.name && !UNNAMED_TYPES.includes(field.type) ? events : undefined;
|
|
122
|
+
const { onHover, onFocus } = reportedEvents || {};
|
|
116
123
|
|
|
117
124
|
return (
|
|
118
125
|
<>
|
|
@@ -126,6 +133,10 @@ export function SilkeSchemaField({
|
|
|
126
133
|
flex
|
|
127
134
|
vAlign={decoration ? 'end' : undefined}
|
|
128
135
|
gap={decoration ? 'xs' : undefined}
|
|
136
|
+
onMouseEnter={onHover && (() => onHover(field, path, true))}
|
|
137
|
+
onMouseLeave={onHover && (() => onHover(field, path, false))}
|
|
138
|
+
onFocusCapture={onFocus && (() => onFocus(field, path, true))}
|
|
139
|
+
onBlurCapture={onFocus && (() => onFocus(field, path, false))}
|
|
129
140
|
>
|
|
130
141
|
<SilkeVariablesWrapper
|
|
131
142
|
component={Field}
|
|
@@ -17,7 +17,7 @@ function isEmojiIcon(icon: SilkeIconProps['icon']): icon is IEmojiIcon {
|
|
|
17
17
|
return isObject(icon) && 'type' in icon;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function SilkeIcon({ icon, className, color, ...rest }: SilkeIconProps): JSX.Element {
|
|
20
|
+
export function SilkeIcon({ icon, className, color, ...rest }: SilkeIconProps): React.JSX.Element {
|
|
21
21
|
let cl = styles.icon;
|
|
22
22
|
if (color) cl += ' ' + 'color-' + color;
|
|
23
23
|
if (className) cl += ' ' + className;
|
|
@@ -3,7 +3,7 @@ import React, { useMemo } from 'react';
|
|
|
3
3
|
import { SilkeBox } from '../silke-box';
|
|
4
4
|
import { SilkeDivider } from '../silke-divider';
|
|
5
5
|
import { SilkeTextSmall } from '../silke-text';
|
|
6
|
-
import type { SilkeListItemType } from './types';
|
|
6
|
+
import type { SilkeListItemData, SilkeListItemType } from './types';
|
|
7
7
|
import { groupSilkeListItems, isSilkeListItem } from './utils';
|
|
8
8
|
import { SilkeListItem } from './silke-list-item';
|
|
9
9
|
import { SilkeSortableItemWrapper } from '../silke-sortable-list/silke-sortable-item-wrapper';
|
|
@@ -23,22 +23,29 @@ type SilkeListProps = {
|
|
|
23
23
|
onSort?: (items: SilkeListItemType[]) => void;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export function SilkeList({
|
|
26
|
+
export function SilkeList({
|
|
27
|
+
items,
|
|
28
|
+
size,
|
|
29
|
+
gap,
|
|
30
|
+
maxHeight,
|
|
31
|
+
sortable,
|
|
32
|
+
disabled,
|
|
33
|
+
onSelect,
|
|
34
|
+
onSort,
|
|
35
|
+
}: SilkeListProps) {
|
|
27
36
|
const resolvedItems = typeof items === 'function' ? items() : items;
|
|
28
37
|
const groupedItems = groupSilkeListItems(resolvedItems);
|
|
29
38
|
const hasGroups = groupedItems.some((g) => g.groupLabel);
|
|
30
39
|
const listId = useMemo(() => generateGuid(), []);
|
|
31
40
|
|
|
32
41
|
const renderItem = (item: SilkeListItemType, index: number, keyPrefix: string) => {
|
|
42
|
+
// groupLabel is only used for grouping above; it must not reach the DOM.
|
|
43
|
+
const { groupLabel: _groupLabel, ...itemProps } = isSilkeListItem(item) ? item : {};
|
|
33
44
|
const content = (
|
|
34
|
-
<SilkeBox
|
|
35
|
-
tag="li"
|
|
36
|
-
key={`${keyPrefix}-${index}`}
|
|
37
|
-
hPad={item === 'divider' ? 'none' : 'xs'}
|
|
38
|
-
>
|
|
45
|
+
<SilkeBox tag="li" key={`${keyPrefix}-${index}`} hPad={item === 'divider' ? 'none' : 'xs'}>
|
|
39
46
|
{isSilkeListItem(item) ? (
|
|
40
47
|
<SilkeListItem
|
|
41
|
-
{...
|
|
48
|
+
{...(itemProps as SilkeListItemData)}
|
|
42
49
|
gap={gap}
|
|
43
50
|
size={size}
|
|
44
51
|
maxHeight={maxHeight}
|
|
@@ -36,7 +36,7 @@ export function SilkeObjectField<T extends Record<string, any>>(props: SilkeObje
|
|
|
36
36
|
const [errors, setErrors] = useState<ErrorMap<T>>({});
|
|
37
37
|
|
|
38
38
|
// Need to copy errors and value into ref so the un-registerField can clear errors and value related to a field
|
|
39
|
-
const errorsRef = useRef<ErrorMap<T
|
|
39
|
+
const errorsRef = useRef<ErrorMap<T> | null>(null);
|
|
40
40
|
const valueRef = useRef<T>(value);
|
|
41
41
|
errorsRef.current = errors;
|
|
42
42
|
valueRef.current = value || {};
|
|
@@ -27,9 +27,9 @@ export type PopoverOrigin =
|
|
|
27
27
|
| 'center-left'
|
|
28
28
|
| 'center-center';
|
|
29
29
|
|
|
30
|
-
export type PopoverAnchor = React.RefObject<HTMLElement> | [x: number, y: number];
|
|
30
|
+
export type PopoverAnchor = React.RefObject<HTMLElement | null> | [x: number, y: number];
|
|
31
31
|
|
|
32
|
-
const PopoverWrapperContext = React.createContext<React.RefObject<HTMLElement
|
|
32
|
+
const PopoverWrapperContext = React.createContext<React.RefObject<HTMLElement> | null>(null);
|
|
33
33
|
export const SilkePopoverContext = ({
|
|
34
34
|
target,
|
|
35
35
|
children,
|
|
@@ -163,7 +163,7 @@ export function SilkePopover({
|
|
|
163
163
|
useMouseDown(
|
|
164
164
|
(e) => {
|
|
165
165
|
const el = targetRef.current;
|
|
166
|
-
const parentPopover = parentContext
|
|
166
|
+
const parentPopover = parentContext?.current;
|
|
167
167
|
|
|
168
168
|
if (!el || !onRequestClose || !isMountedAndOpenRef.current) return;
|
|
169
169
|
// if click inside parent popover then close
|
|
@@ -217,11 +217,13 @@ export function applyPopoverStyles(
|
|
|
217
217
|
): void {
|
|
218
218
|
let width: string | null = null;
|
|
219
219
|
let height: string | null = null;
|
|
220
|
+
let anchorPosition: [number, number] = [0, 0];
|
|
221
|
+
|
|
220
222
|
if (isRefObject(anchor)) {
|
|
221
223
|
if (anchor.current) {
|
|
222
224
|
const anchorRect = anchor.current.getBoundingClientRect();
|
|
223
225
|
const [originX, originY] = getOriginOffset(anchorOrigin);
|
|
224
|
-
|
|
226
|
+
anchorPosition = [
|
|
225
227
|
anchorRect.left + offsetX + anchorRect.width * originX,
|
|
226
228
|
anchorRect.top + offsetY + anchorRect.height * originY,
|
|
227
229
|
];
|
|
@@ -229,20 +231,22 @@ export function applyPopoverStyles(
|
|
|
229
231
|
if (matchAnchorWidth) width = anchorRect.width + 'px';
|
|
230
232
|
if (matchAnchorHeight) height = anchorRect.height + 'px';
|
|
231
233
|
} else {
|
|
232
|
-
|
|
234
|
+
anchorPosition = [0, 0];
|
|
233
235
|
}
|
|
234
|
-
} else if (Array.isArray(anchor))
|
|
236
|
+
} else if (Array.isArray(anchor)) {
|
|
237
|
+
anchorPosition = anchor.slice() as [number, number];
|
|
238
|
+
}
|
|
235
239
|
|
|
236
240
|
const targetRect = target.getBoundingClientRect();
|
|
237
241
|
const [originX, originY] = getOriginOffset(targetOrigin);
|
|
238
242
|
const maxX = window.innerWidth - targetRect.width;
|
|
239
243
|
const maxY = window.innerHeight - targetRect.height;
|
|
240
|
-
|
|
241
|
-
|
|
244
|
+
anchorPosition[0] = clamp(anchorPosition[0] + offsetX - targetRect.width * originX, 0, maxX);
|
|
245
|
+
anchorPosition[1] = clamp(anchorPosition[1] + offsetY - targetRect.height * originY, 0, maxY);
|
|
242
246
|
if (translateAnimation) target.style.transition = 'all 0.1s ease-out';
|
|
243
247
|
Object.assign(target.style, {
|
|
244
|
-
left:
|
|
245
|
-
top:
|
|
248
|
+
left: anchorPosition[0] + 'px',
|
|
249
|
+
top: anchorPosition[1] + 'px',
|
|
246
250
|
width,
|
|
247
251
|
height,
|
|
248
252
|
...(pointerEventsNone && { pointerEvents: 'none' }),
|
|
@@ -12,7 +12,7 @@ export type PopoverPlacement =
|
|
|
12
12
|
| 'left-start'
|
|
13
13
|
| 'left-end';
|
|
14
14
|
|
|
15
|
-
export type PopoverAnchorNative = React.RefObject<HTMLElement>;
|
|
15
|
+
export type PopoverAnchorNative = React.RefObject<HTMLElement | null>;
|
|
16
16
|
|
|
17
17
|
// ToggleEvent is part of the Popover API but not yet in TypeScript's DOM types
|
|
18
18
|
export interface PopoverToggleEvent extends Event {
|
|
@@ -2,7 +2,7 @@ import { useEffect, type CSSProperties } from 'react';
|
|
|
2
2
|
import type { PopoverAnchorNative, PopoverPlacement } from './types';
|
|
3
3
|
|
|
4
4
|
export function usePopoverPositioning(
|
|
5
|
-
popoverRef: React.RefObject<HTMLDivElement>,
|
|
5
|
+
popoverRef: React.RefObject<HTMLDivElement | null>,
|
|
6
6
|
anchor: PopoverAnchorNative | undefined,
|
|
7
7
|
anchorName: string,
|
|
8
8
|
placementStyles: ExtendedCSSProperties,
|