From 29983db3d41cdb590a0743444917f1d55a414b2f Mon Sep 17 00:00:00 2001 From: anubra266 Date: Tue, 29 Aug 2023 21:07:13 +0100 Subject: [PATCH 1/3] chore: Rename `file-upload` to `file-picker` --- .changeset/big-bears-study.md | 5 + .xstate/file-picker.js | 85 ++++++++++++++++ examples/next-ts/package.json | 4 +- .../{file-upload.tsx => file-picker.tsx} | 12 +-- examples/nuxt-ts/package.json | 4 +- .../{file-upload.vue => file-picker.vue} | 12 +-- examples/shadow-dom/package.json | 4 +- examples/solid-ts/package.json | 4 +- .../{file-upload.tsx => file-picker.tsx} | 12 +-- examples/solid-ts/src/routes.ts | 2 +- examples/vue-ts/package.json | 4 +- examples/vue-ts/src/pages/file-picker.tsx | 58 +++++++++++ examples/vue-ts/src/pages/file-upload.tsx | 14 +-- examples/vue-ts/src/routes.ts | 2 +- .../{file-upload.tsx => file-picker.tsx} | 2 +- .../anatomy-icons/src/components/index.ts | 4 +- packages/docs/api.json | 4 +- .../{file-upload => file-picker}/CHANGELOG.md | 2 +- .../{file-upload => file-picker}/README.md | 8 +- .../{file-upload => file-picker}/package.json | 10 +- .../src/file-picker.anatomy.ts} | 2 +- .../src/file-picker.connect.ts} | 8 +- .../file-picker/src/file-picker.dom.ts | 11 +++ .../src/file-picker.machine.ts} | 8 +- .../src/file-picker.types.ts} | 0 .../src/file-picker.utils.ts} | 2 +- packages/machines/file-picker/src/index.ts | 4 + .../tsconfig.json | 0 .../file-upload/src/file-upload.dom.ts | 11 --- packages/machines/file-upload/src/index.ts | 4 - pnpm-lock.yaml | 26 ++--- shared/src/controls.ts | 2 +- shared/src/routes.ts | 2 +- shared/src/style.css | 8 +- .../{file-upload.tsx => file-picker.tsx} | 8 +- website/components/showcase.tsx | 6 +- .../{file-upload.mdx => file-picker.mdx} | 97 +++++++++---------- .../react/file-picker/installation.mdx | 5 + .../{file-upload => file-picker}/usage.mdx | 8 +- .../react/file-upload/installation.mdx | 5 - .../solid/file-picker/installation.mdx | 5 + .../{file-upload => file-picker}/usage.mdx | 8 +- .../solid/file-upload/installation.mdx | 5 - .../vue-jsx/file-picker/installation.mdx | 5 + .../{file-upload => file-picker}/usage.mdx | 10 +- .../vue-jsx/file-upload/installation.mdx | 5 - .../vue-sfc/file-picker/installation.mdx | 5 + .../{file-upload => file-picker}/usage.mdx | 6 +- .../vue-sfc/file-upload/installation.mdx | 5 - website/package.json | 4 +- website/sidebar.config.ts | 2 +- 51 files changed, 338 insertions(+), 191 deletions(-) create mode 100644 .changeset/big-bears-study.md create mode 100644 .xstate/file-picker.js rename examples/next-ts/pages/{file-upload.tsx => file-picker.tsx} (78%) rename examples/nuxt-ts/pages/{file-upload.vue => file-picker.vue} (74%) rename examples/solid-ts/src/pages/{file-upload.tsx => file-picker.tsx} (80%) create mode 100644 examples/vue-ts/src/pages/file-picker.tsx rename packages/anatomy-icons/src/components/{file-upload.tsx => file-picker.tsx} (99%) rename packages/machines/{file-upload => file-picker}/CHANGELOG.md (99%) rename packages/machines/{file-upload => file-picker}/README.md (68%) rename packages/machines/{file-upload => file-picker}/package.json (89%) rename packages/machines/{file-upload/src/file-upload.anatomy.ts => file-picker/src/file-picker.anatomy.ts} (68%) rename packages/machines/{file-upload/src/file-upload.connect.ts => file-picker/src/file-picker.connect.ts} (95%) create mode 100644 packages/machines/file-picker/src/file-picker.dom.ts rename packages/machines/{file-upload/src/file-upload.machine.ts => file-picker/src/file-picker.machine.ts} (96%) rename packages/machines/{file-upload/src/file-upload.types.ts => file-picker/src/file-picker.types.ts} (100%) rename packages/machines/{file-upload/src/file-upload.utils.ts => file-picker/src/file-picker.utils.ts} (97%) create mode 100644 packages/machines/file-picker/src/index.ts rename packages/machines/{file-upload => file-picker}/tsconfig.json (100%) delete mode 100644 packages/machines/file-upload/src/file-upload.dom.ts delete mode 100644 packages/machines/file-upload/src/index.ts rename website/components/machines/{file-upload.tsx => file-picker.tsx} (87%) rename website/data/components/{file-upload.mdx => file-picker.mdx} (58%) create mode 100644 website/data/snippets/react/file-picker/installation.mdx rename website/data/snippets/react/{file-upload => file-picker}/usage.mdx (79%) delete mode 100644 website/data/snippets/react/file-upload/installation.mdx create mode 100644 website/data/snippets/solid/file-picker/installation.mdx rename website/data/snippets/solid/{file-upload => file-picker}/usage.mdx (81%) delete mode 100644 website/data/snippets/solid/file-upload/installation.mdx create mode 100644 website/data/snippets/vue-jsx/file-picker/installation.mdx rename website/data/snippets/vue-jsx/{file-upload => file-picker}/usage.mdx (79%) delete mode 100644 website/data/snippets/vue-jsx/file-upload/installation.mdx create mode 100644 website/data/snippets/vue-sfc/file-picker/installation.mdx rename website/data/snippets/vue-sfc/{file-upload => file-picker}/usage.mdx (77%) delete mode 100644 website/data/snippets/vue-sfc/file-upload/installation.mdx diff --git a/.changeset/big-bears-study.md b/.changeset/big-bears-study.md new file mode 100644 index 0000000000..0a6aeb89e1 --- /dev/null +++ b/.changeset/big-bears-study.md @@ -0,0 +1,5 @@ +--- +"@zag-js/file-picker": 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 @@