PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.79
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.79
9.1.3 9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 All 222 releases
wpvr / admin / lib / onboarding / js / onboarding.js

onboarding.js in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.79, at admin/lib/onboarding/js/onboarding.js

321 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 var LinnoOnboarding = (() => {
3 var __defProp = Object.defineProperty;
4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5 var __getOwnPropNames = Object.getOwnPropertyNames;
6 var __hasOwnProp = Object.prototype.hasOwnProperty;
7 var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8 var __export = (target, all) => {
9 for (var name in all)
10 __defProp(target, name, { get: all[name], enumerable: true });
11 };
12 var __copyProps = (to, from, except, desc) => {
13 if (from && typeof from === "object" || typeof from === "function") {
14 for (let key of __getOwnPropNames(from))
15 if (!__hasOwnProp.call(to, key) && key !== except)
16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17 }
18 return to;
19 };
20 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21 var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
23 // src/index.ts
24 var src_exports = {};
25 __export(src_exports, {
26 Lifecycle: () => Lifecycle,
27 LinnoOnboardingEngine: () => LinnoOnboardingEngine,
28 LocalStorageAdapter: () => LocalStorageAdapter,
29 Tracker: () => Tracker,
30 VanillaAdapter: () => VanillaAdapter,
31 engine: () => engine,
32 registerOnboarding: () => registerOnboarding,
33 tracker: () => tracker
34 });
35
36 // src/storage/interface.ts
37 var LocalStorageAdapter = class {
38 async get(key) {
39 const item = localStorage.getItem(key);
40 return item ? JSON.parse(item) : null;
41 }
42 async set(key, value) {
43 localStorage.setItem(key, JSON.stringify(value));
44 }
45 async remove(key) {
46 localStorage.removeItem(key);
47 }
48 };
49
50 // src/core/lifecycle.ts
51 var Lifecycle = class {
52 constructor() {
53 __publicField(this, "status", "registered");
54 }
55 getStatus() {
56 return this.status;
57 }
58 transitionTo(newStatus) {
59 this.status = newStatus;
60 }
61 };
62
63 // src/core/tracker.ts
64 var Tracker = class {
65 constructor() {
66 __publicField(this, "listeners", {});
67 }
68 on(event, handler) {
69 if (!this.listeners[event]) {
70 this.listeners[event] = [];
71 }
72 this.listeners[event].push(handler);
73 }
74 off(event, handler) {
75 if (!this.listeners[event]) return;
76 this.listeners[event] = this.listeners[event].filter((h) => h !== handler);
77 }
78 emit(event, payload) {
79 if (this.listeners[event]) {
80 this.listeners[event].forEach((handler) => handler(payload));
81 }
82 }
83 };
84 var tracker = new Tracker();
85
86 // src/core/validator.ts
87 var Validator = class {
88 static validate(config) {
89 if (!config.plugin) {
90 throw new Error("[LinnoOnboarding] Plugin name is required.");
91 }
92 if (!config.steps || config.steps.length === 0) {
93 throw new Error("[LinnoOnboarding] At least one step is required.");
94 }
95 if (!config.firstStrike) {
96 throw new Error("[LinnoOnboarding] First Strike configuration is mandatory.");
97 }
98 if (typeof config.firstStrike.verify !== "function") {
99 throw new Error("[LinnoOnboarding] First Strike must provide a verify function.");
100 }
101 }
102 };
103
104 // src/core/engine.ts
105 var LinnoOnboardingEngine = class {
106 constructor(storage) {
107 __publicField(this, "config");
108 __publicField(this, "storage");
109 __publicField(this, "lifecycle");
110 __publicField(this, "persistState", false);
111 __publicField(this, "currentStepIndex", 0);
112 __publicField(this, "completedSteps", /* @__PURE__ */ new Set());
113 this.storage = storage || new LocalStorageAdapter();
114 this.lifecycle = new Lifecycle();
115 }
116 async register(config) {
117 Validator.validate(config);
118 this.config = config;
119 this.persistState = config.persistState ?? false;
120 if (this.persistState) {
121 await this.restoreState();
122 }
123 this.lifecycle.transitionTo("registered");
124 tracker.emit("onboarding_registered", { plugin: config.plugin });
125 }
126 async start() {
127 if (!this.config) {
128 console.error("LinnoOnboarding: Cannot start before registration.");
129 return;
130 }
131 if (this.lifecycle.getStatus() === "registered") {
132 this.lifecycle.transitionTo("started");
133 tracker.emit("onboarding_started", { plugin: this.config.plugin });
134 if (this.config.telemetry?.onSetupStarted) {
135 await Promise.resolve(this.config.telemetry.onSetupStarted({
136 plugin: this.config.plugin,
137 version: this.config.version
138 }));
139 }
140 if (this.persistState) {
141 await this.saveState();
142 }
143 }
144 }
145 getCurrentStep() {
146 if (!this.config || !this.config.steps) return null;
147 if (this.currentStepIndex < this.config.steps.length) {
148 return this.config.steps[this.currentStepIndex];
149 }
150 return null;
151 }
152 async completeStep(stepId) {
153 const step = this.config.steps.find((s) => s.id === stepId);
154 if (!step) return;
155 this.completedSteps.add(stepId);
156 tracker.emit("step_completed", { stepId, plugin: this.config.plugin });
157 if (this.currentStepIndex < this.config.steps.length - 1) {
158 this.currentStepIndex++;
159 this.lifecycle.transitionTo("step_in_progress");
160 tracker.emit("step_changed", { index: this.currentStepIndex });
161 } else {
162 if (this.completedSteps.size >= this.config.steps.length) {
163 this.lifecycle.transitionTo("onboarding_completed");
164 tracker.emit("onboarding_completed", { plugin: this.config.plugin });
165 if (this.config.telemetry?.onSetupCompleted) {
166 await Promise.resolve(this.config.telemetry.onSetupCompleted({
167 plugin: this.config.plugin,
168 version: this.config.version
169 }));
170 }
171 await this.verifyFirstStrike();
172 }
173 }
174 if (this.persistState) {
175 await this.saveState();
176 }
177 }
178 async verifyFirstStrike() {
179 const passed = await this.config.firstStrike.verify();
180 if (passed) {
181 this.lifecycle.transitionTo("first_strike_verified");
182 tracker.emit("first_strike_verified", { plugin: this.config.plugin });
183 if (this.config.telemetry?.onFirstStrikeCompleted) {
184 await Promise.resolve(this.config.telemetry.onFirstStrikeCompleted({
185 plugin: this.config.plugin,
186 version: this.config.version
187 }));
188 }
189 if (this.persistState) {
190 await this.saveState();
191 }
192 return true;
193 }
194 return false;
195 }
196 async saveState() {
197 if (!this.persistState) return;
198 await this.storage.set(`linno_onboarding_${this.config.plugin}`, {
199 status: this.lifecycle.getStatus(),
200 currentStepIndex: this.currentStepIndex,
201 completedSteps: Array.from(this.completedSteps)
202 });
203 }
204 async restoreState() {
205 const data = await this.storage.get(`linno_onboarding_${this.config.plugin}`);
206 if (data) {
207 this.currentStepIndex = data.currentStepIndex;
208 this.completedSteps = new Set(data.completedSteps);
209 this.lifecycle.transitionTo(data.status);
210 }
211 }
212 // Public API helpers for steps
213 getStepContext() {
214 if (!this.config) {
215 return {
216 plugin: "",
217 userId: 0,
218 completeStep: () => {
219 },
220 skipStep: () => {
221 },
222 goNext: () => {
223 },
224 goBack: () => {
225 },
226 emit: () => {
227 }
228 };
229 }
230 return {
231 plugin: this.config.plugin,
232 userId: 0,
233 // Placeholder, ideally passed in config or separate init
234 completeStep: () => {
235 const current = this.getCurrentStep();
236 if (current) this.completeStep(current.id);
237 },
238 skipStep: () => {
239 const current = this.getCurrentStep();
240 if (current && current.canSkip) {
241 tracker.emit("step_skipped", { stepId: current.id });
242 this.completeStep(current.id);
243 }
244 },
245 goNext: () => {
246 const current = this.getCurrentStep();
247 if (current && current.onNext) {
248 Promise.resolve(current.onNext(this.getStepContext())).then((shouldProceed) => {
249 if (shouldProceed !== false) {
250 this.completeStep(current.id);
251 }
252 });
253 } else if (current) {
254 this.completeStep(current.id);
255 }
256 },
257 goBack: () => {
258 if (this.currentStepIndex > 0) {
259 this.currentStepIndex--;
260 this.lifecycle.transitionTo("step_in_progress");
261 tracker.emit("step_changed", { index: this.currentStepIndex });
262 }
263 },
264 emit: (event, payload) => tracker.emit(event, payload)
265 };
266 }
267 getStatus() {
268 return this.lifecycle.getStatus();
269 }
270 getProgress() {
271 if (!this.config) return null;
272 return {
273 total: this.config.steps.length,
274 current: this.currentStepIndex,
275 percent: Math.round(this.completedSteps.size / this.config.steps.length * 100),
276 steps: this.config.steps.map((step, index) => ({
277 ...step,
278 status: this.completedSteps.has(step.id) ? "completed" : index === this.currentStepIndex ? "current" : "pending"
279 }))
280 };
281 }
282 };
283 var engine = new LinnoOnboardingEngine();
284
285 // src/adapters/vanilla.ts
286 var VanillaAdapter = class {
287 constructor(containerId) {
288 this.containerId = containerId;
289 }
290 init() {
291 tracker.on("onboarding_started", () => this.render());
292 tracker.on("step_completed", () => this.render());
293 tracker.on("step_skipped", () => this.render());
294 }
295 render() {
296 const container = document.getElementById(this.containerId);
297 if (!container) return;
298 const currentStep = engine.getCurrentStep();
299 if (!currentStep) return;
300 container.innerHTML = `<h2>${currentStep.title}</h2><p>${currentStep.description || ""}</p>`;
301 if (currentStep.mount) {
302 const stepContainer = document.createElement("div");
303 container.appendChild(stepContainer);
304 currentStep.mount(stepContainer, engine.getStepContext());
305 }
306 const nextBtn = document.createElement("button");
307 nextBtn.innerText = "Next";
308 nextBtn.onclick = () => {
309 engine.getStepContext().goNext();
310 };
311 container.appendChild(nextBtn);
312 }
313 };
314
315 // src/index.ts
316 var registerOnboarding = async (config) => {
317 await engine.register(config);
318 };
319 return __toCommonJS(src_exports);
320 })();
321 //# sourceMappingURL=index.global.js.map