@bloklabs/vue 1.16.0 → 2.0.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.
@@ -1,70 +0,0 @@
1
- // packages/vue/src/useBlokReady.ts
2
- import {
3
- onMounted,
4
- onScopeDispose,
5
- shallowRef,
6
- toValue,
7
- type MaybeRefOrGetter,
8
- type ShallowRef,
9
- } from 'vue';
10
-
11
- import { Blok as BlokRuntime } from '@bloklabs/core';
12
-
13
- /** Options accepted by {@link useBlokReady}. */
14
- export interface UseBlokReadyOptions {
15
- /**
16
- * Restrict the wait to editors mounted inside this element. Accepts the
17
- * template ref you already hold on the container (or a getter); it is
18
- * re-read on every readiness change, so a ref that fills in on mount is
19
- * picked up.
20
- *
21
- * Omit it to observe every editor on the page. Passing it while it still
22
- * resolves to null reports NOT ready — an unresolved scope must never fall
23
- * back to the page-global one.
24
- */
25
- within?: MaybeRefOrGetter<Element | null | undefined>;
26
- /**
27
- * `'ready'` (default) settles when each editor has finished booting.
28
- * `'rendered'` also waits for its content to be in the DOM and re-arms on
29
- * every post-boot re-render.
30
- */
31
- settleOn?: 'ready' | 'rendered';
32
- }
33
-
34
- /**
35
- * Vue composable exposing the live readiness of the Blok editors in a DOM
36
- * scope as a boolean ref.
37
- *
38
- * The readiness logic itself is framework-agnostic and lives in core
39
- * (`Blok.readyState` / `Blok.subscribeReady`) — the SAME implementation behind
40
- * React's `useBlokReady` and Angular's `injectBlokReady`, so the three adapters
41
- * cannot drift. This composable supplies only Vue's reactivity wrapper: a
42
- * `shallowRef` re-read on every registry change, with the subscription
43
- * disposed by the surrounding effect scope.
44
- *
45
- * The ref starts `false` and takes its first real reading on mount, once the
46
- * template ref has filled in. Over-waiting is safe; under-waiting is a bug.
47
- * @param options - scope and readiness depth
48
- */
49
- export function useBlokReady(options: UseBlokReadyOptions = {}): Readonly<ShallowRef<boolean>> {
50
- const { within, settleOn } = options;
51
- const ready = shallowRef(false);
52
-
53
- const read = (): void => {
54
- const scope = within === undefined ? null : (toValue(within) ?? null);
55
-
56
- // A scope that was asked for but has not resolved yet is NOT the global
57
- // scope — reporting ready here would gate on the wrong set of editors.
58
- ready.value = within !== undefined && scope === null
59
- ? false
60
- : BlokRuntime.readyState({
61
- within: scope,
62
- settleOn,
63
- }).ready;
64
- };
65
-
66
- onScopeDispose(BlokRuntime.subscribeReady(read));
67
- onMounted(read);
68
-
69
- return ready;
70
- }