@guidelytech/svelte 0.0.0-stage → 0.1.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.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @guidelytech/svelte
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Svelte 4/5 stores, actions and context helpers for Guidely (wraps `@guidelytech/sdk-core`).
4
+
5
+ ```bash
6
+ pnpm add @guidelytech/svelte
7
+ ```
8
+
9
+ ```svelte
10
+ <script>
11
+ import { onMount } from "svelte";
12
+ import { createGuidely, guidely, activeGuide, guideTrigger } from "@guidelytech/svelte";
13
+ onMount(() => {
14
+ const client = createGuidely({ projectId: "pk_dev_…", apiUrl: "http://localhost:3000" });
15
+ return () => client.destroy();
16
+ });
17
+ </script>
18
+
19
+ <button use:guideTrigger={"new-user-onboarding"}>Restart tour</button>
20
+ {#if $activeGuide}<p>Showing {$activeGuide.name}</p>{/if}
21
+ ```
22
+
23
+ | Export | Description |
24
+ |---|---|
25
+ | `createGuidely(options)` | Creates the client (browser only; throws a helpful error on the server) and stores it in `guidely`. Returns the existing client when called twice with the same key. |
26
+ | `destroyGuidely()` | Destroys the client and clears the store. |
27
+ | `guidely` | `Writable<GuidelyClient \| null>`. |
28
+ | `guidelyReady` | `Readable<boolean>`. |
29
+ | `activeGuide` | `Readable<PublishedGuide \| null>`. |
30
+ | `checklistProgress(idOrKey)` | `Readable<ChecklistProgressState>`. |
31
+ | `guideCompleted(idOrKey)` | `Readable<boolean>`. |
32
+ | `setGuidelyContext(client)` / `getGuidelyContext()` | Component context helpers (fall back to the store). |
33
+ | `use:guideTrigger={"guide-key"}` | Clicking the element starts the guide. |
34
+ | `use:guidelyTarget={"id"}` | Marks the element with `data-tour="id"` (no runtime behaviour). |
package/dist/index.cjs ADDED
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ activeGuide: () => activeGuide,
24
+ checklistProgress: () => checklistProgress,
25
+ createGuidely: () => createGuidely,
26
+ destroyGuidely: () => destroyGuidely,
27
+ getGuidelyContext: () => getGuidelyContext,
28
+ guideCompleted: () => guideCompleted,
29
+ guideTrigger: () => guideTrigger,
30
+ guidely: () => guidely,
31
+ guidelyReady: () => guidelyReady,
32
+ guidelyTarget: () => guidelyTarget,
33
+ setGuidelyContext: () => setGuidelyContext
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_sdk_core = require("@guidelytech/sdk-core");
37
+ var import_svelte = require("svelte");
38
+ var import_store = require("svelte/store");
39
+ var guidely = (0, import_store.writable)(null);
40
+ function createGuidely(options) {
41
+ if (typeof window === "undefined") throw new Error("[Guidely] createGuidely() can only run in the browser. Call it inside onMount(), or use initGuidely() from @guidelytech/sveltekit.");
42
+ const existing = (0, import_store.get)(guidely);
43
+ if (existing && !existing.getState().destroyed && existing.options.projectId === options.projectId) return existing;
44
+ existing?.destroy();
45
+ const client = (0, import_sdk_core.createGuidely)(options);
46
+ guidely.set(client);
47
+ return client;
48
+ }
49
+ function destroyGuidely() {
50
+ (0, import_store.get)(guidely)?.destroy();
51
+ guidely.set(null);
52
+ }
53
+ var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("guidely");
54
+ function setGuidelyContext(client) {
55
+ (0, import_svelte.setContext)(CONTEXT_KEY, client);
56
+ }
57
+ function getGuidelyContext() {
58
+ return (0, import_svelte.getContext)(CONTEXT_KEY) ?? (0, import_store.get)(guidely);
59
+ }
60
+ function fromClient(initial, compute, events) {
61
+ return (0, import_store.readable)(initial, (set) => {
62
+ let offs = [];
63
+ const unsub = guidely.subscribe((client) => {
64
+ offs.forEach((off) => off());
65
+ offs = [];
66
+ if (!client) return set(initial);
67
+ const update = () => set(compute(client));
68
+ update();
69
+ offs = events.map((e) => client.on(e, update));
70
+ });
71
+ return () => {
72
+ offs.forEach((off) => off());
73
+ unsub();
74
+ };
75
+ });
76
+ }
77
+ var guidelyReady = fromClient(false, (c) => c.getState().ready, ["ready"]);
78
+ var activeGuide = fromClient(null, (c) => c.getActiveGuide(), ["ready", "guide:start", "guide:complete", "guide:dismiss", "guide:skip", "identify"]);
79
+ function checklistProgress(idOrKey) {
80
+ return fromClient({ completedTaskIds: [], completedAt: null, dismissedAt: null }, (c) => c.getChecklistProgress(idOrKey), ["ready", "identify", "checklist:task", "checklist:complete"]);
81
+ }
82
+ function guideCompleted(idOrKey) {
83
+ return (0, import_store.derived)(fromClient(false, (c) => c.isGuideCompleted(idOrKey), ["ready", "identify", "guide:complete"]), (v) => v);
84
+ }
85
+ function guideTrigger(node, key) {
86
+ let current = key;
87
+ const onClick = (e) => {
88
+ e.preventDefault();
89
+ (0, import_store.get)(guidely)?.startGuide(current);
90
+ };
91
+ node.addEventListener("click", onClick);
92
+ node.setAttribute("data-guidely-trigger", current);
93
+ return {
94
+ update(next) {
95
+ current = next;
96
+ node.setAttribute("data-guidely-trigger", next);
97
+ },
98
+ destroy() {
99
+ node.removeEventListener("click", onClick);
100
+ }
101
+ };
102
+ }
103
+ function guidelyTarget(node, id) {
104
+ const apply = (v) => {
105
+ if (v) node.setAttribute("data-tour", v);
106
+ };
107
+ apply(id);
108
+ return { update: apply, destroy() {
109
+ } };
110
+ }
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ activeGuide,
114
+ checklistProgress,
115
+ createGuidely,
116
+ destroyGuidely,
117
+ getGuidelyContext,
118
+ guideCompleted,
119
+ guideTrigger,
120
+ guidely,
121
+ guidelyReady,
122
+ guidelyTarget,
123
+ setGuidelyContext
124
+ });
125
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createGuidely as createCore, type ChecklistProgressState, type GuidelyClient, type GuidelyOptions, type PublishedGuide } from \"@guidelytech/sdk-core\";\nimport { getContext, setContext } from \"svelte\";\nimport { derived, get, readable, writable, type Readable } from \"svelte/store\";\n\nexport type { GuidelyClient, GuidelyOptions, GuidelyEvents, GuidelyUser, ChecklistProgressState, PublishedGuide } from \"@guidelytech/sdk-core\";\n\n/** The current client (null on the server and before `createGuidely`). */\nexport const guidely = writable<GuidelyClient | null>(null);\n\n/**\n * Creates the client and stores it in the `guidely` store. Browser-only: throws a helpful error\n * when called during SSR (call it from `onMount` or use `@guidelytech/sveltekit`'s `initGuidely`).\n */\nexport function createGuidely(options: GuidelyOptions): GuidelyClient {\n if (typeof window === \"undefined\") throw new Error(\"[Guidely] createGuidely() can only run in the browser. Call it inside onMount(), or use initGuidely() from @guidelytech/sveltekit.\");\n const existing = get(guidely);\n if (existing && !existing.getState().destroyed && existing.options.projectId === options.projectId) return existing;\n existing?.destroy();\n const client = createCore(options);\n guidely.set(client);\n return client;\n}\n\n/** Destroys the current client and clears the store. */\nexport function destroyGuidely(): void {\n get(guidely)?.destroy();\n guidely.set(null);\n}\n\nconst CONTEXT_KEY = Symbol.for(\"guidely\");\n\nexport function setGuidelyContext(client: GuidelyClient | null): void {\n setContext(CONTEXT_KEY, client);\n}\n\nexport function getGuidelyContext(): GuidelyClient | null {\n return (getContext(CONTEXT_KEY) as GuidelyClient | null | undefined) ?? get(guidely);\n}\n\nfunction fromClient<T>(initial: T, compute: (client: GuidelyClient) => T, events: Array<Parameters<GuidelyClient[\"on\"]>[0]>): Readable<T> {\n return readable<T>(initial, (set) => {\n let offs: Array<() => void> = [];\n const unsub = guidely.subscribe((client) => {\n offs.forEach((off) => off());\n offs = [];\n if (!client) return set(initial);\n const update = () => set(compute(client));\n update();\n offs = events.map((e) => client.on(e, update as never));\n });\n return () => {\n offs.forEach((off) => off());\n unsub();\n };\n });\n}\n\n/** True once the configuration has loaded. */\nexport const guidelyReady: Readable<boolean> = fromClient(false, (c) => c.getState().ready, [\"ready\"]);\n\n/** The guide currently showing (flows, modals, surveys), or null. */\nexport const activeGuide: Readable<PublishedGuide | null> = fromClient<PublishedGuide | null>(null, (c) => c.getActiveGuide(), [\"ready\", \"guide:start\", \"guide:complete\", \"guide:dismiss\", \"guide:skip\", \"identify\"]);\n\n/** Live checklist progress for a checklist guide (by id or key). */\nexport function checklistProgress(idOrKey: string): Readable<ChecklistProgressState> {\n return fromClient<ChecklistProgressState>({ completedTaskIds: [], completedAt: null, dismissedAt: null }, (c) => c.getChecklistProgress(idOrKey), [\"ready\", \"identify\", \"checklist:task\", \"checklist:complete\"]);\n}\n\n/** Is the given guide completed for the current user? */\nexport function guideCompleted(idOrKey: string): Readable<boolean> {\n return derived(fromClient<boolean>(false, (c) => c.isGuideCompleted(idOrKey), [\"ready\", \"identify\", \"guide:complete\"]), (v) => v);\n}\n\n/** `use:guideTrigger={\"guide-key\"}` — clicking the element starts the guide. */\nexport function guideTrigger(node: HTMLElement, key: string): { update(key: string): void; destroy(): void } {\n let current = key;\n const onClick = (e: Event) => {\n e.preventDefault();\n get(guidely)?.startGuide(current);\n };\n node.addEventListener(\"click\", onClick);\n node.setAttribute(\"data-guidely-trigger\", current);\n return {\n update(next: string) {\n current = next;\n node.setAttribute(\"data-guidely-trigger\", next);\n },\n destroy() {\n node.removeEventListener(\"click\", onClick);\n },\n };\n}\n\n/** `use:guidelyTarget={\"id\"}` — marks an element as a guide target (`data-tour`). No runtime behaviour. */\nexport function guidelyTarget(node: HTMLElement, id?: string): { update(id?: string): void; destroy(): void } {\n const apply = (v?: string) => {\n if (v) node.setAttribute(\"data-tour\", v);\n };\n apply(id);\n return { update: apply, destroy() {} };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuI;AACvI,oBAAuC;AACvC,mBAAgE;AAKzD,IAAM,cAAU,uBAA+B,IAAI;AAMnD,SAAS,cAAc,SAAwC;AACpE,MAAI,OAAO,WAAW,YAAa,OAAM,IAAI,MAAM,oIAAoI;AACvL,QAAM,eAAW,kBAAI,OAAO;AAC5B,MAAI,YAAY,CAAC,SAAS,SAAS,EAAE,aAAa,SAAS,QAAQ,cAAc,QAAQ,UAAW,QAAO;AAC3G,YAAU,QAAQ;AAClB,QAAM,aAAS,gBAAAA,eAAW,OAAO;AACjC,UAAQ,IAAI,MAAM;AAClB,SAAO;AACT;AAGO,SAAS,iBAAuB;AACrC,wBAAI,OAAO,GAAG,QAAQ;AACtB,UAAQ,IAAI,IAAI;AAClB;AAEA,IAAM,cAAc,uBAAO,IAAI,SAAS;AAEjC,SAAS,kBAAkB,QAAoC;AACpE,gCAAW,aAAa,MAAM;AAChC;AAEO,SAAS,oBAA0C;AACxD,aAAQ,0BAAW,WAAW,SAA0C,kBAAI,OAAO;AACrF;AAEA,SAAS,WAAc,SAAY,SAAuC,QAAgE;AACxI,aAAO,uBAAY,SAAS,CAAC,QAAQ;AACnC,QAAI,OAA0B,CAAC;AAC/B,UAAM,QAAQ,QAAQ,UAAU,CAAC,WAAW;AAC1C,WAAK,QAAQ,CAAC,QAAQ,IAAI,CAAC;AAC3B,aAAO,CAAC;AACR,UAAI,CAAC,OAAQ,QAAO,IAAI,OAAO;AAC/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,CAAC,MAAe;AAC5B,QAAI,EAAG,MAAK,aAAa,aAAa,CAAC;AAAA,EACzC;AACA,QAAM,EAAE;AACR,SAAO,EAAE,QAAQ,OAAO,UAAU;AAAA,EAAC,EAAE;AACvC;","names":["createCore"]}
@@ -0,0 +1,36 @@
1
+ import * as svelte_store from 'svelte/store';
2
+ import { Readable } from 'svelte/store';
3
+ import { PublishedGuide, ChecklistProgressState, GuidelyOptions, GuidelyClient } from '@guidelytech/sdk-core';
4
+ export { ChecklistProgressState, GuidelyClient, GuidelyEvents, GuidelyOptions, GuidelyUser, PublishedGuide } from '@guidelytech/sdk-core';
5
+
6
+ /** The current client (null on the server and before `createGuidely`). */
7
+ declare const guidely: svelte_store.Writable<GuidelyClient | null>;
8
+ /**
9
+ * Creates the client and stores it in the `guidely` store. Browser-only: throws a helpful error
10
+ * when called during SSR (call it from `onMount` or use `@guidelytech/sveltekit`'s `initGuidely`).
11
+ */
12
+ declare function createGuidely(options: GuidelyOptions): GuidelyClient;
13
+ /** Destroys the current client and clears the store. */
14
+ declare function destroyGuidely(): void;
15
+ declare function setGuidelyContext(client: GuidelyClient | null): void;
16
+ declare function getGuidelyContext(): GuidelyClient | null;
17
+ /** True once the configuration has loaded. */
18
+ declare const guidelyReady: Readable<boolean>;
19
+ /** The guide currently showing (flows, modals, surveys), or null. */
20
+ declare const activeGuide: Readable<PublishedGuide | null>;
21
+ /** Live checklist progress for a checklist guide (by id or key). */
22
+ declare function checklistProgress(idOrKey: string): Readable<ChecklistProgressState>;
23
+ /** Is the given guide completed for the current user? */
24
+ declare function guideCompleted(idOrKey: string): Readable<boolean>;
25
+ /** `use:guideTrigger={"guide-key"}` — clicking the element starts the guide. */
26
+ declare function guideTrigger(node: HTMLElement, key: string): {
27
+ update(key: string): void;
28
+ destroy(): void;
29
+ };
30
+ /** `use:guidelyTarget={"id"}` — marks an element as a guide target (`data-tour`). No runtime behaviour. */
31
+ declare function guidelyTarget(node: HTMLElement, id?: string): {
32
+ update(id?: string): void;
33
+ destroy(): void;
34
+ };
35
+
36
+ export { activeGuide, checklistProgress, createGuidely, destroyGuidely, getGuidelyContext, guideCompleted, guideTrigger, guidely, guidelyReady, guidelyTarget, setGuidelyContext };
@@ -0,0 +1,36 @@
1
+ import * as svelte_store from 'svelte/store';
2
+ import { Readable } from 'svelte/store';
3
+ import { PublishedGuide, ChecklistProgressState, GuidelyOptions, GuidelyClient } from '@guidelytech/sdk-core';
4
+ export { ChecklistProgressState, GuidelyClient, GuidelyEvents, GuidelyOptions, GuidelyUser, PublishedGuide } from '@guidelytech/sdk-core';
5
+
6
+ /** The current client (null on the server and before `createGuidely`). */
7
+ declare const guidely: svelte_store.Writable<GuidelyClient | null>;
8
+ /**
9
+ * Creates the client and stores it in the `guidely` store. Browser-only: throws a helpful error
10
+ * when called during SSR (call it from `onMount` or use `@guidelytech/sveltekit`'s `initGuidely`).
11
+ */
12
+ declare function createGuidely(options: GuidelyOptions): GuidelyClient;
13
+ /** Destroys the current client and clears the store. */
14
+ declare function destroyGuidely(): void;
15
+ declare function setGuidelyContext(client: GuidelyClient | null): void;
16
+ declare function getGuidelyContext(): GuidelyClient | null;
17
+ /** True once the configuration has loaded. */
18
+ declare const guidelyReady: Readable<boolean>;
19
+ /** The guide currently showing (flows, modals, surveys), or null. */
20
+ declare const activeGuide: Readable<PublishedGuide | null>;
21
+ /** Live checklist progress for a checklist guide (by id or key). */
22
+ declare function checklistProgress(idOrKey: string): Readable<ChecklistProgressState>;
23
+ /** Is the given guide completed for the current user? */
24
+ declare function guideCompleted(idOrKey: string): Readable<boolean>;
25
+ /** `use:guideTrigger={"guide-key"}` — clicking the element starts the guide. */
26
+ declare function guideTrigger(node: HTMLElement, key: string): {
27
+ update(key: string): void;
28
+ destroy(): void;
29
+ };
30
+ /** `use:guidelyTarget={"id"}` — marks an element as a guide target (`data-tour`). No runtime behaviour. */
31
+ declare function guidelyTarget(node: HTMLElement, id?: string): {
32
+ update(id?: string): void;
33
+ destroy(): void;
34
+ };
35
+
36
+ export { activeGuide, checklistProgress, createGuidely, destroyGuidely, getGuidelyContext, guideCompleted, guideTrigger, guidely, guidelyReady, guidelyTarget, setGuidelyContext };
package/dist/index.js ADDED
@@ -0,0 +1,90 @@
1
+ // src/index.ts
2
+ import { createGuidely as createCore } from "@guidelytech/sdk-core";
3
+ import { getContext, setContext } from "svelte";
4
+ import { derived, get, readable, writable } from "svelte/store";
5
+ var guidely = writable(null);
6
+ function createGuidely(options) {
7
+ if (typeof window === "undefined") throw new Error("[Guidely] createGuidely() can only run in the browser. Call it inside onMount(), or use initGuidely() from @guidelytech/sveltekit.");
8
+ const existing = get(guidely);
9
+ if (existing && !existing.getState().destroyed && existing.options.projectId === options.projectId) return existing;
10
+ existing?.destroy();
11
+ const client = createCore(options);
12
+ guidely.set(client);
13
+ return client;
14
+ }
15
+ function destroyGuidely() {
16
+ get(guidely)?.destroy();
17
+ guidely.set(null);
18
+ }
19
+ var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("guidely");
20
+ function setGuidelyContext(client) {
21
+ setContext(CONTEXT_KEY, client);
22
+ }
23
+ function getGuidelyContext() {
24
+ return getContext(CONTEXT_KEY) ?? get(guidely);
25
+ }
26
+ function fromClient(initial, compute, events) {
27
+ return readable(initial, (set) => {
28
+ let offs = [];
29
+ const unsub = guidely.subscribe((client) => {
30
+ offs.forEach((off) => off());
31
+ offs = [];
32
+ if (!client) return set(initial);
33
+ const update = () => set(compute(client));
34
+ update();
35
+ offs = events.map((e) => client.on(e, update));
36
+ });
37
+ return () => {
38
+ offs.forEach((off) => off());
39
+ unsub();
40
+ };
41
+ });
42
+ }
43
+ var guidelyReady = fromClient(false, (c) => c.getState().ready, ["ready"]);
44
+ var activeGuide = fromClient(null, (c) => c.getActiveGuide(), ["ready", "guide:start", "guide:complete", "guide:dismiss", "guide:skip", "identify"]);
45
+ function checklistProgress(idOrKey) {
46
+ return fromClient({ completedTaskIds: [], completedAt: null, dismissedAt: null }, (c) => c.getChecklistProgress(idOrKey), ["ready", "identify", "checklist:task", "checklist:complete"]);
47
+ }
48
+ function guideCompleted(idOrKey) {
49
+ return derived(fromClient(false, (c) => c.isGuideCompleted(idOrKey), ["ready", "identify", "guide:complete"]), (v) => v);
50
+ }
51
+ function guideTrigger(node, key) {
52
+ let current = key;
53
+ const onClick = (e) => {
54
+ e.preventDefault();
55
+ get(guidely)?.startGuide(current);
56
+ };
57
+ node.addEventListener("click", onClick);
58
+ node.setAttribute("data-guidely-trigger", current);
59
+ return {
60
+ update(next) {
61
+ current = next;
62
+ node.setAttribute("data-guidely-trigger", next);
63
+ },
64
+ destroy() {
65
+ node.removeEventListener("click", onClick);
66
+ }
67
+ };
68
+ }
69
+ function guidelyTarget(node, id) {
70
+ const apply = (v) => {
71
+ if (v) node.setAttribute("data-tour", v);
72
+ };
73
+ apply(id);
74
+ return { update: apply, destroy() {
75
+ } };
76
+ }
77
+ export {
78
+ activeGuide,
79
+ checklistProgress,
80
+ createGuidely,
81
+ destroyGuidely,
82
+ getGuidelyContext,
83
+ guideCompleted,
84
+ guideTrigger,
85
+ guidely,
86
+ guidelyReady,
87
+ guidelyTarget,
88
+ setGuidelyContext
89
+ };
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createGuidely as createCore, type ChecklistProgressState, type GuidelyClient, type GuidelyOptions, type PublishedGuide } from \"@guidelytech/sdk-core\";\nimport { getContext, setContext } from \"svelte\";\nimport { derived, get, readable, writable, type Readable } from \"svelte/store\";\n\nexport type { GuidelyClient, GuidelyOptions, GuidelyEvents, GuidelyUser, ChecklistProgressState, PublishedGuide } from \"@guidelytech/sdk-core\";\n\n/** The current client (null on the server and before `createGuidely`). */\nexport const guidely = writable<GuidelyClient | null>(null);\n\n/**\n * Creates the client and stores it in the `guidely` store. Browser-only: throws a helpful error\n * when called during SSR (call it from `onMount` or use `@guidelytech/sveltekit`'s `initGuidely`).\n */\nexport function createGuidely(options: GuidelyOptions): GuidelyClient {\n if (typeof window === \"undefined\") throw new Error(\"[Guidely] createGuidely() can only run in the browser. Call it inside onMount(), or use initGuidely() from @guidelytech/sveltekit.\");\n const existing = get(guidely);\n if (existing && !existing.getState().destroyed && existing.options.projectId === options.projectId) return existing;\n existing?.destroy();\n const client = createCore(options);\n guidely.set(client);\n return client;\n}\n\n/** Destroys the current client and clears the store. */\nexport function destroyGuidely(): void {\n get(guidely)?.destroy();\n guidely.set(null);\n}\n\nconst CONTEXT_KEY = Symbol.for(\"guidely\");\n\nexport function setGuidelyContext(client: GuidelyClient | null): void {\n setContext(CONTEXT_KEY, client);\n}\n\nexport function getGuidelyContext(): GuidelyClient | null {\n return (getContext(CONTEXT_KEY) as GuidelyClient | null | undefined) ?? get(guidely);\n}\n\nfunction fromClient<T>(initial: T, compute: (client: GuidelyClient) => T, events: Array<Parameters<GuidelyClient[\"on\"]>[0]>): Readable<T> {\n return readable<T>(initial, (set) => {\n let offs: Array<() => void> = [];\n const unsub = guidely.subscribe((client) => {\n offs.forEach((off) => off());\n offs = [];\n if (!client) return set(initial);\n const update = () => set(compute(client));\n update();\n offs = events.map((e) => client.on(e, update as never));\n });\n return () => {\n offs.forEach((off) => off());\n unsub();\n };\n });\n}\n\n/** True once the configuration has loaded. */\nexport const guidelyReady: Readable<boolean> = fromClient(false, (c) => c.getState().ready, [\"ready\"]);\n\n/** The guide currently showing (flows, modals, surveys), or null. */\nexport const activeGuide: Readable<PublishedGuide | null> = fromClient<PublishedGuide | null>(null, (c) => c.getActiveGuide(), [\"ready\", \"guide:start\", \"guide:complete\", \"guide:dismiss\", \"guide:skip\", \"identify\"]);\n\n/** Live checklist progress for a checklist guide (by id or key). */\nexport function checklistProgress(idOrKey: string): Readable<ChecklistProgressState> {\n return fromClient<ChecklistProgressState>({ completedTaskIds: [], completedAt: null, dismissedAt: null }, (c) => c.getChecklistProgress(idOrKey), [\"ready\", \"identify\", \"checklist:task\", \"checklist:complete\"]);\n}\n\n/** Is the given guide completed for the current user? */\nexport function guideCompleted(idOrKey: string): Readable<boolean> {\n return derived(fromClient<boolean>(false, (c) => c.isGuideCompleted(idOrKey), [\"ready\", \"identify\", \"guide:complete\"]), (v) => v);\n}\n\n/** `use:guideTrigger={\"guide-key\"}` — clicking the element starts the guide. */\nexport function guideTrigger(node: HTMLElement, key: string): { update(key: string): void; destroy(): void } {\n let current = key;\n const onClick = (e: Event) => {\n e.preventDefault();\n get(guidely)?.startGuide(current);\n };\n node.addEventListener(\"click\", onClick);\n node.setAttribute(\"data-guidely-trigger\", current);\n return {\n update(next: string) {\n current = next;\n node.setAttribute(\"data-guidely-trigger\", next);\n },\n destroy() {\n node.removeEventListener(\"click\", onClick);\n },\n };\n}\n\n/** `use:guidelyTarget={\"id\"}` — marks an element as a guide target (`data-tour`). No runtime behaviour. */\nexport function guidelyTarget(node: HTMLElement, id?: string): { update(id?: string): void; destroy(): void } {\n const apply = (v?: string) => {\n if (v) node.setAttribute(\"data-tour\", v);\n };\n apply(id);\n return { update: apply, destroy() {} };\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,kBAA6G;AACvI,SAAS,YAAY,kBAAkB;AACvC,SAAS,SAAS,KAAK,UAAU,gBAA+B;AAKzD,IAAM,UAAU,SAA+B,IAAI;AAMnD,SAAS,cAAc,SAAwC;AACpE,MAAI,OAAO,WAAW,YAAa,OAAM,IAAI,MAAM,oIAAoI;AACvL,QAAM,WAAW,IAAI,OAAO;AAC5B,MAAI,YAAY,CAAC,SAAS,SAAS,EAAE,aAAa,SAAS,QAAQ,cAAc,QAAQ,UAAW,QAAO;AAC3G,YAAU,QAAQ;AAClB,QAAM,SAAS,WAAW,OAAO;AACjC,UAAQ,IAAI,MAAM;AAClB,SAAO;AACT;AAGO,SAAS,iBAAuB;AACrC,MAAI,OAAO,GAAG,QAAQ;AACtB,UAAQ,IAAI,IAAI;AAClB;AAEA,IAAM,cAAc,uBAAO,IAAI,SAAS;AAEjC,SAAS,kBAAkB,QAAoC;AACpE,aAAW,aAAa,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,eAAe;AACjB,QAAI,OAAO,GAAG,WAAW,OAAO;AAAA,EAClC;AACA,OAAK,iBAAiB,SAAS,OAAO;AACtC,OAAK,aAAa,wBAAwB,OAAO;AACjD,SAAO;AAAA,IACL,OAAO,MAAc;AACnB,gBAAU;AACV,WAAK,aAAa,wBAAwB,IAAI;AAAA,IAChD;AAAA,IACA,UAAU;AACR,WAAK,oBAAoB,SAAS,OAAO;AAAA,IAC3C;AAAA,EACF;AACF;AAGO,SAAS,cAAc,MAAmB,IAA6D;AAC5G,QAAM,QAAQ,CAAC,MAAe;AAC5B,QAAI,EAAG,MAAK,aAAa,aAAa,CAAC;AAAA,EACzC;AACA,QAAM,EAAE;AACR,SAAO,EAAE,QAAQ,OAAO,UAAU;AAAA,EAAC,EAAE;AACvC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@guidelytech/svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Svelte stores, actions and client for Guidely",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "dependencies": {
23
+ "@guidelytech/sdk-core": "0.1.0",
24
+ "@guidelytech/shared": "0.1.0"
25
+ },
26
+ "devDependencies": {
27
+ "tsup": "^8.5.1",
28
+ "typescript": "^5.9.3",
29
+ "vitest": "^3.2.7",
30
+ "happy-dom": "^17.6.3",
31
+ "eslint": "^9.39.5",
32
+ "@eslint/js": "^9.39.5",
33
+ "typescript-eslint": "^8.46.0",
34
+ "svelte": "^5.57.2"
35
+ },
36
+ "peerDependencies": {
37
+ "svelte": ">=4.0.0"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/parmarg/Guidely.git",
45
+ "directory": "packages/svelte"
46
+ },
47
+ "homepage": "https://github.com/parmarg/Guidely/tree/main/packages/svelte#readme",
48
+ "bugs": {
49
+ "url": "https://github.com/parmarg/Guidely/issues"
50
+ },
51
+ "keywords": [
52
+ "guidely",
53
+ "product-adoption",
54
+ "onboarding",
55
+ "product-tour",
56
+ "in-app-guidance",
57
+ "svelte"
58
+ ],
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "dev": "tsup --watch",
62
+ "typecheck": "tsc --noEmit",
63
+ "test": "vitest run",
64
+ "lint": "eslint src",
65
+ "clean": "rm -rf dist"
66
+ }
6
67
  }