@picked/client 0.0.0-chore-version-and-release-packages.1733366498981-3517ab4
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.d.ts +260 -0
- package/dist/index.js +75 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { RulesLogic } from 'json-logic-js';
|
|
2
|
+
|
|
3
|
+
export declare interface AdaptedBlock<F extends string, C> {
|
|
4
|
+
id: string;
|
|
5
|
+
framework: F;
|
|
6
|
+
mount: Mount<C>;
|
|
7
|
+
component: C;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare function addEventListener_2<K extends keyof ClientEventMap>(type: K, listener: (event: ClientEventMap[K]) => void): () => void;
|
|
11
|
+
export { addEventListener_2 as addEventListener }
|
|
12
|
+
|
|
13
|
+
export declare interface AppEvent extends ClientEvent {
|
|
14
|
+
readonly app?: {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare interface BlockComponentProps {
|
|
18
|
+
properties: { id: string; settings: any; zones: [] }
|
|
19
|
+
experience: ExperienceData // todo: is there some other way to pass this value to components? Perhaps via an SDK method
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export declare interface ClientEvent {
|
|
23
|
+
readonly type: keyof ClientEventMap;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export declare interface ClientEventMap {
|
|
27
|
+
beforeinit: ClientEvent;
|
|
28
|
+
init: ClientEvent;
|
|
29
|
+
beforeappload: AppEvent;
|
|
30
|
+
appload: AppEvent;
|
|
31
|
+
beforeappopen: AppEvent;
|
|
32
|
+
appopen: AppEvent;
|
|
33
|
+
beforeappclose: AppEvent;
|
|
34
|
+
appclose: AppEvent;
|
|
35
|
+
beforeexperienceload: ExperienceEvent;
|
|
36
|
+
experienceload: ExperienceEvent;
|
|
37
|
+
beforeexperienceopen: ExperienceEvent;
|
|
38
|
+
experienceopen: ExperienceEvent;
|
|
39
|
+
beforeexperienceclose: ExperienceEvent;
|
|
40
|
+
experienceclose: ExperienceEvent;
|
|
41
|
+
beforederivesessiontags: SessionEvent;
|
|
42
|
+
derivesessiontags: SessionEvent;
|
|
43
|
+
beforeupdatehistorystate: HistoryEvent;
|
|
44
|
+
updatehistorystate: HistoryEvent;
|
|
45
|
+
beforemodalopen: ModalEvent;
|
|
46
|
+
modalopen: ModalEvent;
|
|
47
|
+
beforemodalclose: ModalEvent;
|
|
48
|
+
modalclose: ModalEvent;
|
|
49
|
+
beforestepsubmit: StepEvent;
|
|
50
|
+
stepsubmit: StepEvent;
|
|
51
|
+
beforestepsubmitsuccess: StepEvent;
|
|
52
|
+
stepsubmitsuccess: StepEvent;
|
|
53
|
+
beforestepenter: StepEvent;
|
|
54
|
+
stepenter: StepEvent;
|
|
55
|
+
beforestepexit: StepEvent;
|
|
56
|
+
stepexit: StepEvent;
|
|
57
|
+
beforeformsubmit: FormEvent;
|
|
58
|
+
formsubmit: FormEvent;
|
|
59
|
+
experieceloaderror: ErrorEvent_2<ExperienceEvent>;
|
|
60
|
+
stepsubmiterror: ErrorEvent_2<StepEvent>;
|
|
61
|
+
formsubmiterror: ErrorEvent_2<FormEvent>;
|
|
62
|
+
fieldvalidationerror: ErrorEvent_2<FieldEvent>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export declare interface ClientEventMap extends EditorEventMap {
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export declare const createClient: (options: Readonly<CreateClientOptions>) => void;
|
|
69
|
+
|
|
70
|
+
export declare interface CreateClientOptions {
|
|
71
|
+
hooks?: CreateClientOptionsHooks;
|
|
72
|
+
mount: Mount<any>;
|
|
73
|
+
blocks: AdaptedBlock<string, any>[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export declare interface CreateClientOptionsHooks {
|
|
77
|
+
onAfterInit?: () => void;
|
|
78
|
+
onBeforeExperienceLoad?: () => void;
|
|
79
|
+
handleExperienceLoad?: (experienceId: string) => Promise<ExperienceData>;
|
|
80
|
+
onexperienceload?: () => void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export declare const destroyClient: () => void;
|
|
84
|
+
|
|
85
|
+
export declare interface EditorEvent extends ClientEvent {
|
|
86
|
+
readonly experience?: ExperienceData;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export declare interface EditorEventMap {
|
|
90
|
+
'editor:update': EditorEvent;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare type ErrorEvent_2<E extends ClientEvent> = E & {
|
|
94
|
+
readonly error: Error;
|
|
95
|
+
};
|
|
96
|
+
export { ErrorEvent_2 as ErrorEvent }
|
|
97
|
+
|
|
98
|
+
declare interface ExperienceConditional {
|
|
99
|
+
id: string
|
|
100
|
+
condition: ExperienceConditionalRulesLogic
|
|
101
|
+
|
|
102
|
+
[key: string]: unknown
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare type ExperienceConditionalNode = ExperienceNodeBase & {
|
|
106
|
+
type: 'conditional'
|
|
107
|
+
conditionalId: string
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare type ExperienceConditionalRulesLogic = RulesLogic<never>
|
|
111
|
+
|
|
112
|
+
declare interface ExperienceConfiguration {
|
|
113
|
+
steps: ExperienceStep[]
|
|
114
|
+
conditionals: ExperienceConditional[]
|
|
115
|
+
edges: ExperienceEdge[]
|
|
116
|
+
nodes: ExperienceNode[]
|
|
117
|
+
fields: ExperienceField[] // todo: rename to "questions" to match analytics
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
declare interface ExperienceData {
|
|
121
|
+
id: ExperienceSummary['id']
|
|
122
|
+
type: ExperienceSummary['type']
|
|
123
|
+
name: ExperienceSummary['name']
|
|
124
|
+
targets: ExperienceSummary['targets']
|
|
125
|
+
decide: ExperienceSummary['decide']
|
|
126
|
+
steps: ExperienceConfiguration['steps']
|
|
127
|
+
conditionals: ExperienceConfiguration['conditionals']
|
|
128
|
+
nodes: ExperienceConfiguration['nodes']
|
|
129
|
+
fields: ExperienceConfiguration['fields']
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare interface ExperienceEdge {
|
|
133
|
+
id: string
|
|
134
|
+
sourceNodeId: string
|
|
135
|
+
targetNodeId: string
|
|
136
|
+
sourceHandle?: string
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export declare interface ExperienceEvent extends ClientEvent {
|
|
140
|
+
readonly experience?: ExperienceData;
|
|
141
|
+
readonly project?: {};
|
|
142
|
+
readonly organization?: {};
|
|
143
|
+
readonly app?: {};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare interface ExperienceField {
|
|
147
|
+
id: string
|
|
148
|
+
type: ExperienceFieldTypePrimitive
|
|
149
|
+
label: string
|
|
150
|
+
placeholder?: string
|
|
151
|
+
required?: boolean
|
|
152
|
+
description?: string
|
|
153
|
+
helpText?: string
|
|
154
|
+
defaultValue?: string | number | boolean | (string | number | boolean)[]
|
|
155
|
+
multiple?: boolean
|
|
156
|
+
|
|
157
|
+
// todo: dynamic validation rules (API lookups, etc)
|
|
158
|
+
validationRules?: ExperienceFieldValidationRulesLogic
|
|
159
|
+
|
|
160
|
+
// todo: which of these do we need?
|
|
161
|
+
options?: ExperienceFieldOption[]
|
|
162
|
+
|
|
163
|
+
analytics: {
|
|
164
|
+
trackCustomerResponse: boolean // should the response to this question be tracked in analytics?
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
declare interface ExperienceFieldOption {
|
|
169
|
+
id: string
|
|
170
|
+
label: string // we used 'title' in snowplaw tracking - should we consolidate names?
|
|
171
|
+
value: string | number | boolean | null
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare type ExperienceFieldTypePrimitive = 'text' | 'number' | 'json' | 'boolean' | 'date'
|
|
175
|
+
|
|
176
|
+
declare type ExperienceFieldValidationRulesLogic = RulesLogic<never>
|
|
177
|
+
|
|
178
|
+
declare type ExperienceNode = ExperienceConditionalNode | ExperienceStepNode | ExperienceOriginNode
|
|
179
|
+
|
|
180
|
+
declare interface ExperienceNodeBase {
|
|
181
|
+
id: string
|
|
182
|
+
position: ExperienceNodePosition
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
declare interface ExperienceNodePosition {
|
|
186
|
+
x: number
|
|
187
|
+
y: number
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
declare type ExperienceOriginNode = ExperienceNodeBase & {
|
|
191
|
+
type: 'origin'
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare interface ExperienceStep {
|
|
195
|
+
id: string
|
|
196
|
+
title: string
|
|
197
|
+
thumbnailUrl?: string
|
|
198
|
+
type: 'question' | 'lead-capture' | 'error' | 'recommendation' // todo: expand or shrink types?
|
|
199
|
+
content: any // todo: step editor content
|
|
200
|
+
|
|
201
|
+
[key: string]: unknown
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
declare type ExperienceStepNode = ExperienceNodeBase & {
|
|
205
|
+
type: 'step'
|
|
206
|
+
stepId: string
|
|
207
|
+
thumbnailUrl?: string
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare interface ExperienceSummary {
|
|
211
|
+
id: string
|
|
212
|
+
type: 'funnel' | 'widget' | 'hello-bar' | 'landing-page'
|
|
213
|
+
name: string
|
|
214
|
+
slug: string
|
|
215
|
+
targets: string[] // CSS selectors to target containers to render inside
|
|
216
|
+
decide: RulesLogic<never> // todo: conditionals for showing/hiding the experience (AB/URL/etc) - JSON Logic would be useful here. Better name for this property?
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export declare interface FieldEvent extends ClientEvent {
|
|
220
|
+
readonly field?: {};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export declare interface FormEvent extends ClientEvent {
|
|
224
|
+
readonly form?: {};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export declare const getBlockById: (id: string) => AdaptedBlock<string, any> | undefined;
|
|
228
|
+
|
|
229
|
+
export declare interface HistoryEvent extends ClientEvent {
|
|
230
|
+
readonly history?: {};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export declare function internal_emitEvent<K extends keyof ClientEventMap>(type: K, event: Omit<ClientEventMap[K], 'type'>): void;
|
|
234
|
+
|
|
235
|
+
export declare interface ModalEvent extends ClientEvent {
|
|
236
|
+
readonly modal?: {};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
declare type Mount<C> = (el: Element, blockProps: BlockComponentProps, component?: C) => () => void;
|
|
240
|
+
|
|
241
|
+
declare function removeEventListener_2<K extends keyof ClientEventMap>(type: K, listener: (event: ClientEventMap[K]) => void): void;
|
|
242
|
+
export { removeEventListener_2 as removeEventListener }
|
|
243
|
+
|
|
244
|
+
export declare interface SessionEvent extends ClientEvent {
|
|
245
|
+
readonly session?: {};
|
|
246
|
+
readonly experience?: ExperienceData;
|
|
247
|
+
readonly project?: {};
|
|
248
|
+
readonly organization?: {};
|
|
249
|
+
readonly app?: {};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export declare interface StepEvent extends ClientEvent {
|
|
253
|
+
readonly step?: {};
|
|
254
|
+
readonly experience?: ExperienceData;
|
|
255
|
+
readonly project?: {};
|
|
256
|
+
readonly organization?: {};
|
|
257
|
+
readonly app?: {};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const f = (e) => ({
|
|
2
|
+
...e
|
|
3
|
+
});
|
|
4
|
+
function E() {
|
|
5
|
+
return document;
|
|
6
|
+
}
|
|
7
|
+
const i = (e, ...n) => {
|
|
8
|
+
console.log(`[@picked/client] ${e}`, ...n);
|
|
9
|
+
}, o = {};
|
|
10
|
+
function $(e, n) {
|
|
11
|
+
return i(`Add listener: ${e}`), o[e] || (o[e] = []), o[e].push(n), () => x(e, n);
|
|
12
|
+
}
|
|
13
|
+
function x(e, n) {
|
|
14
|
+
i(`Remove listener: ${e}`), o[e] && (o[e] = o[e].filter((t) => t !== n));
|
|
15
|
+
}
|
|
16
|
+
function c(e, n) {
|
|
17
|
+
i(`Emit event: ${e}`), o[e] && o[e].forEach((t) => t({ type: e, ...n }));
|
|
18
|
+
}
|
|
19
|
+
const m = (e) => e.decide === !0, p = async (e) => {
|
|
20
|
+
const n = ["todo"];
|
|
21
|
+
await Promise.allSettled(
|
|
22
|
+
n.map(async (t) => {
|
|
23
|
+
const r = await v(e);
|
|
24
|
+
m(r) && h(e, r);
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
}, g = () => {
|
|
28
|
+
for (; a.length > 0; ) {
|
|
29
|
+
const e = a.pop();
|
|
30
|
+
e == null || e();
|
|
31
|
+
}
|
|
32
|
+
}, a = [], h = (e, n) => {
|
|
33
|
+
n.targets.forEach((r) => {
|
|
34
|
+
E().querySelectorAll(r).forEach((u) => {
|
|
35
|
+
const d = e.mount(u, {
|
|
36
|
+
properties: { id: "123", settings: {}, zones: [] },
|
|
37
|
+
experience: n
|
|
38
|
+
});
|
|
39
|
+
a.push(d);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
async function v(e) {
|
|
44
|
+
var t, r;
|
|
45
|
+
c("beforeexperienceload", {});
|
|
46
|
+
const n = await ((r = (t = e.hooks) == null ? void 0 : t.handleExperienceLoad) == null ? void 0 : r.call(t, "experience-id"));
|
|
47
|
+
if (c("experienceload", {}), !n) {
|
|
48
|
+
const s = new Error("Error loading experience");
|
|
49
|
+
throw c("experieceloaderror", {
|
|
50
|
+
error: s
|
|
51
|
+
}), s;
|
|
52
|
+
}
|
|
53
|
+
return n;
|
|
54
|
+
}
|
|
55
|
+
const l = {}, b = (e) => (i(`Get block by ID: ${e}`, l), l[e]), w = (e = []) => {
|
|
56
|
+
i(`Register ${e.length} blocks`), e.forEach((n) => {
|
|
57
|
+
l[n.id] = n;
|
|
58
|
+
});
|
|
59
|
+
}, A = (e) => {
|
|
60
|
+
if (!e)
|
|
61
|
+
throw new Error("options is required");
|
|
62
|
+
c("beforeinit", {});
|
|
63
|
+
const n = f(e);
|
|
64
|
+
w(n.blocks), p(n), c("init", {});
|
|
65
|
+
}, B = () => {
|
|
66
|
+
g();
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
$ as addEventListener,
|
|
70
|
+
A as createClient,
|
|
71
|
+
B as destroyClient,
|
|
72
|
+
b as getBlockById,
|
|
73
|
+
c as internal_emitEvent,
|
|
74
|
+
x as removeEventListener
|
|
75
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@picked/client",
|
|
3
|
+
"version": "0.0.0-chore-version-and-release-packages.1733366498981-3517ab4",
|
|
4
|
+
"devDependencies": {
|
|
5
|
+
"@repo/eslint-config": "workspace:*",
|
|
6
|
+
"@repo/types": "workspace:*",
|
|
7
|
+
"@repo/typescript-config": "workspace:*",
|
|
8
|
+
"tslib": "^2.8.1",
|
|
9
|
+
"vite": "^5.4.10",
|
|
10
|
+
"vite-plugin-dts": "^4.3.0"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"main": "dist",
|
|
16
|
+
"private": false,
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "vite build",
|
|
19
|
+
"dev": "vite build --watch",
|
|
20
|
+
"lint": "eslint .",
|
|
21
|
+
"lint:format": "eslint . --fix",
|
|
22
|
+
"lint:report": "eslint . -o './.reports/eslint.json' -f json || true",
|
|
23
|
+
"type-check": "tsc -p . --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"type": "module"
|
|
26
|
+
}
|