vue-datocms 4.0.0 → 4.0.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/dist/index.cjs.js +13 -25
- package/dist/index.d.ts +5 -5
- package/dist/index.esm.mjs +14 -26
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -663,46 +663,34 @@ const DatocmsStructuredTextPlugin = {
|
|
|
663
663
|
}
|
|
664
664
|
};
|
|
665
665
|
|
|
666
|
-
|
|
667
|
-
const { enabled, initialData, ...other } = options;
|
|
666
|
+
const useQuerySubscription = ({ enabled = true, initialData, query, token, ...other }) => {
|
|
668
667
|
const error = vueDemi.ref(null);
|
|
669
|
-
const data = vueDemi.ref(null);
|
|
670
|
-
const status = vueDemi.ref(
|
|
671
|
-
enabled ? "connecting" : "closed"
|
|
672
|
-
);
|
|
668
|
+
const data = vueDemi.ref(vueDemi.unref(initialData) || null);
|
|
669
|
+
const status = vueDemi.ref(vueDemi.unref(enabled) ? "connecting" : "closed");
|
|
673
670
|
const subscribeToQueryOptions = other;
|
|
674
|
-
vueDemi.watchEffect((onCleanup) => {
|
|
675
|
-
if (
|
|
676
|
-
|
|
677
|
-
return () => {
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
let unsubscribe;
|
|
681
|
-
async function subscribe() {
|
|
682
|
-
unsubscribe = await datocmsListen.subscribeToQuery({
|
|
671
|
+
vueDemi.watchEffect(async (onCleanup) => {
|
|
672
|
+
if (query && token && vueDemi.unref(enabled)) {
|
|
673
|
+
const unsubscribe = await datocmsListen.subscribeToQuery({
|
|
683
674
|
...subscribeToQueryOptions,
|
|
675
|
+
query,
|
|
676
|
+
token,
|
|
684
677
|
onStatusChange: (connectionStatus) => {
|
|
685
678
|
status.value = connectionStatus;
|
|
686
679
|
},
|
|
687
|
-
onUpdate: (
|
|
680
|
+
onUpdate: ({ response }) => {
|
|
688
681
|
error.value = null;
|
|
689
|
-
data.value =
|
|
682
|
+
data.value = response.data;
|
|
690
683
|
},
|
|
691
684
|
onChannelError: (errorData) => {
|
|
692
685
|
data.value = null;
|
|
693
686
|
error.value = errorData;
|
|
694
687
|
}
|
|
695
688
|
});
|
|
689
|
+
onCleanup(unsubscribe);
|
|
696
690
|
}
|
|
697
|
-
subscribe();
|
|
698
|
-
onCleanup(() => {
|
|
699
|
-
if (unsubscribe) {
|
|
700
|
-
unsubscribe();
|
|
701
|
-
}
|
|
702
|
-
});
|
|
703
691
|
});
|
|
704
|
-
return {
|
|
705
|
-
}
|
|
692
|
+
return { data, status, error };
|
|
693
|
+
};
|
|
706
694
|
|
|
707
695
|
const highlightPieces = (textWithHighlightMarker) => {
|
|
708
696
|
return textWithHighlightMarker.split(/\[h\](.+?)\[\/h\]/g).map((text, index) => ({
|
package/dist/index.d.ts
CHANGED
|
@@ -381,26 +381,26 @@ declare const DatocmsStructuredTextPlugin: {
|
|
|
381
381
|
declare type SubscribeToQueryOptions<QueryResult, QueryVariables> = Omit<Options<QueryResult, QueryVariables>, 'onStatusChange' | 'onUpdate' | 'onChannelError'>;
|
|
382
382
|
declare type EnabledQueryListenerOptions<QueryResult, QueryVariables> = {
|
|
383
383
|
/** Whether the subscription has to be performed or not */
|
|
384
|
-
enabled?: true
|
|
384
|
+
enabled?: true | Ref<boolean>;
|
|
385
385
|
/** The initial data to use while the initial request is being performed */
|
|
386
386
|
initialData?: QueryResult;
|
|
387
387
|
} & SubscribeToQueryOptions<QueryResult, QueryVariables>;
|
|
388
388
|
declare type DisabledQueryListenerOptions<QueryResult, QueryVariables> = {
|
|
389
389
|
/** Whether the subscription has to be performed or not */
|
|
390
|
-
enabled: false
|
|
390
|
+
enabled: false | Ref<boolean>;
|
|
391
391
|
/** The initial data to use while the initial request is being performed */
|
|
392
392
|
initialData?: QueryResult;
|
|
393
393
|
} & Partial<SubscribeToQueryOptions<QueryResult, QueryVariables>>;
|
|
394
394
|
declare type QueryListenerOptions<QueryResult, QueryVariables> = EnabledQueryListenerOptions<QueryResult, QueryVariables> | DisabledQueryListenerOptions<QueryResult, QueryVariables>;
|
|
395
|
-
declare
|
|
395
|
+
declare const useQuerySubscription: <QueryResult = any, QueryVariables = Record<string, any>>({ enabled, initialData, query, token, ...other }: QueryListenerOptions<QueryResult, QueryVariables>) => {
|
|
396
|
+
data: Ref<vue_demi.UnwrapRef<NonNullable<QueryResult>> | null>;
|
|
397
|
+
status: Ref<ConnectionStatus>;
|
|
396
398
|
error: Ref<{
|
|
397
399
|
code: string;
|
|
398
400
|
message: string;
|
|
399
401
|
fatal: boolean;
|
|
400
402
|
response?: any;
|
|
401
403
|
} | null>;
|
|
402
|
-
status: Ref<ConnectionStatus>;
|
|
403
|
-
data: Ref<QueryResult | null>;
|
|
404
404
|
};
|
|
405
405
|
|
|
406
406
|
declare type SearchResultInstancesHrefSchema = {
|
package/dist/index.esm.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import hypenateStyleName from 'hyphenate-style-name';
|
|
2
|
-
import { ref, onMounted, onBeforeUnmount, defineComponent, h, isVue2, isVue3, watchEffect, reactive, computed, toRaw } from 'vue-demi';
|
|
2
|
+
import { ref, onMounted, onBeforeUnmount, defineComponent, h, isVue2, isVue3, watchEffect, unref, reactive, computed, toRaw } from 'vue-demi';
|
|
3
3
|
import { render, renderNodeRule, defaultMetaTransformer } from 'datocms-structured-text-generic-html-renderer';
|
|
4
4
|
export { renderMarkRule, renderNodeRule, renderNodeRule as renderRule } from 'datocms-structured-text-generic-html-renderer';
|
|
5
5
|
import { isRoot, isInlineItem, RenderError, isStructuredText, isItemLink, isBlock } from 'datocms-structured-text-utils';
|
|
@@ -657,46 +657,34 @@ const DatocmsStructuredTextPlugin = {
|
|
|
657
657
|
}
|
|
658
658
|
};
|
|
659
659
|
|
|
660
|
-
|
|
661
|
-
const { enabled, initialData, ...other } = options;
|
|
660
|
+
const useQuerySubscription = ({ enabled = true, initialData, query, token, ...other }) => {
|
|
662
661
|
const error = ref(null);
|
|
663
|
-
const data = ref(null);
|
|
664
|
-
const status = ref(
|
|
665
|
-
enabled ? "connecting" : "closed"
|
|
666
|
-
);
|
|
662
|
+
const data = ref(unref(initialData) || null);
|
|
663
|
+
const status = ref(unref(enabled) ? "connecting" : "closed");
|
|
667
664
|
const subscribeToQueryOptions = other;
|
|
668
|
-
watchEffect((onCleanup) => {
|
|
669
|
-
if (
|
|
670
|
-
|
|
671
|
-
return () => {
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
let unsubscribe;
|
|
675
|
-
async function subscribe() {
|
|
676
|
-
unsubscribe = await subscribeToQuery({
|
|
665
|
+
watchEffect(async (onCleanup) => {
|
|
666
|
+
if (query && token && unref(enabled)) {
|
|
667
|
+
const unsubscribe = await subscribeToQuery({
|
|
677
668
|
...subscribeToQueryOptions,
|
|
669
|
+
query,
|
|
670
|
+
token,
|
|
678
671
|
onStatusChange: (connectionStatus) => {
|
|
679
672
|
status.value = connectionStatus;
|
|
680
673
|
},
|
|
681
|
-
onUpdate: (
|
|
674
|
+
onUpdate: ({ response }) => {
|
|
682
675
|
error.value = null;
|
|
683
|
-
data.value =
|
|
676
|
+
data.value = response.data;
|
|
684
677
|
},
|
|
685
678
|
onChannelError: (errorData) => {
|
|
686
679
|
data.value = null;
|
|
687
680
|
error.value = errorData;
|
|
688
681
|
}
|
|
689
682
|
});
|
|
683
|
+
onCleanup(unsubscribe);
|
|
690
684
|
}
|
|
691
|
-
subscribe();
|
|
692
|
-
onCleanup(() => {
|
|
693
|
-
if (unsubscribe) {
|
|
694
|
-
unsubscribe();
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
685
|
});
|
|
698
|
-
return {
|
|
699
|
-
}
|
|
686
|
+
return { data, status, error };
|
|
687
|
+
};
|
|
700
688
|
|
|
701
689
|
const highlightPieces = (textWithHighlightMarker) => {
|
|
702
690
|
return textWithHighlightMarker.split(/\[h\](.+?)\[\/h\]/g).map((text, index) => ({
|