@colixsystems/widget-sdk 0.335.0 → 0.336.0

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/README.md CHANGED
@@ -91,7 +91,20 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
91
91
 
92
92
  ## Status
93
93
 
94
- `v0.335.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
94
+ `v0.336.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
95
+
96
+ ### What's new in 0.336.0 (contract 1.274.0)
97
+
98
+ **A file dropped on `<FilePicker>` on the web is picked, not opened.** The web picker only answered clicks, so a widget that drew a "drag and drop" area inside it let the browser open the dropped file instead. Leaving the app that way loses everything the user had filled in. A file dropped on the picker now reaches `onPick` as if picked. Any file `accept` rules out is left out, and only the first is passed on unless `multiple` is set. A drop is claimed even while the picker is disabled. The new `onDragActiveChange(active)` prop reports a file being dragged over the picker, so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when the new `FilePicker.acceptsDrop` is true (it is false on native). `<FileUpload>` still takes a drop anywhere on its field. The web Player also claims a file dropped outside every drop target, so the browser never replaces the app with it.
99
+
100
+ ```jsx
101
+ const [over, setOver] = useState(false);
102
+ <FilePicker accept="image/*" multiple onPick={addPhotos} onDragActiveChange={setOver}>
103
+ <View style={{ borderStyle: "dashed", borderWidth: 2, borderColor: over ? colors.primary : colors.border }}>
104
+ <Text>{FilePicker.acceptsDrop ? t("drop_or_click", "Drop photos here or click to choose") : t("tap_to_choose", "Tap to choose photos")}</Text>
105
+ </View>
106
+ </FilePicker>
107
+ ```
95
108
 
96
109
  ### What's new in 0.335.0 (contract 1.273.0)
97
110
 
package/dist/contract.cjs CHANGED
@@ -3679,7 +3679,7 @@ const PRIMITIVES = [
3679
3679
  {
3680
3680
  name: "FilePicker",
3681
3681
  description:
3682
- 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3682
+ 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. On the web a file can also be dropped onto the picker: dropped files reach `onPick` as if picked, leaving out any that `accept` rules out (and all but the first unless `multiple`), and `onDragActiveChange(active)` reports a file being dragged over it so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when `FilePicker.acceptsDrop` is true. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3683
3683
  rnComponent: null,
3684
3684
  docsUrl: null,
3685
3685
  },
@@ -7096,7 +7096,9 @@ const CONTRACT = deepFreeze({
7096
7096
  // 1.273.0: additive (sc-17588) — `useAgent(agentRef, { connections: true })`
7097
7097
  // returns `connections`: the signed-in app user's own MCP servers for the
7098
7098
  // agent, with add, test, remove and refresh.
7099
- version: "1.273.0",
7099
+ // 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
7100
+ // through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
7101
+ version: "1.274.0",
7100
7102
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7101
7103
  hooks: HOOKS,
7102
7104
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -3674,7 +3674,7 @@ const PRIMITIVES = [
3674
3674
  {
3675
3675
  name: "FilePicker",
3676
3676
  description:
3677
- 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3677
+ 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. On the web a file can also be dropped onto the picker: dropped files reach `onPick` as if picked, leaving out any that `accept` rules out (and all but the first unless `multiple`), and `onDragActiveChange(active)` reports a file being dragged over it so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when `FilePicker.acceptsDrop` is true. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3678
3678
  rnComponent: null,
3679
3679
  docsUrl: null,
3680
3680
  },
@@ -7091,7 +7091,9 @@ const CONTRACT = deepFreeze({
7091
7091
  // 1.273.0: additive (sc-17588) — `useAgent(agentRef, { connections: true })`
7092
7092
  // returns `connections`: the signed-in app user's own MCP servers for the
7093
7093
  // agent, with add, test, remove and refresh.
7094
- version: "1.273.0",
7094
+ // 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
7095
+ // through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
7096
+ version: "1.274.0",
7095
7097
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7096
7098
  hooks: HOOKS,
7097
7099
  primitives: PRIMITIVES,
@@ -0,0 +1,58 @@
1
+ // The web's file drop target, shared by `<FilePicker>` and `<FileUpload>`.
2
+ // React Native has no events for files dragged onto an app, so native never uses it.
3
+
4
+ import React from "react";
5
+
6
+ // Drops a target already took; read instead of defaultPrevented, which
7
+ // another library's capture listener may set.
8
+ const claimedDrops = new WeakSet();
9
+
10
+ function carriesFiles(event) {
11
+ const types = event.dataTransfer && event.dataTransfer.types;
12
+ return Boolean(types) && Array.from(types).includes("Files");
13
+ }
14
+
15
+ /**
16
+ * The handlers that make an element take dropped files. A drop is always
17
+ * claimed, even while disabled, so the browser never opens the dropped file.
18
+ * The outermost target takes it (capture phase): a `<FilePicker>` inside a
19
+ * `<FileUpload>` field, or inside another picker, leaves the drop to it.
20
+ *
21
+ * @param {{ disabled?: boolean, onFiles: (files: File[]) => void,
22
+ * onActiveChange?: (active: boolean) => void }} options
23
+ */
24
+ export function useFileDropTarget({ disabled, onFiles, onActiveChange }) {
25
+ // Entering a child fires dragleave on the parent; count the depth.
26
+ const depth = React.useRef(0);
27
+ const setActive = (active) => {
28
+ if (typeof onActiveChange === "function") onActiveChange(active);
29
+ };
30
+ return {
31
+ onDragEnter: (event) => {
32
+ if (!carriesFiles(event)) return;
33
+ event.preventDefault();
34
+ depth.current += 1;
35
+ if (!disabled) setActive(true);
36
+ },
37
+ onDragOver: (event) => {
38
+ if (!carriesFiles(event)) return;
39
+ event.preventDefault();
40
+ event.dataTransfer.dropEffect = disabled ? "none" : "copy";
41
+ },
42
+ onDragLeave: (event) => {
43
+ if (!carriesFiles(event)) return;
44
+ depth.current = Math.max(0, depth.current - 1);
45
+ if (depth.current === 0) setActive(false);
46
+ },
47
+ onDropCapture: (event) => {
48
+ if (!carriesFiles(event)) return;
49
+ const native = event.nativeEvent || event;
50
+ const claimedOutside = claimedDrops.has(native);
51
+ claimedDrops.add(native);
52
+ event.preventDefault();
53
+ depth.current = 0;
54
+ setActive(false);
55
+ if (!disabled && !claimedOutside) onFiles(Array.from(event.dataTransfer.files || []));
56
+ },
57
+ };
58
+ }
@@ -10,51 +10,14 @@ import { makeFileUpload } from "./file-upload-view.js";
10
10
  import { FilePicker } from "./filepicker.js";
11
11
  import { Button } from "./button.js";
12
12
  import { Spinner } from "./loading.js";
13
+ import { useFileDropTarget } from "./drop-target.js";
13
14
 
14
15
  const DROP_ZONE_STYLE = { display: "flex", flexDirection: "column", minWidth: 0 };
15
16
 
16
- function carriesFiles(event) {
17
- const types = event.dataTransfer && event.dataTransfer.types;
18
- return Boolean(types) && Array.from(types).includes("Files");
19
- }
20
-
21
- /**
22
- * The field's drop target. A drop is always claimed, even while disabled,
23
- * so the browser never navigates away to the dropped file.
24
- */
17
+ /** The field's drop target: the whole field, not only its button. */
25
18
  function DropZone({ disabled, onFiles, onActiveChange, children }) {
26
- // Entering a child fires dragleave on the parent; count the depth.
27
- const depth = React.useRef(0);
28
- return React.createElement(
29
- "div",
30
- {
31
- style: DROP_ZONE_STYLE,
32
- onDragEnter: (event) => {
33
- if (!carriesFiles(event)) return;
34
- event.preventDefault();
35
- depth.current += 1;
36
- if (!disabled) onActiveChange(true);
37
- },
38
- onDragOver: (event) => {
39
- if (!carriesFiles(event)) return;
40
- event.preventDefault();
41
- event.dataTransfer.dropEffect = disabled ? "none" : "copy";
42
- },
43
- onDragLeave: (event) => {
44
- if (!carriesFiles(event)) return;
45
- depth.current = Math.max(0, depth.current - 1);
46
- if (depth.current === 0) onActiveChange(false);
47
- },
48
- onDrop: (event) => {
49
- if (!carriesFiles(event)) return;
50
- event.preventDefault();
51
- depth.current = 0;
52
- onActiveChange(false);
53
- if (!disabled) onFiles(Array.from(event.dataTransfer.files || []));
54
- },
55
- },
56
- children,
57
- );
19
+ const dropTarget = useFileDropTarget({ disabled, onFiles, onActiveChange });
20
+ return React.createElement("div", { style: DROP_ZONE_STYLE, ...dropTarget }, children);
58
21
  }
59
22
 
60
23
  export const FileUpload = makeFileUpload(
@@ -23,9 +23,16 @@
23
23
  // accessibilityLabel: string? — written to the wrapper label.
24
24
  // onFocus / onBlur: () => void — the hidden input's focus, so a
25
25
  // caller can draw a focus ring on its visible trigger.
26
+ // onDragActiveChange: (active) => void — files are being dragged over the
27
+ // picker, so a caller can highlight its drop area. Files dropped
28
+ // on the picker reach `onPick` as if picked, filtered by
29
+ // `accept` (and only the first unless `multiple`); the native
30
+ // picker has no drop and never calls it.
26
31
  // aria-describedby / aria-invalid — tie the picker to a field's note.
27
32
 
28
33
  import React, { useRef, useCallback } from "react";
34
+ import { useFileDropTarget } from "./drop-target.js";
35
+ import { partitionAccepted } from "./file-upload-logic.js";
29
36
 
30
37
  const HIDDEN_INPUT_STYLE = {
31
38
  position: "absolute",
@@ -68,10 +75,20 @@ export function FilePicker({
68
75
  accessibilityLabel,
69
76
  onFocus,
70
77
  onBlur,
78
+ onDragActiveChange,
71
79
  "aria-describedby": describedBy,
72
80
  "aria-invalid": invalid,
73
81
  }) {
74
82
  const inputRef = useRef(null);
83
+ const dropTarget = useFileDropTarget({
84
+ disabled,
85
+ onActiveChange: onDragActiveChange,
86
+ onFiles: (files) => {
87
+ const { accepted } = partitionAccepted(files, accept);
88
+ if (accepted.length === 0 || typeof onPick !== "function") return;
89
+ onPick(multiple ? accepted : accepted[0]);
90
+ },
91
+ });
75
92
 
76
93
  const handleChange = useCallback(
77
94
  (event) => {
@@ -92,6 +109,7 @@ export function FilePicker({
92
109
  {
93
110
  style: disabled ? LABEL_STYLE_DISABLED : LABEL_STYLE,
94
111
  "aria-label": accessibilityLabel,
112
+ ...dropTarget,
95
113
  },
96
114
  React.createElement("input", {
97
115
  ref: inputRef,
@@ -111,3 +129,4 @@ export function FilePicker({
111
129
  }
112
130
 
113
131
  FilePicker.isSupported = true;
132
+ FilePicker.acceptsDrop = true;
@@ -8,6 +8,8 @@
8
8
  // directly. Both honour the same public contract — `accept` / `multiple`
9
9
  // / `disabled` / `onPick` / `children` / `accessibilityLabel` / `onFocus`
10
10
  // / `onBlur` / `aria-describedby` / `aria-invalid`.
11
+ // `onDragActiveChange` is accepted and never called: React Native has no events
12
+ // for files dragged onto an app.
11
13
  //
12
14
  // `onPick` receives the same shape on both platforms:
13
15
  // - web → the browser's `File` object (a `Blob` with name + type).
@@ -122,3 +124,5 @@ export function FilePicker({
122
124
  }
123
125
 
124
126
  FilePicker.isSupported = true;
127
+ // React Native has no events for files dragged onto an app; tap only.
128
+ FilePicker.acceptsDrop = false;
package/dist/index.d.ts CHANGED
@@ -5692,6 +5692,9 @@ export interface PickedFile {
5692
5692
  * hidden file input; native opens the OS document picker. `isSupported` is
5693
5693
  * false on a host with no picker. For an upload field use `<FileUpload>`.
5694
5694
  * It lays its children out like a `View`, a stretching column, on both hosts.
5695
+ * On the web a file dropped on it reaches `onPick` as if picked, leaving out
5696
+ * any `accept` rules out (the outermost of nested pickers takes it).
5697
+ * `acceptsDrop` is false on native: React Native has no file-drag events.
5695
5698
  */
5696
5699
  export const FilePicker: ((props: {
5697
5700
  /** An HTML accept value: "image/*", ".pdf", "application/pdf". */
@@ -5703,12 +5706,14 @@ export const FilePicker: ((props: {
5703
5706
  /** The picker's keyboard focus, for a trigger that draws its own ring. */
5704
5707
  onFocus?: () => void;
5705
5708
  onBlur?: () => void;
5709
+ /** A file is being dragged over the picker (web only), to highlight a drop area. */
5710
+ onDragActiveChange?: (active: boolean) => void;
5706
5711
  accessibilityLabel?: string;
5707
5712
  /** The id of the note that describes the picker, such as a field's error. */
5708
5713
  "aria-describedby"?: string;
5709
5714
  "aria-invalid"?: boolean;
5710
5715
  children?: ReactNode;
5711
- }) => any) & { isSupported: boolean };
5716
+ }) => any) & { isSupported: boolean; acceptsDrop: boolean };
5712
5717
 
5713
5718
  /**
5714
5719
  * Themed file chooser on `<FilePicker>`: a button (the `button` scope) in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.335.0",
3
+ "version": "0.336.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/contract.js CHANGED
@@ -3674,7 +3674,7 @@ const PRIMITIVES = [
3674
3674
  {
3675
3675
  name: "FilePicker",
3676
3676
  description:
3677
- 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3677
+ 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. On the web a file can also be dropped onto the picker: dropped files reach `onPick` as if picked, leaving out any that `accept` rules out (and all but the first unless `multiple`), and `onDragActiveChange(active)` reports a file being dragged over it so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when `FilePicker.acceptsDrop` is true. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3678
3678
  rnComponent: null,
3679
3679
  docsUrl: null,
3680
3680
  },
@@ -7091,7 +7091,9 @@ const CONTRACT = deepFreeze({
7091
7091
  // 1.273.0: additive (sc-17588) — `useAgent(agentRef, { connections: true })`
7092
7092
  // returns `connections`: the signed-in app user's own MCP servers for the
7093
7093
  // agent, with add, test, remove and refresh.
7094
- version: "1.273.0",
7094
+ // 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
7095
+ // through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
7096
+ version: "1.274.0",
7095
7097
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7096
7098
  hooks: HOOKS,
7097
7099
  primitives: PRIMITIVES,