From 82b6071b06ecfda3c04b563b80b1f3f0eb6c32ff Mon Sep 17 00:00:00 2001 From: jp calvo Date: Sat, 12 Oct 2024 21:18:05 +0800 Subject: [PATCH] chore: expose createUniqueId and createContext --- packages/core/package.json | 8 ++++++++ .../src/lib/accordion/create-accordion.svelte.ts | 8 ++++---- .../lib/alert-dialog/create-alert-dialog.svelte.ts | 6 +++--- packages/core/src/lib/avatar/create-avatar.svelte.ts | 8 ++++---- .../core/src/lib/carousel/create-carousel.svelte.ts | 8 ++++---- .../core/src/lib/checkbox/create-checkbox.svelte.ts | 10 +++++----- .../src/lib/clipboard/create-clipboard.svelte.ts | 8 ++++---- .../src/lib/collapsible/create-collapsible.svelte.ts | 6 +++--- .../lib/color-picker/create-color-picker.svelte.ts | 4 ++-- .../core/src/lib/combobox/combobox-item-group.svelte | 4 ++-- .../core/src/lib/combobox/create-combobox.svelte.ts | 4 ++-- packages/core/src/lib/create-unique-id.ts | 3 +++ .../src/lib/date-picker/create-date-picker.svelte.ts | 7 ++++--- packages/core/src/lib/dialog/create-dialog.svelte.ts | 6 +++--- packages/core/src/lib/drawer/create-drawer.svelte.ts | 6 +++--- .../core/src/lib/editable/create-editable.svelte.ts | 6 +++--- packages/core/src/lib/field/create-field.svelte.ts | 4 ++-- .../src/lib/file-upload/create-file-upload.svelte.ts | 12 ++++++------ .../floating-panel/create-floating-panel.svelte.ts | 8 ++++---- .../src/lib/hover-card/create-hover-card.svelte.ts | 6 +++--- packages/core/src/lib/index.ts | 5 ++++- packages/core/src/lib/menu/create-menu.svelte.ts | 6 +++--- packages/core/src/lib/menu/menu-item-group.svelte | 4 ++-- .../lib/number-input/create-number-input.svelte.ts | 12 ++++++------ .../src/lib/pagination/create-pagination.svelte.ts | 8 ++++---- .../src/lib/pin-input/create-pin-input.svelte.ts | 10 +++++----- .../core/src/lib/popover/create-popover.svelte.ts | 6 +++--- .../core/src/lib/progress/create-progress.svelte.ts | 8 ++++---- .../core/src/lib/qr-code/create-qr-code.svelte.ts | 8 ++++---- .../src/lib/radio-group/create-radio-group.svelte.ts | 8 ++++---- .../lib/rating-group/create-rating-group.svelte.ts | 10 +++++----- .../lib/segment-group/create-segment-group.svelte.ts | 8 ++++---- packages/core/src/lib/select/create-select.svelte.ts | 4 ++-- .../core/src/lib/select/select-item-group.svelte | 4 ++-- .../lib/signature-pad/create-signature-pad.svelte.ts | 8 ++++---- packages/core/src/lib/slider/create-slider.svelte.ts | 8 ++++---- .../core/src/lib/splitter/create-splitter.svelte.ts | 8 +++++--- packages/core/src/lib/steps/create-steps.svelte.ts | 8 ++++---- packages/core/src/lib/switch/create-switch.svelte.ts | 10 +++++----- packages/core/src/lib/tabs/create-tabs.svelte.ts | 8 ++++---- .../src/lib/tags-input/create-tags-input.svelte.ts | 10 +++++----- .../src/lib/time-picker/create-time-picker.svelte.ts | 6 +++--- packages/core/src/lib/timer/create-timer.svelte.ts | 8 ++++---- packages/core/src/lib/toast/create-toaster.svelte.ts | 8 +++----- .../lib/toggle-group/create-toggle-group.svelte.ts | 8 ++++---- .../core/src/lib/tooltip/create-tooltip.svelte.ts | 6 +++--- packages/core/src/lib/tour/create-tour.svelte.ts | 6 +++--- .../src/lib/tree-view/create-tree-view.svelte.ts | 8 ++++---- 48 files changed, 179 insertions(+), 164 deletions(-) create mode 100644 packages/core/src/lib/create-unique-id.ts diff --git a/packages/core/package.json b/packages/core/package.json index 6f4df04c..f32aef9d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -214,6 +214,14 @@ "./merge-props": { "types": "./dist/merge-props.d.ts", "import": "./dist/merge-props.js" + }, + "./create-context": { + "types": "./dist/create-context.d.ts", + "import": "./dist/create-context.js" + }, + "./create-unique-id": { + "types": "./dist/create-unique-id.d.ts", + "import": "./dist/create-unique-id.js" } }, "files": [ diff --git a/packages/core/src/lib/accordion/create-accordion.svelte.ts b/packages/core/src/lib/accordion/create-accordion.svelte.ts index 0cc81049..e11dd59a 100644 --- a/packages/core/src/lib/accordion/create-accordion.svelte.ts +++ b/packages/core/src/lib/accordion/create-accordion.svelte.ts @@ -1,8 +1,8 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import {getLocaleContext} from '$lib/locale-provider/local-provider-context.svelte.js'; import * as accordion from '@zag-js/accordion'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; export interface CreateAccordionProps extends Omit { @@ -17,13 +17,13 @@ export function createAccordion( const locale = getLocaleContext(); const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: accordion.Context = reflect(() => ({ - ...props, - id: props.id ?? id, + id, dir: locale?.dir, getRootNode: environment?.getRootNode, + ...props, })); const [state, send] = useMachine(accordion.machine(context), {context}); diff --git a/packages/core/src/lib/alert-dialog/create-alert-dialog.svelte.ts b/packages/core/src/lib/alert-dialog/create-alert-dialog.svelte.ts index b2540c87..ea2c6380 100644 --- a/packages/core/src/lib/alert-dialog/create-alert-dialog.svelte.ts +++ b/packages/core/src/lib/alert-dialog/create-alert-dialog.svelte.ts @@ -1,9 +1,9 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import {getLocaleContext} from '$lib/locale-provider/local-provider-context.svelte.js'; import {mergeProps} from '$lib/merge-props.js'; import * as dialog from '@zag-js/dialog'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; import {parts} from './alert-dialog-anatomy.js'; export interface CreateAlertDialogProps @@ -23,15 +23,15 @@ export function createAlertDialog( const locale = getLocaleContext(); const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: dialog.Context = reflect(() => ({ id, dir: locale?.dir, role: 'alertdialog', - ...props, getRootNode: environment?.getRootNode, 'open.controlled': props.openControlled, + ...props, })); const [state, send] = useMachine(dialog.machine(context), {context}); diff --git a/packages/core/src/lib/avatar/create-avatar.svelte.ts b/packages/core/src/lib/avatar/create-avatar.svelte.ts index 950052ea..e7595718 100644 --- a/packages/core/src/lib/avatar/create-avatar.svelte.ts +++ b/packages/core/src/lib/avatar/create-avatar.svelte.ts @@ -1,8 +1,8 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import {getLocaleContext} from '$lib/locale-provider/local-provider-context.svelte.js'; import * as avatar from '@zag-js/avatar'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; export interface CreateAvatarProps extends Omit { @@ -15,13 +15,13 @@ export function createAvatar(props: CreateAvatarProps): CreateAvatarReturn { const locale = getLocaleContext(); const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: avatar.Context = reflect(() => ({ - ...props, - id: props.id ?? id, + id, dir: locale?.dir, getRootNode: environment?.getRootNode, + ...props, })); const [state, send] = useMachine(avatar.machine(context), {context}); diff --git a/packages/core/src/lib/carousel/create-carousel.svelte.ts b/packages/core/src/lib/carousel/create-carousel.svelte.ts index dee1e7da..e481971c 100644 --- a/packages/core/src/lib/carousel/create-carousel.svelte.ts +++ b/packages/core/src/lib/carousel/create-carousel.svelte.ts @@ -1,8 +1,8 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import {getLocaleContext} from '$lib/locale-provider/local-provider-context.svelte.js'; import * as carousel from '@zag-js/carousel'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; export interface CreateCarouselProps extends Omit { @@ -17,13 +17,13 @@ export function createCarousel( const locale = getLocaleContext(); const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: carousel.Context = reflect(() => ({ - ...props, - id: props.id ?? id, + id, dir: locale?.dir, getRootNode: environment?.getRootNode, + ...props, })); const [state, send] = useMachine(carousel.machine(context), {context}); diff --git a/packages/core/src/lib/checkbox/create-checkbox.svelte.ts b/packages/core/src/lib/checkbox/create-checkbox.svelte.ts index b0e7b49a..9dea14c9 100644 --- a/packages/core/src/lib/checkbox/create-checkbox.svelte.ts +++ b/packages/core/src/lib/checkbox/create-checkbox.svelte.ts @@ -1,9 +1,9 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import {getFieldContext} from '$lib/field/field-context.svelte.js'; import {getLocaleContext} from '$lib/locale-provider/local-provider-context.svelte.js'; import * as checkbox from '@zag-js/checkbox'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; export interface CreateCheckboxProps extends Omit { @@ -19,9 +19,11 @@ export function createCheckbox( const locale = getLocaleContext(); const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: checkbox.Context = reflect(() => ({ + id, + dir: locale?.dir, ids: { label: field?.ids.label, hiddenInput: field?.ids.control, @@ -30,10 +32,8 @@ export function createCheckbox( disabled: field?.disabled, readOnly: field?.readOnly, required: field?.required, - ...props, - id: props.id ?? id, - dir: locale?.dir, getRootNode: environment?.getRootNode, + ...props, })); const [state, send] = useMachine(checkbox.machine(context), {context}); diff --git a/packages/core/src/lib/clipboard/create-clipboard.svelte.ts b/packages/core/src/lib/clipboard/create-clipboard.svelte.ts index 66ff98c0..03f44cc2 100644 --- a/packages/core/src/lib/clipboard/create-clipboard.svelte.ts +++ b/packages/core/src/lib/clipboard/create-clipboard.svelte.ts @@ -1,7 +1,7 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import * as clipboard from '@zag-js/clipboard'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; export interface CreateClipboardProps extends Omit { @@ -15,12 +15,12 @@ export function createClipboard( ): CreateClipboardReturn { const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: clipboard.Context = reflect(() => ({ - ...props, - id: props.id ?? id, + id, getRootNode: environment?.getRootNode, + ...props, })); const [state, send] = useMachine(clipboard.machine(context), {context}); diff --git a/packages/core/src/lib/collapsible/create-collapsible.svelte.ts b/packages/core/src/lib/collapsible/create-collapsible.svelte.ts index fb8036d7..a568b2d2 100644 --- a/packages/core/src/lib/collapsible/create-collapsible.svelte.ts +++ b/packages/core/src/lib/collapsible/create-collapsible.svelte.ts @@ -1,8 +1,8 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import {getLocaleContext} from '$lib/locale-provider/local-provider-context.svelte.js'; import * as collapsible from '@zag-js/collapsible'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; export interface CreateCollapsibleProps extends Omit< @@ -21,14 +21,14 @@ export function createCollapsible( const locale = getLocaleContext(); const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: collapsible.Context = reflect(() => ({ id, dir: locale?.dir, - ...props, getRootNode: environment?.getRootNode, 'open.controlled': props.openControlled, + ...props, })); const [state, send] = useMachine(collapsible.machine(context), {context}); diff --git a/packages/core/src/lib/color-picker/create-color-picker.svelte.ts b/packages/core/src/lib/color-picker/create-color-picker.svelte.ts index da6cc59e..16fd5cbc 100644 --- a/packages/core/src/lib/color-picker/create-color-picker.svelte.ts +++ b/packages/core/src/lib/color-picker/create-color-picker.svelte.ts @@ -1,9 +1,9 @@ +import {createUniqueId} from '$lib/create-unique-id.js'; import {getEnvironmentContext} from '$lib/environment-provider/enviroment-provider-context.svelte.js'; import {getLocaleContext} from '$lib/locale-provider/local-provider-context.svelte.js'; import type {GenericObject} from '$lib/types.js'; import * as colorPicker from '@zag-js/color-picker'; import {normalizeProps, reflect, useMachine} from '@zag-js/svelte'; -import {uid} from 'uid'; import {parts} from './color-picker-anatomy.js'; type Omitted = 'id' | 'dir' | 'value' | 'getRootNode' | 'open.controlled'; @@ -26,7 +26,7 @@ export function createColorPicker( const locale = getLocaleContext(); const environment = getEnvironmentContext(); - const id = uid(); + const id = createUniqueId(); const context: colorPicker.Context = $derived.by(() => ({ id, diff --git a/packages/core/src/lib/combobox/combobox-item-group.svelte b/packages/core/src/lib/combobox/combobox-item-group.svelte index 74a90499..32a02492 100644 --- a/packages/core/src/lib/combobox/combobox-item-group.svelte +++ b/packages/core/src/lib/combobox/combobox-item-group.svelte @@ -6,8 +6,8 @@