@vicinae/api 0.20.14 → 0.21.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Form = exports.DatePickerType = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const use_imperative_form_handle_1 = require("../hooks/use-imperative-form-handle");
6
+ const use_event_counted_1 = require("../hooks/use-event-counted");
6
7
  const image_1 = require("../image");
7
8
  const dropdown_1 = require("./dropdown");
8
9
  const wrapFormItemProps = (props) => {
@@ -29,13 +30,15 @@ const FormRoot = ({ enableDrafts = false, actions, children, isLoading = false,
29
30
  //@ts-ignore
30
31
  enableDrafts: enableDrafts, isLoading: isLoading, navigationTitle: navigationTitle, children: [searchBarAccessory, children, actions] }));
31
32
  };
32
- const TextField = ({ ref, ...props }) => {
33
+ const TextField = ({ ref, value, onChange, ...props }) => {
33
34
  (0, use_imperative_form_handle_1.useImperativeFormHandle)(ref);
34
- return (0, jsx_runtime_1.jsx)("text-field", { ...wrapFormItemProps(props) });
35
+ const [countedValue, wrappedOnChange] = (0, use_event_counted_1.useEventCounted)(value, onChange);
36
+ return (0, jsx_runtime_1.jsx)("text-field", { ...wrapFormItemProps(props), value: countedValue, onChange: wrappedOnChange });
35
37
  };
36
- const PasswordField = ({ ref, ...props }) => {
38
+ const PasswordField = ({ ref, value, onChange, ...props }) => {
37
39
  (0, use_imperative_form_handle_1.useImperativeFormHandle)(ref);
38
- return (0, jsx_runtime_1.jsx)("password-field", { ...props });
40
+ const [countedValue, wrappedOnChange] = (0, use_event_counted_1.useEventCounted)(value, onChange);
41
+ return (0, jsx_runtime_1.jsx)("password-field", { ...props, value: countedValue, onChange: wrappedOnChange });
39
42
  };
40
43
  var DatePickerType;
41
44
  (function (DatePickerType) {
@@ -88,9 +91,10 @@ const TagPickerItem = ({ icon, ...props }) => {
88
91
  const TagPicker = Object.assign(TagPickerRoot, {
89
92
  Item: TagPickerItem,
90
93
  });
91
- const TextArea = ({ ref, ...props }) => {
94
+ const TextArea = ({ ref, value, onChange, ...props }) => {
92
95
  (0, use_imperative_form_handle_1.useImperativeFormHandle)(ref);
93
- return (0, jsx_runtime_1.jsx)("text-area-field", { ...wrapFormItemProps(props) });
96
+ const [countedValue, wrappedOnChange] = (0, use_event_counted_1.useEventCounted)(value, onChange);
97
+ return (0, jsx_runtime_1.jsx)("text-area-field", { ...wrapFormItemProps(props), value: countedValue, onChange: wrappedOnChange });
94
98
  };
95
99
  const FilePicker = ({ ref, ...props }) => {
96
100
  (0, use_imperative_form_handle_1.useImperativeFormHandle)(ref);
@@ -8,6 +8,7 @@ const crypto_1 = require("crypto");
8
8
  const empty_view_1 = require("./empty-view");
9
9
  const color_1 = require("../color");
10
10
  const dropdown_1 = require("./dropdown");
11
+ const use_event_counted_1 = require("../hooks/use-event-counted");
11
12
  var GridInset;
12
13
  (function (GridInset) {
13
14
  GridInset["Zero"] = "zero";
@@ -52,7 +53,7 @@ var GridFit;
52
53
  */
53
54
  GridFit["Fill"] = "fill";
54
55
  })(GridFit || (GridFit = {}));
55
- const GridRoot = ({ searchBarAccessory, children, actions, inset, itemSize, fit = GridFit.Contain, aspectRatio = "1", ...props }) => {
56
+ const GridRoot = ({ searchBarAccessory, children, actions, inset, itemSize, fit = GridFit.Contain, aspectRatio = "1", searchText, onSearchTextChange, ...props }) => {
56
57
  if (typeof props.enableFiltering === "boolean" &&
57
58
  typeof props.filtering === "undefined") {
58
59
  props.filtering = props.enableFiltering;
@@ -64,7 +65,8 @@ const GridRoot = ({ searchBarAccessory, children, actions, inset, itemSize, fit
64
65
  [GridItemSize.Large]: 3,
65
66
  }[itemSize];
66
67
  }
67
- return ((0, jsx_runtime_1.jsxs)("grid", { fit: fit, inset: inset, aspectRatio: aspectRatioMap[aspectRatio], ...props, children: [searchBarAccessory, children, actions] }));
68
+ const [countedSearchText, wrappedOnSearchTextChange] = (0, use_event_counted_1.useEventCounted)(searchText, onSearchTextChange);
69
+ return ((0, jsx_runtime_1.jsxs)("grid", { fit: fit, inset: inset, aspectRatio: aspectRatioMap[aspectRatio], searchText: countedSearchText, onSearchTextChange: wrappedOnSearchTextChange, ...props, children: [searchBarAccessory, children, actions] }));
68
70
  };
69
71
  const GridItem = ({ detail, actions, content, accessory, ...props }) => {
70
72
  const id = (0, react_1.useRef)(props.id ?? (0, crypto_1.randomUUID)());
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.List = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const use_event_counted_1 = require("../hooks/use-event-counted");
6
7
  const image_1 = require("../image");
7
8
  const node_crypto_1 = require("node:crypto");
8
9
  const metadata_1 = require("./metadata");
@@ -41,12 +42,13 @@ function serializeText(text) {
41
42
  return { color, value };
42
43
  }
43
44
  }
44
- const ListRoot = ({ searchBarAccessory, children, actions, ...props }) => {
45
+ const ListRoot = ({ searchBarAccessory, children, actions, searchText, onSearchTextChange, ...props }) => {
45
46
  if (typeof props.enableFiltering === "boolean" &&
46
47
  typeof props.filtering === "undefined") {
47
48
  props.filtering = props.enableFiltering;
48
49
  }
49
- return ((0, jsx_runtime_1.jsxs)("list", { ...props, children: [searchBarAccessory, children, actions] }));
50
+ const [countedSearchText, wrappedOnSearchTextChange] = (0, use_event_counted_1.useEventCounted)(searchText, onSearchTextChange);
51
+ return ((0, jsx_runtime_1.jsxs)("list", { ...props, searchText: countedSearchText, onSearchTextChange: wrappedOnSearchTextChange, children: [searchBarAccessory, children, actions] }));
50
52
  };
51
53
  const ListItem = ({ detail, actions, icon, accessories, ...props }) => {
52
54
  const id = (0, react_1.useRef)(props.id ?? (0, node_crypto_1.randomUUID)());
@@ -1 +1,2 @@
1
+ export * from "./use-event-counted";
1
2
  export * from "./use-navigation";
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./use-event-counted"), exports);
17
18
  __exportStar(require("./use-navigation"), exports);
@@ -0,0 +1,5 @@
1
+ export type EventCounted<T> = {
2
+ value: T;
3
+ eventCount: number;
4
+ };
5
+ export declare function useEventCounted<T>(value: T | undefined, onChange?: (value: T) => void): [EventCounted<T> | undefined, ((...args: any[]) => void) | undefined];
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useEventCounted = useEventCounted;
4
+ const react_1 = require("react");
5
+ function useEventCounted(value, onChange) {
6
+ const ref = (0, react_1.useRef)(0);
7
+ const handler = (0, react_1.useCallback)((...args) => {
8
+ if (typeof args[1] === "number")
9
+ ref.current = args[1];
10
+ onChange?.(args[0]);
11
+ }, [onChange]);
12
+ const counted = value != null ? { value, eventCount: ref.current } : undefined;
13
+ return [counted, onChange ? handler : undefined];
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vicinae/api",
3
- "version": "0.20.14",
3
+ "version": "0.21.0",
4
4
  "description": "TypeScript SDK to build Vicinae extensions",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/types/jsx.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type * as React from "react";
2
2
  import type {
3
3
  DatePickerType,
4
+ EventCounted,
4
5
  Grid,
5
6
  Keyboard,
6
7
  List,
@@ -13,6 +14,7 @@ type BaseFormField = {
13
14
  onBlur?: Function;
14
15
  onFocus?: Function;
15
16
  onChange?: Function;
17
+ value?: any;
16
18
  };
17
19
 
18
20
  declare module "react" {
@@ -30,9 +32,10 @@ declare module "react" {
30
32
  filtering?: boolean;
31
33
  isLoading?: boolean;
32
34
  isShowingDetail?: boolean;
35
+ searchText?: EventCounted<string>;
33
36
  searchBarPlaceholder?: string;
34
37
  navigationTitle?: string;
35
- onSearchTextChange?: (text: string) => void;
38
+ onSearchTextChange?: (...args: any[]) => void;
36
39
  onSelectionChange?: (selectedItemId: string) => void;
37
40
  };
38
41
  "list-section": {
@@ -67,9 +70,10 @@ declare module "react" {
67
70
  filtering?: boolean;
68
71
  isLoading?: boolean;
69
72
  isShowingDetail?: boolean;
73
+ searchText?: EventCounted<string>;
70
74
  searchBarPlaceholder?: string;
71
75
  navigationTitle?: string;
72
- onSearchTextChange?: (text: string) => void;
76
+ onSearchTextChange?: (...args: any[]) => void;
73
77
  onSelectionChange?: (selectedItemId: string) => void;
74
78
  };
75
79
  "grid-section": {
@@ -193,7 +197,7 @@ declare module "react" {
193
197
  type?: DatePickerType;
194
198
  };
195
199
  "checkbox-field": BaseFormField & {};
196
- "password-field": {};
200
+ "password-field": BaseFormField & {};
197
201
  "textarea-field": {};
198
202
 
199
203
  dropdown: {