@localess/client 3.3.0-dev.20260708093226 → 3.3.0-dev.20260708124505
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 +4 -8
- package/SKILL.md +6 -4
- package/dist/index.d.ts +10 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -222,18 +222,14 @@ When your application is loaded inside the Localess Visual Editor, you can subsc
|
|
|
222
222
|
|
|
223
223
|
```ts
|
|
224
224
|
if (window.localess) {
|
|
225
|
-
// Subscribe to a single event
|
|
225
|
+
// Subscribe to a single event — `event` is typed to that event's variant, no narrowing needed
|
|
226
226
|
window.localess.on('change', (event) => {
|
|
227
|
-
|
|
228
|
-
setPageData(event.data);
|
|
229
|
-
}
|
|
227
|
+
setPageData(event.data);
|
|
230
228
|
});
|
|
231
229
|
|
|
232
|
-
// Subscribe to multiple events
|
|
230
|
+
// Subscribe to multiple events — `event` is narrowed to the union of those variants
|
|
233
231
|
window.localess.on(['input', 'change'], (event) => {
|
|
234
|
-
|
|
235
|
-
setPageData(event.data);
|
|
236
|
-
}
|
|
232
|
+
setPageData(event.data);
|
|
237
233
|
});
|
|
238
234
|
}
|
|
239
235
|
```
|
package/SKILL.md
CHANGED
|
@@ -204,14 +204,16 @@ import { localessEditable, localessEditableField } from "@localess/client";
|
|
|
204
204
|
// Only available when app is loaded inside the Localess Visual Editor iframe
|
|
205
205
|
if (window.localess) {
|
|
206
206
|
window.localess.on(['input', 'change'], (event) => {
|
|
207
|
-
|
|
208
|
-
setPageData(event.data); // Real-time preview update
|
|
209
|
-
}
|
|
207
|
+
setPageData(event.data); // Real-time preview update — event is narrowed to the 'input' | 'change' variant, no type check needed
|
|
210
208
|
});
|
|
211
209
|
// No .off() method — subscribe once on mount
|
|
212
210
|
}
|
|
213
211
|
```
|
|
214
212
|
|
|
213
|
+
> `on`'s callback type is inferred from the event(s) passed in — subscribing to `['input', 'change']` narrows `event` to the variant carrying `data`, so no manual `event.type === ...` check is needed inside the callback.
|
|
214
|
+
|
|
215
|
+
`window.localess.onChange(callback)` is shorthand for `on(['input', 'change'], callback)` — it fires only for content-change events, with `callback` narrowed to that variant.
|
|
216
|
+
|
|
215
217
|
**Event types:**
|
|
216
218
|
|
|
217
219
|
| Event | When |
|
|
@@ -334,7 +336,7 @@ export type {
|
|
|
334
336
|
ContentMetadata, ContentAsset, ContentLink,
|
|
335
337
|
ContentRichText, ContentReference,
|
|
336
338
|
Links, References, Translations,
|
|
337
|
-
LocalessSync, EventToApp, EventCallback, EventToAppType,
|
|
339
|
+
LocalessSync, EventToApp, EventToAppOf, EventCallback, EventToAppType,
|
|
338
340
|
AssetTransformParams,
|
|
339
341
|
}
|
|
340
342
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -17,9 +17,17 @@ export type EventToApp = {
|
|
|
17
17
|
schema: string;
|
|
18
18
|
field?: string;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Narrows {@link EventToApp} down to the variant(s) matching event type `T`.
|
|
22
|
+
* Used to type {@link LocalessSync.on}'s callback based on the subscribed event(s),
|
|
23
|
+
* e.g. subscribing to `'input' | 'change'` narrows the callback's `event` to the variant with `data`.
|
|
24
|
+
*/
|
|
25
|
+
export type EventToAppOf<T extends EventToAppType> = Extract<EventToApp, {
|
|
26
|
+
type: T;
|
|
27
|
+
}>;
|
|
20
28
|
export interface LocalessSync {
|
|
21
|
-
onChange: (callback:
|
|
22
|
-
on: (event:
|
|
29
|
+
onChange: (callback: (event: EventToAppOf<'change' | 'input'>) => void) => void;
|
|
30
|
+
on: <T extends EventToAppType>(event: T | T[], callback: (event: EventToAppOf<T>) => void) => void;
|
|
23
31
|
}
|
|
24
32
|
declare global {
|
|
25
33
|
interface Window {
|