@depict-ai/react-ui 0.0.63 → 0.0.65

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SDKColsAtSize, SDKGridSpacing } from "@depict-ai/ui/dist";
2
2
  import { Display } from "../../../lib/displays/Display";
3
- import React, { ReactNode, PropsWithChildren } from "react";
3
+ import React, { ReactNode, PropsWithChildren, ReactElement } from "react";
4
4
  import { Locale } from "@depict-ai/ui/locales";
5
5
  import { Display as _Display1 } from "@depict-ai/utilishared";
6
6
  import { CategoryPage } from "@depict-ai/ui";
@@ -392,16 +392,64 @@ interface UseSearchModalReturn {
392
392
  */
393
393
  export function useDepictSearchModal(params: UseSearchModalParams): UseSearchModalReturn;
394
394
  interface SearchFieldProps {
395
+ /**
396
+ * A reference to the DOM element that the modal should be aligned to.
397
+ *
398
+ * The top of the modal will be aligned to the top of the element.
399
+ *
400
+ * The hight of the search field in the modal will be the same as the height of the element.
401
+ * If not provided, the modal will be aligned to the search field itself.
402
+ */
395
403
  alignerRef?: React.RefObject<HTMLElement>;
396
404
  }
397
405
  interface UseDepictSearchFieldReturn {
398
- DepictSearchField: React.FC;
399
- }
400
- interface SearchFieldProps {
401
- alignerRef?: React.RefObject<HTMLElement>;
406
+ /**
407
+ * A React component that renders the search field.
408
+ */
409
+ DepictSearchField: () => ReactElement;
402
410
  }
411
+ /**
412
+ * Hook used to configure the Depict search field.
413
+ * @example
414
+ * Render a search field that opens a modal aligned to the search field itself:
415
+ * ```tsx
416
+ * import React from "react";
417
+ * import { useDepictSearchField } from "@depict-ai/react-ui";
418
+ *
419
+ * const App = () => {
420
+ * const { DepictSearchField } = useDepictSearchModal();
421
+ *
422
+ * return (
423
+ * <div>
424
+ * <DepictSearchField />
425
+ * </div>
426
+ * );
427
+ * };
428
+ * ```
429
+ * @example
430
+ * Render a search field that opens a modal aligned another DOM element:
431
+ * ```tsx
432
+ * import React from "react";
433
+ * import { useDepictSearchField } from "@depict-ai/react-ui";
434
+ *
435
+ * const App = () => {
436
+ * const alignerRef = useRef(null);
437
+ * const { DepictSearchField } = useDepictSearchModal({
438
+ * alignerRef: ref
439
+ * });
440
+ *
441
+ * return (
442
+ * <div>
443
+ * <div ref={alignerRef} style={{ height: "100px", width: "100px" }} />
444
+ * <DepictSearchField />
445
+ * </div>
446
+ * );
447
+ * };
448
+ * ```
449
+ * @returns {JSX.Element}
450
+ */
403
451
  export const useDepictSearchField: (props: SearchFieldProps) => UseDepictSearchFieldReturn;
404
- export const version = "0.0.63";
452
+ export const version = "0.0.65";
405
453
  /**
406
454
  * Helper function to navigate to a new page depending on the navigation library used.
407
455
  */
package/dist/main.js CHANGED
@@ -410,7 +410,6 @@ const $7c8b440edc188ad5$export$89c6019e4baa40b1 = ({ width: width , height: heig
410
410
 
411
411
 
412
412
 
413
-
414
413
  const $ef7db890e488d4f4$export$d69d8daa20eae175 = (createOpenModalParams)=>{
415
414
  const { globalState: globalState , location: location , alignerRef: alignerRef } = createOpenModalParams;
416
415
  const openModal = ()=>{
@@ -423,17 +422,11 @@ const $ef7db890e488d4f4$export$d69d8daa20eae175 = (createOpenModalParams)=>{
423
422
  globalState.search.modal_open = true;
424
423
  return;
425
424
  }
426
- const style_element = document.createElement("style");
427
- document.head.append(style_element);
428
- const resize_observer = new ResizeObserver((0, $4GYXz$depictaiutilishared.catchify)(()=>{
429
- const styles = (0, $4GYXz$depictaiui.styles_to_valid_css_string)({
430
- ".depict.plp .depict-search-modal .query-input": {
431
- "height": `${headerAligner?.clientHeight}px`
432
- }
433
- });
434
- style_element.replaceChildren(styles);
435
- }));
436
- resize_observer.observe(headerAligner);
425
+ if (!headerAligner) // Very important not to throw here, as it just means the ref hasn't been set by react yet.
426
+ // This is a race condition that will be resolved in the next render.
427
+ // If we throw here, the app will crash.
428
+ return;
429
+ const { cleanup: cleanup } = (0, $4GYXz$depictaiui.connect_query_input_height_to_aligner_height)(headerAligner);
437
430
  let dispose_aligner;
438
431
  /**
439
432
  * Setting position to fixed is important to make the modal work with align_field.
@@ -442,8 +435,7 @@ const $ef7db890e488d4f4$export$d69d8daa20eae175 = (createOpenModalParams)=>{
442
435
  });
443
436
  (0, $4GYXz$solidjs.createRoot)((dispose)=>{
444
437
  dispose_aligner = ()=>{
445
- resize_observer.disconnect();
446
- style_element.remove();
438
+ cleanup();
447
439
  dispose();
448
440
  };
449
441
  (0, $4GYXz$depictaiui.align_field)(style_props_, headerAligner, undefined, false, "top");
@@ -497,7 +489,7 @@ const $ca5840628781f899$export$45080d603eda647c = (props)=>{
497
489
 
498
490
 
499
491
 
500
- const $db7b67857900028b$export$83d89fbfd8236492 = "0.0.63";
492
+ const $db7b67857900028b$export$83d89fbfd8236492 = "0.0.65";
501
493
 
502
494
 
503
495
 
package/dist/module.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import {dlog as $TZSbU$dlog, catchify as $TZSbU$catchify, observer as $TZSbU$observer, history_replacer as $TZSbU$history_replacer, queueMacroTask as $TZSbU$queueMacroTask, href_change_ipns as $TZSbU$href_change_ipns, ContainedPlaceholderImage as $TZSbU$ContainedPlaceholderImage, Placeholder as $TZSbU$Placeholder} from "@depict-ai/utilishared";
2
- import {add_to_version_info as $TZSbU$add_to_version_info, CategoryTitle as $43099132aad1ceb6$re_export$CategoryTitle, embedded_num_products as $43099132aad1ceb6$re_export$EmbeddedNumProducts, DepictSearch as $TZSbU$DepictSearch, DepictCategory as $TZSbU$DepictCategory, get_search_query_updating_blocked_signal as $TZSbU$get_search_query_updating_blocked_signal, SearchPage as $TZSbU$SearchPage, CategoryPage as $TZSbU$CategoryPage, BreadCrumbs as $TZSbU$BreadCrumbs, QuickLinks as $TZSbU$QuickLinks, styles_to_valid_css_string as $TZSbU$styles_to_valid_css_string, align_field as $TZSbU$align_field, SearchField as $TZSbU$SearchField} from "@depict-ai/ui";
2
+ import {add_to_version_info as $TZSbU$add_to_version_info, CategoryTitle as $43099132aad1ceb6$re_export$CategoryTitle, embedded_num_products as $43099132aad1ceb6$re_export$EmbeddedNumProducts, DepictSearch as $TZSbU$DepictSearch, DepictCategory as $TZSbU$DepictCategory, get_search_query_updating_blocked_signal as $TZSbU$get_search_query_updating_blocked_signal, SearchPage as $TZSbU$SearchPage, CategoryPage as $TZSbU$CategoryPage, BreadCrumbs as $TZSbU$BreadCrumbs, QuickLinks as $TZSbU$QuickLinks, connect_query_input_height_to_aligner_height as $TZSbU$connect_query_input_height_to_aligner_height, align_field as $TZSbU$align_field, SearchField as $TZSbU$SearchField} from "@depict-ai/ui";
3
3
  import {createRoot as $TZSbU$createRoot, untrack as $TZSbU$untrack, createSignal as $TZSbU$createSignal, createComponent as $TZSbU$createComponent, Show as $TZSbU$Show, onCleanup as $TZSbU$onCleanup, createComputed as $TZSbU$createComputed} from "solid-js";
4
4
  import {createElement as $TZSbU$createElement, Fragment as $TZSbU$Fragment, useState as $TZSbU$useState, useRef as $TZSbU$useRef, useEffect as $TZSbU$useEffect, forwardRef as $TZSbU$forwardRef} from "react";
5
5
  import {en as $TZSbU$en} from "@depict-ai/ui/locales";
@@ -392,7 +392,6 @@ const $cbd250061abf11cb$export$89c6019e4baa40b1 = ({ width: width , height: heig
392
392
 
393
393
 
394
394
 
395
-
396
395
  const $5e26376d86621891$export$d69d8daa20eae175 = (createOpenModalParams)=>{
397
396
  const { globalState: globalState , location: location , alignerRef: alignerRef } = createOpenModalParams;
398
397
  const openModal = ()=>{
@@ -405,17 +404,11 @@ const $5e26376d86621891$export$d69d8daa20eae175 = (createOpenModalParams)=>{
405
404
  globalState.search.modal_open = true;
406
405
  return;
407
406
  }
408
- const style_element = document.createElement("style");
409
- document.head.append(style_element);
410
- const resize_observer = new ResizeObserver((0, $TZSbU$catchify)(()=>{
411
- const styles = (0, $TZSbU$styles_to_valid_css_string)({
412
- ".depict.plp .depict-search-modal .query-input": {
413
- "height": `${headerAligner?.clientHeight}px`
414
- }
415
- });
416
- style_element.replaceChildren(styles);
417
- }));
418
- resize_observer.observe(headerAligner);
407
+ if (!headerAligner) // Very important not to throw here, as it just means the ref hasn't been set by react yet.
408
+ // This is a race condition that will be resolved in the next render.
409
+ // If we throw here, the app will crash.
410
+ return;
411
+ const { cleanup: cleanup } = (0, $TZSbU$connect_query_input_height_to_aligner_height)(headerAligner);
419
412
  let dispose_aligner;
420
413
  /**
421
414
  * Setting position to fixed is important to make the modal work with align_field.
@@ -424,8 +417,7 @@ const $5e26376d86621891$export$d69d8daa20eae175 = (createOpenModalParams)=>{
424
417
  });
425
418
  (0, $TZSbU$createRoot)((dispose)=>{
426
419
  dispose_aligner = ()=>{
427
- resize_observer.disconnect();
428
- style_element.remove();
420
+ cleanup();
429
421
  dispose();
430
422
  };
431
423
  (0, $TZSbU$align_field)(style_props_, headerAligner, undefined, false, "top");
@@ -479,7 +471,7 @@ const $e3ccaca62718bae4$export$45080d603eda647c = (props)=>{
479
471
 
480
472
 
481
473
 
482
- const $c9c4d066f9a5b51b$export$83d89fbfd8236492 = "0.0.63";
474
+ const $c9c4d066f9a5b51b$export$83d89fbfd8236492 = "0.0.65";
483
475
 
484
476
 
485
477
 
@@ -1,11 +1,15 @@
1
+ import { ReactElement } from "react";
1
2
  type OpenModal = () => void;
2
3
  interface UseSearchModalReturn {
3
4
  open: OpenModal;
4
5
  }
5
6
  interface UseDepictSearchFieldReturn {
6
- DepictSearchField: React.FC;
7
+ /**
8
+ * A React component that renders the search field.
9
+ */
10
+ DepictSearchField: () => ReactElement;
7
11
  }
8
- export const version = "0.0.63";
12
+ export const version = "0.0.65";
9
13
  export function DepictProvider(props: any): any;
10
14
  export function DepictSearchPage(): any;
11
15
  export function DepictCategoryPage(): any;
@@ -19,7 +19,7 @@ $parcel$export(module.exports, "useDepictSearchModal", () => $41e7e5d85b5e0d49$e
19
19
  $parcel$export(module.exports, "version", () => $db7b67857900028b$export$83d89fbfd8236492);
20
20
 
21
21
 
22
- const $db7b67857900028b$export$83d89fbfd8236492 = "0.0.63";
22
+ const $db7b67857900028b$export$83d89fbfd8236492 = "0.0.65";
23
23
 
24
24
 
25
25
  function $41e7e5d85b5e0d49$export$9fac37a9c21c2f3b(props) {
@@ -65,9 +65,9 @@ function $41e7e5d85b5e0d49$export$89c6019e4baa40b1() {
65
65
  }
66
66
  function $41e7e5d85b5e0d49$export$45080d603eda647c() {
67
67
  return {
68
- DepictSearchField: (0, $5efvh$reactjsxruntime.jsx)("div", {
69
- children: []
70
- })
68
+ DepictSearchField: ()=>(0, $5efvh$reactjsxruntime.jsx)("div", {
69
+ children: []
70
+ })
71
71
  };
72
72
  }
73
73
  function $41e7e5d85b5e0d49$export$a7f6cffb6b8ba11c() {}
@@ -3,7 +3,7 @@ import {jsx as $1RlIW$jsx} from "react/jsx-runtime";
3
3
 
4
4
 
5
5
 
6
- const $c9c4d066f9a5b51b$export$83d89fbfd8236492 = "0.0.63";
6
+ const $c9c4d066f9a5b51b$export$83d89fbfd8236492 = "0.0.65";
7
7
 
8
8
 
9
9
  function $2b1fdeb83610500f$export$9fac37a9c21c2f3b(props) {
@@ -49,9 +49,9 @@ function $2b1fdeb83610500f$export$89c6019e4baa40b1() {
49
49
  }
50
50
  function $2b1fdeb83610500f$export$45080d603eda647c() {
51
51
  return {
52
- DepictSearchField: (0, $1RlIW$jsx)("div", {
53
- children: []
54
- })
52
+ DepictSearchField: ()=>(0, $1RlIW$jsx)("div", {
53
+ children: []
54
+ })
55
55
  };
56
56
  }
57
57
  function $2b1fdeb83610500f$export$a7f6cffb6b8ba11c() {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depict-ai/react-ui",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "packageManager": "yarn@3.2.2",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",
@@ -90,8 +90,8 @@
90
90
  "/locales"
91
91
  ],
92
92
  "dependencies": {
93
- "@depict-ai/ui": "^0.0.40",
94
- "@depict-ai/utilishared": "^0.0.38",
93
+ "@depict-ai/ui": "^0.0.42",
94
+ "@depict-ai/utilishared": "^0.0.40",
95
95
  "solid-js": "^1.6.2"
96
96
  },
97
97
  "peerDependencies": {