basefn 1.9.0 → 1.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basefn",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/brnrdog/basefn.git"
@@ -103,16 +103,15 @@ let make = (
103
103
  }
104
104
  }
105
105
 
106
- // Auto-focus input when opened
106
+ // Auto-focus input when opened using requestAnimationFrame for reliable timing
107
107
  let _ = Effect.run(() => {
108
108
  if Signal.get(isOpen) {
109
- let _ = setTimeout(() => {
110
- let doc: Dom.element = %raw(`document.body`)
111
- switch querySelector(doc, ".basefn-spotlight__input") {
112
- | Value(el) => focus(el)
113
- | _ => ()
114
- }
115
- }, 16)
109
+ let _ = %raw(`requestAnimationFrame(() => {
110
+ requestAnimationFrame(() => {
111
+ const el = document.querySelector(".basefn-spotlight__input");
112
+ if (el) el.focus();
113
+ })
114
+ })`)
116
115
  }
117
116
  None
118
117
  })
@@ -165,7 +164,7 @@ let make = (
165
164
  if Signal.get(isOpen) {
166
165
  [
167
166
  <div class="basefn-spotlight-backdrop" onClick={handleBackdropClick}>
168
- <div class="basefn-spotlight">
167
+ <div class="basefn-spotlight" onKeyDown={handleKeyDown}>
169
168
  <div class="basefn-spotlight__input-wrapper">
170
169
  <Basefn__Icon name={Basefn__Icon.Search} size={Basefn__Icon.Sm} />
171
170
  <input
@@ -174,7 +173,6 @@ let make = (
174
173
  placeholder
175
174
  value={ReactiveProp.reactive(query)}
176
175
  onInput={handleInput}
177
- onKeyDown={handleKeyDown}
178
176
  />
179
177
  </div>
180
178
  <div class="basefn-spotlight__results"> {renderResults()} </div>
@@ -93,14 +93,12 @@ function Basefn__Spotlight(props) {
93
93
  };
94
94
  Xote.Effect.run(() => {
95
95
  if (Xote.Signal.get(isOpen)) {
96
- setTimeout(() => {
97
- let doc = document.body;
98
- let el = doc.querySelector(".basefn-spotlight__input");
99
- if (el == null) {
100
- return;
101
- }
102
- el.focus();
103
- }, 16);
96
+ ((requestAnimationFrame(() => {
97
+ requestAnimationFrame(() => {
98
+ const el = document.querySelector(".basefn-spotlight__input");
99
+ if (el) el.focus();
100
+ })
101
+ })));
104
102
  }
105
103
  }, undefined);
106
104
  let renderResults = () => {
@@ -155,6 +153,7 @@ function Basefn__Spotlight(props) {
155
153
  onClick: handleBackdropClick,
156
154
  children: Xote__JSX.Elements.jsxs("div", {
157
155
  class: "basefn-spotlight",
156
+ onKeyDown: handleKeyDown,
158
157
  children: Xote__JSX.array([
159
158
  Xote__JSX.Elements.jsxs("div", {
160
159
  class: "basefn-spotlight__input-wrapper",
@@ -168,8 +167,7 @@ function Basefn__Spotlight(props) {
168
167
  type: "text",
169
168
  value: Xote.ReactiveProp.reactive(query),
170
169
  placeholder: placeholder,
171
- onInput: handleInput,
172
- onKeyDown: handleKeyDown
170
+ onInput: handleInput
173
171
  })
174
172
  ])
175
173
  }),