diff --git a/.changeset/big-bears-study.md b/.changeset/big-bears-study.md new file mode 100644 index 0000000000..f06f8e357b --- /dev/null +++ b/.changeset/big-bears-study.md @@ -0,0 +1,6 @@ +--- +"@zag-js/file-picker": patch +"@zag-js/anatomy-icons": patch +--- + +Rename `file-upload` to `file-picker` diff --git a/.xstate/file-picker.js b/.xstate/file-picker.js new file mode 100644 index 0000000000..63c33c879d --- /dev/null +++ b/.xstate/file-picker.js @@ -0,0 +1,85 @@ +"use strict"; + +var _xstate = require("xstate"); +const { + actions, + createMachine, + assign +} = _xstate; +const { + choose +} = actions; +const fetchMachine = createMachine({ + id: "filePicker", + initial: "idle", + context: { + "!isWithinRange": false + }, + on: { + "FILES.SET": { + actions: ["setFilesFromEvent"] + }, + "FILE.DELETE": { + actions: ["removeFile"] + } + }, + on: { + UPDATE_CONTEXT: { + actions: "updateContext" + } + }, + states: { + idle: { + on: { + OPEN: "open", + "DROPZONE.CLICK": "open", + "DROPZONE.FOCUS": "focused", + "DROPZONE.DRAG_OVER": [{ + cond: "!isWithinRange", + target: "dragging", + actions: ["setInvalid"] + }, { + target: "dragging" + }] + } + }, + focused: { + on: { + OPEN: "open", + "DROPZONE.CLICK": "open", + "DROPZONE.ENTER": "open", + "DROPZONE.BLUR": "idle" + } + }, + dragging: { + on: { + "DROPZONE.DROP": { + target: "idle", + actions: ["clearInvalid", "setFilesFromEvent"] + }, + "DROPZONE.DRAG_LEAVE": { + target: "idle", + actions: ["clearInvalid"] + } + } + }, + open: { + activities: ["trackWindowFocus"], + entry: ["openFilePicker"], + on: { + CLOSE: "idle" + } + } + } +}, { + actions: { + updateContext: assign((context, event) => { + return { + [event.contextKey]: true + }; + }) + }, + guards: { + "!isWithinRange": ctx => ctx["!isWithinRange"] + } +}); \ No newline at end of file diff --git a/examples/next-ts/package.json b/examples/next-ts/package.json index 726c3765be..1527cde335 100644 --- a/examples/next-ts/package.json +++ b/examples/next-ts/package.json @@ -33,7 +33,7 @@ "@zag-js/editable": "workspace:*", "@zag-js/element-rect": "workspace:*", "@zag-js/element-size": "workspace:*", - "@zag-js/file-upload": "workspace:*", + "@zag-js/file-picker": "workspace:*", "@zag-js/focus-scope": "workspace:*", "@zag-js/focus-visible": "workspace:*", "@zag-js/form-utils": "workspace:*", @@ -90,4 +90,4 @@ "typescript": "5.1.6" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/examples/next-ts/pages/file-upload.tsx b/examples/next-ts/pages/file-picker.tsx similarity index 78% rename from examples/next-ts/pages/file-upload.tsx rename to examples/next-ts/pages/file-picker.tsx index 477730a6b3..6ec0ed9dd6 100644 --- a/examples/next-ts/pages/file-upload.tsx +++ b/examples/next-ts/pages/file-picker.tsx @@ -1,19 +1,19 @@ -import * as fileUpload from "@zag-js/file-upload" +import * as filePicker from "@zag-js/file-picker" import { normalizeProps, useMachine } from "@zag-js/react" -import { fileUploadControls, formatFileSize } from "@zag-js/shared" +import { filePickerControls, formatFileSize } from "@zag-js/shared" import { useId } from "react" import { StateVisualizer } from "../components/state-visualizer" import { Toolbar } from "../components/toolbar" import { useControls } from "../hooks/use-controls" export default function Page() { - const controls = useControls(fileUploadControls) - const [state, send] = useMachine(fileUpload.machine({ id: useId() }), { context: controls.context }) - const api = fileUpload.connect(state, send, normalizeProps) + const controls = useControls(filePickerControls) + const [state, send] = useMachine(filePicker.machine({ id: useId() }), { context: controls.context }) + const api = filePicker.connect(state, send, normalizeProps) return ( <> -
+
diff --git a/examples/nuxt-ts/package.json b/examples/nuxt-ts/package.json index d349ad87a7..34e5e1c8bb 100644 --- a/examples/nuxt-ts/package.json +++ b/examples/nuxt-ts/package.json @@ -31,7 +31,7 @@ "@zag-js/editable": "workspace:*", "@zag-js/element-rect": "workspace:*", "@zag-js/element-size": "workspace:*", - "@zag-js/file-upload": "workspace:*", + "@zag-js/file-picker": "workspace:*", "@zag-js/focus-scope": "workspace:*", "@zag-js/focus-visible": "workspace:*", "@zag-js/form-utils": "workspace:*", @@ -80,4 +80,4 @@ "@types/node": "^20.5.3", "nuxt": "^3.6.5" } -} +} \ No newline at end of file diff --git a/examples/nuxt-ts/pages/file-upload.vue b/examples/nuxt-ts/pages/file-picker.vue similarity index 74% rename from examples/nuxt-ts/pages/file-upload.vue rename to examples/nuxt-ts/pages/file-picker.vue index 08904795bb..262203a43b 100644 --- a/examples/nuxt-ts/pages/file-upload.vue +++ b/examples/nuxt-ts/pages/file-picker.vue @@ -1,19 +1,19 @@