@launchdarkly/toolbar 2.1.4 → 2.2.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 +245 -18
- package/dist/angular/launchdarkly-toolbar.service.d.ts +104 -0
- package/dist/angular.cjs +439 -0
- package/dist/angular.cjs.map +1 -0
- package/dist/angular.d.ts +51 -0
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/js/816.js +56 -0
- package/dist/js/816.js.map +1 -0
- package/dist/js/96.js +4 -54
- package/dist/js/96.js.map +1 -1
- package/dist/js/angular.js +353 -0
- package/dist/js/angular.js.map +1 -0
- package/dist/js/react.js +2 -1
- package/dist/js/vue.js +34 -0
- package/dist/js/vue.js.map +1 -0
- package/dist/react.cjs +3 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/vue/useLaunchDarklyToolbar.d.ts +20 -0
- package/dist/vue.cjs +122 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.ts +24 -0
- package/package.json +70 -18
- /package/dist/{react → core}/lazyLoadToolbar.d.ts +0 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { Injectable } from "@angular/core";
|
|
2
|
+
import { package_namespaceObject, lazyLoadToolbar } from "./816.js";
|
|
3
|
+
function applyDecs2203RFactory() {
|
|
4
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
5
|
+
return function(initializer) {
|
|
6
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
7
|
+
assertCallable(initializer, "An initializer");
|
|
8
|
+
initializers.push(initializer);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
12
|
+
var kindStr;
|
|
13
|
+
switch(kind){
|
|
14
|
+
case 1:
|
|
15
|
+
kindStr = "accessor";
|
|
16
|
+
break;
|
|
17
|
+
case 2:
|
|
18
|
+
kindStr = "method";
|
|
19
|
+
break;
|
|
20
|
+
case 3:
|
|
21
|
+
kindStr = "getter";
|
|
22
|
+
break;
|
|
23
|
+
case 4:
|
|
24
|
+
kindStr = "setter";
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
kindStr = "field";
|
|
28
|
+
}
|
|
29
|
+
var ctx = {
|
|
30
|
+
kind: kindStr,
|
|
31
|
+
name: isPrivate ? "#" + name : name,
|
|
32
|
+
static: isStatic,
|
|
33
|
+
private: isPrivate,
|
|
34
|
+
metadata: metadata
|
|
35
|
+
};
|
|
36
|
+
var decoratorFinishedRef = {
|
|
37
|
+
v: false
|
|
38
|
+
};
|
|
39
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
40
|
+
var get, set;
|
|
41
|
+
if (0 === kind) if (isPrivate) {
|
|
42
|
+
get = desc.get;
|
|
43
|
+
set = desc.set;
|
|
44
|
+
} else {
|
|
45
|
+
get = function() {
|
|
46
|
+
return this[name];
|
|
47
|
+
};
|
|
48
|
+
set = function(v) {
|
|
49
|
+
this[name] = v;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
else if (2 === kind) get = function() {
|
|
53
|
+
return desc.value;
|
|
54
|
+
};
|
|
55
|
+
else {
|
|
56
|
+
if (1 === kind || 3 === kind) get = function() {
|
|
57
|
+
return desc.get.call(this);
|
|
58
|
+
};
|
|
59
|
+
if (1 === kind || 4 === kind) set = function(v) {
|
|
60
|
+
desc.set.call(this, v);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
ctx.access = get && set ? {
|
|
64
|
+
get: get,
|
|
65
|
+
set: set
|
|
66
|
+
} : get ? {
|
|
67
|
+
get: get
|
|
68
|
+
} : {
|
|
69
|
+
set: set
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
return dec(value, ctx);
|
|
73
|
+
} finally{
|
|
74
|
+
decoratorFinishedRef.v = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
78
|
+
if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
79
|
+
}
|
|
80
|
+
function assertCallable(fn, hint) {
|
|
81
|
+
if ("function" != typeof fn) throw new TypeError(hint + " must be a function");
|
|
82
|
+
}
|
|
83
|
+
function assertValidReturnValue(kind, value) {
|
|
84
|
+
var type = typeof value;
|
|
85
|
+
if (1 === kind) {
|
|
86
|
+
if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
87
|
+
if (void 0 !== value.get) assertCallable(value.get, "accessor.get");
|
|
88
|
+
if (void 0 !== value.set) assertCallable(value.set, "accessor.set");
|
|
89
|
+
if (void 0 !== value.init) assertCallable(value.init, "accessor.init");
|
|
90
|
+
} else if ("function" !== type) {
|
|
91
|
+
var hint;
|
|
92
|
+
hint = 0 === kind ? "field" : 10 === kind ? "class" : "method";
|
|
93
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
97
|
+
var decs = decInfo[0];
|
|
98
|
+
var desc, init, value;
|
|
99
|
+
if (isPrivate) desc = 0 === kind || 1 === kind ? {
|
|
100
|
+
get: decInfo[3],
|
|
101
|
+
set: decInfo[4]
|
|
102
|
+
} : 3 === kind ? {
|
|
103
|
+
get: decInfo[3]
|
|
104
|
+
} : 4 === kind ? {
|
|
105
|
+
set: decInfo[3]
|
|
106
|
+
} : {
|
|
107
|
+
value: decInfo[3]
|
|
108
|
+
};
|
|
109
|
+
else if (0 !== kind) desc = Object.getOwnPropertyDescriptor(base, name);
|
|
110
|
+
if (1 === kind) value = {
|
|
111
|
+
get: desc.get,
|
|
112
|
+
set: desc.set
|
|
113
|
+
};
|
|
114
|
+
else if (2 === kind) value = desc.value;
|
|
115
|
+
else if (3 === kind) value = desc.get;
|
|
116
|
+
else if (4 === kind) value = desc.set;
|
|
117
|
+
var newValue, get, set;
|
|
118
|
+
if ("function" == typeof decs) {
|
|
119
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
120
|
+
if (void 0 !== newValue) {
|
|
121
|
+
assertValidReturnValue(kind, newValue);
|
|
122
|
+
if (0 === kind) init = newValue;
|
|
123
|
+
else if (1 === kind) {
|
|
124
|
+
init = newValue.init;
|
|
125
|
+
get = newValue.get || value.get;
|
|
126
|
+
set = newValue.set || value.set;
|
|
127
|
+
value = {
|
|
128
|
+
get: get,
|
|
129
|
+
set: set
|
|
130
|
+
};
|
|
131
|
+
} else value = newValue;
|
|
132
|
+
}
|
|
133
|
+
} else for(var i = decs.length - 1; i >= 0; i--){
|
|
134
|
+
var dec = decs[i];
|
|
135
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
136
|
+
if (void 0 !== newValue) {
|
|
137
|
+
assertValidReturnValue(kind, newValue);
|
|
138
|
+
var newInit;
|
|
139
|
+
if (0 === kind) newInit = newValue;
|
|
140
|
+
else if (1 === kind) {
|
|
141
|
+
newInit = newValue.init;
|
|
142
|
+
get = newValue.get || value.get;
|
|
143
|
+
set = newValue.set || value.set;
|
|
144
|
+
value = {
|
|
145
|
+
get: get,
|
|
146
|
+
set: set
|
|
147
|
+
};
|
|
148
|
+
} else value = newValue;
|
|
149
|
+
if (void 0 !== newInit) if (void 0 === init) init = newInit;
|
|
150
|
+
else if ("function" == typeof init) init = [
|
|
151
|
+
init,
|
|
152
|
+
newInit
|
|
153
|
+
];
|
|
154
|
+
else init.push(newInit);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (0 === kind || 1 === kind) {
|
|
158
|
+
if (void 0 === init) init = function(instance, init) {
|
|
159
|
+
return init;
|
|
160
|
+
};
|
|
161
|
+
else if ("function" != typeof init) {
|
|
162
|
+
var ownInitializers = init;
|
|
163
|
+
init = function(instance, init) {
|
|
164
|
+
var value = init;
|
|
165
|
+
for(var i = 0; i < ownInitializers.length; i++)value = ownInitializers[i].call(instance, value);
|
|
166
|
+
return value;
|
|
167
|
+
};
|
|
168
|
+
} else {
|
|
169
|
+
var originalInitializer = init;
|
|
170
|
+
init = function(instance, init) {
|
|
171
|
+
return originalInitializer.call(instance, init);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
ret.push(init);
|
|
175
|
+
}
|
|
176
|
+
if (0 !== kind) {
|
|
177
|
+
if (1 === kind) {
|
|
178
|
+
desc.get = value.get;
|
|
179
|
+
desc.set = value.set;
|
|
180
|
+
} else if (2 === kind) desc.value = value;
|
|
181
|
+
else if (3 === kind) desc.get = value;
|
|
182
|
+
else if (4 === kind) desc.set = value;
|
|
183
|
+
if (isPrivate) if (1 === kind) {
|
|
184
|
+
ret.push(function(instance, args) {
|
|
185
|
+
return value.get.call(instance, args);
|
|
186
|
+
});
|
|
187
|
+
ret.push(function(instance, args) {
|
|
188
|
+
return value.set.call(instance, args);
|
|
189
|
+
});
|
|
190
|
+
} else if (2 === kind) ret.push(value);
|
|
191
|
+
else ret.push(function(instance, args) {
|
|
192
|
+
return value.call(instance, args);
|
|
193
|
+
});
|
|
194
|
+
else Object.defineProperty(base, name, desc);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
198
|
+
var ret = [];
|
|
199
|
+
var protoInitializers;
|
|
200
|
+
var staticInitializers;
|
|
201
|
+
var existingProtoNonFields = new Map();
|
|
202
|
+
var existingStaticNonFields = new Map();
|
|
203
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
204
|
+
var decInfo = decInfos[i];
|
|
205
|
+
if (Array.isArray(decInfo)) {
|
|
206
|
+
var kind = decInfo[1];
|
|
207
|
+
var name = decInfo[2];
|
|
208
|
+
var isPrivate = decInfo.length > 3;
|
|
209
|
+
var isStatic = kind >= 5;
|
|
210
|
+
var base;
|
|
211
|
+
var initializers;
|
|
212
|
+
if (isStatic) {
|
|
213
|
+
base = Class;
|
|
214
|
+
kind -= 5;
|
|
215
|
+
staticInitializers = staticInitializers || [];
|
|
216
|
+
initializers = staticInitializers;
|
|
217
|
+
} else {
|
|
218
|
+
base = Class.prototype;
|
|
219
|
+
protoInitializers = protoInitializers || [];
|
|
220
|
+
initializers = protoInitializers;
|
|
221
|
+
}
|
|
222
|
+
if (0 !== kind && !isPrivate) {
|
|
223
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
224
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
225
|
+
if (true === existingKind || 3 === existingKind && 4 !== kind || 4 === existingKind && 3 !== kind) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
226
|
+
if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
227
|
+
else existingNonFields.set(name, true);
|
|
228
|
+
}
|
|
229
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
pushInitializers(ret, protoInitializers);
|
|
233
|
+
pushInitializers(ret, staticInitializers);
|
|
234
|
+
return ret;
|
|
235
|
+
}
|
|
236
|
+
function pushInitializers(ret, initializers) {
|
|
237
|
+
if (initializers) ret.push(function(instance) {
|
|
238
|
+
for(var i = 0; i < initializers.length; i++)initializers[i].call(instance);
|
|
239
|
+
return instance;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
243
|
+
if (classDecs.length > 0) {
|
|
244
|
+
var initializers = [];
|
|
245
|
+
var newClass = targetClass;
|
|
246
|
+
var name = targetClass.name;
|
|
247
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
248
|
+
var decoratorFinishedRef = {
|
|
249
|
+
v: false
|
|
250
|
+
};
|
|
251
|
+
try {
|
|
252
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
253
|
+
kind: "class",
|
|
254
|
+
name: name,
|
|
255
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
256
|
+
metadata
|
|
257
|
+
});
|
|
258
|
+
} finally{
|
|
259
|
+
decoratorFinishedRef.v = true;
|
|
260
|
+
}
|
|
261
|
+
if (void 0 !== nextNewClass) {
|
|
262
|
+
assertValidReturnValue(10, nextNewClass);
|
|
263
|
+
newClass = nextNewClass;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return [
|
|
267
|
+
defineMetadata(newClass, metadata),
|
|
268
|
+
function() {
|
|
269
|
+
for(var i = 0; i < initializers.length; i++)initializers[i].call(newClass);
|
|
270
|
+
}
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function defineMetadata(Class, metadata) {
|
|
275
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
276
|
+
configurable: true,
|
|
277
|
+
enumerable: true,
|
|
278
|
+
value: metadata
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return function(targetClass, memberDecs, classDecs, parentClass) {
|
|
282
|
+
if (void 0 !== parentClass) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
283
|
+
var metadata = Object.create(void 0 === parentMetadata ? null : parentMetadata);
|
|
284
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
285
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
286
|
+
return {
|
|
287
|
+
e: e,
|
|
288
|
+
get c () {
|
|
289
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
295
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
296
|
+
}
|
|
297
|
+
var _dec, _initClass;
|
|
298
|
+
let _LaunchDarklyToolbarService;
|
|
299
|
+
_dec = Injectable({
|
|
300
|
+
providedIn: 'root'
|
|
301
|
+
});
|
|
302
|
+
class LaunchDarklyToolbarService {
|
|
303
|
+
static{
|
|
304
|
+
({ c: [_LaunchDarklyToolbarService, _initClass] } = _apply_decs_2203_r(this, [], [
|
|
305
|
+
_dec
|
|
306
|
+
]));
|
|
307
|
+
}
|
|
308
|
+
cleanup;
|
|
309
|
+
abortController;
|
|
310
|
+
initialized = false;
|
|
311
|
+
async initialize(config) {
|
|
312
|
+
if (this.initialized) return void console.warn('[LaunchDarkly Toolbar] Already initialized. Call destroy() first to reinitialize.');
|
|
313
|
+
const { toolbarBundleUrl, enabled, ...initConfig } = config;
|
|
314
|
+
if (false === enabled) return;
|
|
315
|
+
this.initialized = true;
|
|
316
|
+
this.abortController = new AbortController();
|
|
317
|
+
const url = toolbarBundleUrl ?? this.versionToCdn(package_namespaceObject.rE);
|
|
318
|
+
try {
|
|
319
|
+
const toolbar = await lazyLoadToolbar(this.abortController.signal, url);
|
|
320
|
+
this.cleanup = toolbar.init(initConfig);
|
|
321
|
+
} catch (err) {
|
|
322
|
+
console.error('[LaunchDarkly Toolbar] Failed to initialize:', err);
|
|
323
|
+
this.initialized = false;
|
|
324
|
+
throw err;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
ngOnDestroy() {
|
|
328
|
+
this.destroy();
|
|
329
|
+
}
|
|
330
|
+
destroy() {
|
|
331
|
+
if (this.abortController) {
|
|
332
|
+
this.abortController.abort();
|
|
333
|
+
this.abortController = void 0;
|
|
334
|
+
}
|
|
335
|
+
if (this.cleanup) {
|
|
336
|
+
this.cleanup();
|
|
337
|
+
this.cleanup = void 0;
|
|
338
|
+
}
|
|
339
|
+
this.initialized = false;
|
|
340
|
+
}
|
|
341
|
+
isInitialized() {
|
|
342
|
+
return this.initialized;
|
|
343
|
+
}
|
|
344
|
+
versionToCdn(version = 'latest') {
|
|
345
|
+
return `https://unpkg.com/@launchdarkly/toolbar@${version}/cdn/toolbar.min.js`;
|
|
346
|
+
}
|
|
347
|
+
static{
|
|
348
|
+
_initClass();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
export { _LaunchDarklyToolbarService as LaunchDarklyToolbarService };
|
|
352
|
+
|
|
353
|
+
//# sourceMappingURL=angular.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js/angular.js","sources":["../../src/angular/launchdarkly-toolbar.service.ts"],"sourcesContent":["import { Injectable, OnDestroy } from '@angular/core';\n\nimport lazyLoadToolbar from '../core/lazyLoadToolbar';\nimport type { InitializationConfig } from '../types';\nimport packageJson from '../../package.json';\n\n/**\n * Configuration options for the LaunchDarkly Toolbar service.\n * Extends the base InitializationConfig with Angular-specific options.\n */\nexport interface LaunchDarklyToolbarConfig extends InitializationConfig {\n /**\n * URL to load the toolbar bundle from.\n * Use this when developing the toolbar itself locally.\n *\n * Example: `'http://localhost:5764/toolbar.min.js'`\n *\n * Default: CDN URL based on package version\n */\n toolbarBundleUrl?: string;\n\n /**\n * Whether the toolbar should be loaded and displayed.\n *\n * Default: `true`\n */\n enabled?: boolean;\n}\n\n/**\n * Injectable service for managing the LaunchDarkly Developer Toolbar in Angular applications.\n *\n * This service handles the lifecycle of the toolbar, including initialization,\n * lazy loading, and cleanup. It can be injected into any Angular component or service.\n *\n * @example\n * ```typescript\n * import { Component, OnInit } from '@angular/core';\n * import { LaunchDarklyToolbarService } from '@launchdarkly/toolbar/angular';\n * import { FlagOverridePlugin, EventInterceptionPlugin } from '@launchdarkly/toolbar/plugins';\n *\n * @Component({\n * selector: 'app-root',\n * standalone: true,\n * providers: [LaunchDarklyToolbarService],\n * template: '<router-outlet />'\n * })\n * export class AppComponent implements OnInit {\n * private flagOverridePlugin = new FlagOverridePlugin();\n * private eventInterceptionPlugin = new EventInterceptionPlugin();\n *\n * constructor(private toolbarService: LaunchDarklyToolbarService) {}\n *\n * ngOnInit() {\n * this.toolbarService.initialize({\n * flagOverridePlugin: this.flagOverridePlugin,\n * eventInterceptionPlugin: this.eventInterceptionPlugin,\n * enabled: true,\n * position: 'bottom-right'\n * });\n * }\n * }\n * ```\n */\n@Injectable({\n providedIn: 'root', // Singleton service across the application\n})\nexport default class LaunchDarklyToolbarService implements OnDestroy {\n private cleanup?: () => void;\n private abortController?: AbortController;\n private initialized = false;\n\n /**\n * Initializes the LaunchDarkly Toolbar with the provided configuration.\n *\n * This method lazy-loads the toolbar bundle from either a custom URL or the CDN,\n * then initializes it with the provided configuration.\n *\n * @param config - Configuration options for the toolbar\n * @returns Promise that resolves when initialization is complete\n *\n * @throws {Error} If initialization fails or toolbar bundle cannot be loaded\n */\n async initialize(config: LaunchDarklyToolbarConfig): Promise<void> {\n if (this.initialized) {\n console.warn('[LaunchDarkly Toolbar] Already initialized. Call destroy() first to reinitialize.');\n return;\n }\n\n const { toolbarBundleUrl, enabled, ...initConfig } = config;\n\n if (enabled === false) {\n return;\n }\n\n this.initialized = true;\n this.abortController = new AbortController();\n const url = toolbarBundleUrl ?? this.versionToCdn(packageJson.version);\n\n try {\n const toolbar = await lazyLoadToolbar(this.abortController.signal, url);\n this.cleanup = toolbar.init(initConfig);\n } catch (err) {\n console.error('[LaunchDarkly Toolbar] Failed to initialize:', err);\n this.initialized = false;\n throw err;\n }\n }\n\n /**\n * Angular lifecycle hook called when the service is destroyed.\n * Automatically cleans up the toolbar.\n */\n ngOnDestroy(): void {\n this.destroy();\n }\n\n /**\n * Manually destroys the toolbar and cleans up resources.\n *\n * This method:\n * - Aborts any pending lazy-load requests\n * - Calls the toolbar's cleanup function\n * - Resets the initialized state\n *\n * After calling destroy(), you can call initialize() again to reinitialize.\n */\n destroy(): void {\n if (this.abortController) {\n this.abortController.abort();\n this.abortController = undefined;\n }\n if (this.cleanup) {\n this.cleanup();\n this.cleanup = undefined;\n }\n this.initialized = false;\n }\n\n /**\n * Checks if the toolbar has been initialized.\n *\n * @returns true if the toolbar is currently initialized, false otherwise\n */\n isInitialized(): boolean {\n return this.initialized;\n }\n\n /**\n * Generates the CDN URL for a specific toolbar version.\n *\n * @param version - Toolbar version (defaults to 'latest')\n * @returns CDN URL for the toolbar bundle\n */\n private versionToCdn(version = 'latest'): string {\n return `https://unpkg.com/@launchdarkly/toolbar@${version}/cdn/toolbar.min.js`;\n }\n}\n"],"names":["Injectable","_LaunchDarklyToolbarService","config","console","toolbarBundleUrl","enabled","initConfig","AbortController","url","packageJson","toolbar","lazyLoadToolbar","err","undefined","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgECA,WAAW;IACV,YAAY;AACd;AACe,MAAMC;;;;;;IACX,QAAqB;IACrB,gBAAkC;IAClC,cAAc,MAAM;IAa5B,MAAM,WAAWC,MAAiC,EAAiB;QACjE,IAAI,IAAI,CAAC,WAAW,EAAE,YACpBC,QAAQ,IAAI,CAAC;QAIf,MAAM,EAAEC,gBAAgB,EAAEC,OAAO,EAAE,GAAGC,YAAY,GAAGJ;QAErD,IAAIG,AAAY,UAAZA,SACF;QAGF,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,CAAC,eAAe,GAAG,IAAIE;QAC3B,MAAMC,MAAMJ,oBAAoB,IAAI,CAAC,YAAY,CAACK,wBAAAA,EAAmB;QAErE,IAAI;YACF,MAAMC,UAAU,MAAMC,gBAAgB,IAAI,CAAC,eAAe,CAAC,MAAM,EAAEH;YACnE,IAAI,CAAC,OAAO,GAAGE,QAAQ,IAAI,CAACJ;QAC9B,EAAE,OAAOM,KAAK;YACZT,QAAQ,KAAK,CAAC,gDAAgDS;YAC9D,IAAI,CAAC,WAAW,GAAG;YACnB,MAAMA;QACR;IACF;IAMA,cAAoB;QAClB,IAAI,CAAC,OAAO;IACd;IAYA,UAAgB;QACd,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,IAAI,CAAC,eAAe,CAAC,KAAK;YAC1B,IAAI,CAAC,eAAe,GAAGC;QACzB;QACA,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,OAAO,GAAGA;QACjB;QACA,IAAI,CAAC,WAAW,GAAG;IACrB;IAOA,gBAAyB;QACvB,OAAO,IAAI,CAAC,WAAW;IACzB;IAQQ,aAAaC,UAAU,QAAQ,EAAU;QAC/C,OAAO,CAAC,wCAAwC,EAAEA,QAAQ,mBAAmB,CAAC;IAChF;;;;AACF"}
|
package/dist/js/react.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { lazyLoadToolbar
|
|
1
|
+
export { lazyLoadToolbar } from "./816.js";
|
|
2
|
+
export { useLaunchDarklyToolbar } from "./96.js";
|
package/dist/js/vue.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { onMounted, onUnmounted, ref } from "vue";
|
|
2
|
+
import { package_namespaceObject, lazyLoadToolbar } from "./816.js";
|
|
3
|
+
function useLaunchDarklyToolbar(args) {
|
|
4
|
+
const { toolbarBundleUrl, enabled, ...initConfig } = args;
|
|
5
|
+
const configRef = ref(null);
|
|
6
|
+
const cleanupRef = ref(null);
|
|
7
|
+
const controllerRef = ref(null);
|
|
8
|
+
const url = toolbarBundleUrl ?? versionToCdn(package_namespaceObject.rE);
|
|
9
|
+
onMounted(()=>{
|
|
10
|
+
if (false === enabled) return;
|
|
11
|
+
if (null === configRef.value || null == initConfig) configRef.value = initConfig;
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
controllerRef.value = controller;
|
|
14
|
+
let cleanup = ()=>{};
|
|
15
|
+
lazyLoadToolbar(controller.signal, url).then((importedToolbar)=>{
|
|
16
|
+
if (null === configRef.value) return;
|
|
17
|
+
cleanup = importedToolbar.init(configRef.value);
|
|
18
|
+
cleanupRef.value = cleanup;
|
|
19
|
+
}).catch((error)=>{
|
|
20
|
+
console.error('[LaunchDarkly Toolbar] Failed to initialize:', error);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
onUnmounted(()=>{
|
|
24
|
+
if (controllerRef.value) controllerRef.value.abort();
|
|
25
|
+
if (cleanupRef.value) cleanupRef.value();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function versionToCdn(version = 'latest') {
|
|
29
|
+
return `https://unpkg.com/@launchdarkly/toolbar@${version}/cdn/toolbar.min.js`;
|
|
30
|
+
}
|
|
31
|
+
export { lazyLoadToolbar } from "./816.js";
|
|
32
|
+
export { useLaunchDarklyToolbar };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js/vue.js","sources":["../../src/vue/useLaunchDarklyToolbar.ts"],"sourcesContent":["import { onMounted, onUnmounted, ref } from 'vue';\n\nimport lazyLoadToolbar from '../core/lazyLoadToolbar';\nimport type { InitializationConfig } from '../types';\nimport packageJson from '../../package.json';\n\ninterface UseLaunchDarklyToolbarConfig extends InitializationConfig {\n /**\n * URL to load the toolbar bundle from.\n * Use this when developing the toolbar itself locally.\n *\n * Example: `'http://localhost:5764/toolbar.min.js'`\n *\n * Default: CDN URL based on package version\n */\n toolbarBundleUrl?: string;\n\n /**\n * Whether the toolbar should be loaded and displayed.\n *\n * Default: `true`\n */\n enabled?: boolean;\n}\n\nexport default function useLaunchDarklyToolbar(args: UseLaunchDarklyToolbarConfig) {\n const { toolbarBundleUrl, enabled, ...initConfig } = args;\n const configRef = ref<InitializationConfig | null>(null);\n const cleanupRef = ref<(() => void) | null>(null);\n const controllerRef = ref<AbortController | null>(null);\n const url = toolbarBundleUrl ?? versionToCdn(packageJson.version);\n\n onMounted(() => {\n if (enabled === false) {\n return;\n }\n\n if (configRef.value === null || initConfig == null) {\n configRef.value = initConfig;\n }\n\n const controller = new AbortController();\n controllerRef.value = controller;\n\n let cleanup: () => void = () => {};\n lazyLoadToolbar(controller.signal, url)\n .then((importedToolbar) => {\n if (configRef.value === null) {\n return;\n }\n\n cleanup = importedToolbar.init(configRef.value);\n cleanupRef.value = cleanup;\n })\n .catch((error) => {\n console.error('[LaunchDarkly Toolbar] Failed to initialize:', error);\n });\n });\n\n onUnmounted(() => {\n if (controllerRef.value) {\n controllerRef.value.abort();\n }\n if (cleanupRef.value) {\n cleanupRef.value();\n }\n });\n}\n\nfunction versionToCdn(version = 'latest'): string {\n return `https://unpkg.com/@launchdarkly/toolbar@${version}/cdn/toolbar.min.js`;\n}\n"],"names":["useLaunchDarklyToolbar","args","toolbarBundleUrl","enabled","initConfig","configRef","ref","cleanupRef","controllerRef","url","versionToCdn","packageJson","onMounted","controller","AbortController","cleanup","lazyLoadToolbar","importedToolbar","error","console","onUnmounted","version"],"mappings":";;AAyBe,SAASA,uBAAuBC,IAAkC;IAC/E,MAAM,EAAEC,gBAAgB,EAAEC,OAAO,EAAE,GAAGC,YAAY,GAAGH;IACrD,MAAMI,YAAYC,IAAiC;IACnD,MAAMC,aAAaD,IAAyB;IAC5C,MAAME,gBAAgBF,IAA4B;IAClD,MAAMG,MAAMP,oBAAoBQ,aAAaC,wBAAAA,EAAmB;IAEhEC,UAAU;QACR,IAAIT,AAAY,UAAZA,SACF;QAGF,IAAIE,AAAoB,SAApBA,UAAU,KAAK,IAAaD,AAAc,QAAdA,YAC9BC,UAAU,KAAK,GAAGD;QAGpB,MAAMS,aAAa,IAAIC;QACvBN,cAAc,KAAK,GAAGK;QAEtB,IAAIE,UAAsB,KAAO;QACjCC,gBAAgBH,WAAW,MAAM,EAAEJ,KAChC,IAAI,CAAC,CAACQ;YACL,IAAIZ,AAAoB,SAApBA,UAAU,KAAK,EACjB;YAGFU,UAAUE,gBAAgB,IAAI,CAACZ,UAAU,KAAK;YAC9CE,WAAW,KAAK,GAAGQ;QACrB,GACC,KAAK,CAAC,CAACG;YACNC,QAAQ,KAAK,CAAC,gDAAgDD;QAChE;IACJ;IAEAE,YAAY;QACV,IAAIZ,cAAc,KAAK,EACrBA,cAAc,KAAK,CAAC,KAAK;QAE3B,IAAID,WAAW,KAAK,EAClBA,WAAW,KAAK;IAEpB;AACF;AAEA,SAASG,aAAaW,UAAU,QAAQ;IACtC,OAAO,CAAC,wCAAwC,EAAEA,QAAQ,mBAAmB,CAAC;AAChF"}
|
package/dist/react.cjs
CHANGED
|
@@ -79,7 +79,7 @@ async function lazyLoad(signal, url) {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
var package_namespaceObject = {
|
|
82
|
-
rE: "2.
|
|
82
|
+
rE: "2.2.0"
|
|
83
83
|
};
|
|
84
84
|
function useLaunchDarklyToolbar(args) {
|
|
85
85
|
const { toolbarBundleUrl, enabled, ...initConfig } = args;
|
|
@@ -99,6 +99,8 @@ function useLaunchDarklyToolbar(args) {
|
|
|
99
99
|
lazyLoadToolbar(controller.signal, url).then((importedToolbar)=>{
|
|
100
100
|
if (null === configRef.current) return;
|
|
101
101
|
cleanup = importedToolbar.init(configRef.current);
|
|
102
|
+
}).catch((error)=>{
|
|
103
|
+
console.error('[LaunchDarkly Toolbar] Failed to initialize:', error);
|
|
102
104
|
});
|
|
103
105
|
return ()=>{
|
|
104
106
|
controller.abort();
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/
|
|
1
|
+
{"version":3,"file":"react.cjs","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/core/lazyLoadToolbar.ts","../src/react/useLaunchDarklyToolbar.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { LaunchDarklyToolbar } from '../index';\n\ninterface WindowWithMaybeToolbar extends Window {\n LaunchDarklyToolbar?: LaunchDarklyToolbar;\n}\n\nfunction getWindow(): WindowWithMaybeToolbar {\n return window;\n}\n\nexport default async function lazyLoadToolbar(signal: AbortSignal, url: string): Promise<LaunchDarklyToolbar> {\n const existing = getWindow().LaunchDarklyToolbar;\n\n if (existing) {\n return Promise.resolve(existing);\n }\n\n await lazyLoad(signal, url);\n\n const toolbarModule = getWindow().LaunchDarklyToolbar;\n if (!toolbarModule) {\n throw new Error(`Unable to detect LaunchDarklyToolbar global from ${url}`);\n }\n\n return toolbarModule;\n}\n\nasync function lazyLoad(signal: AbortSignal, url: string): Promise<void> {\n // Check if a script with this URL already exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`) as HTMLScriptElement | null;\n\n if (existingScript) {\n // If script already exists and is loaded, return immediately\n if (existingScript.dataset.loaded === 'true') {\n return Promise.resolve();\n }\n\n // If script exists but is still loading, wait for it to complete\n return new Promise<void>((resolve, reject) => {\n existingScript.addEventListener('load', () => {\n if (!signal.aborted) {\n existingScript.dataset.loaded = 'true';\n resolve();\n }\n });\n existingScript.addEventListener('error', (error) => {\n if (!signal.aborted) {\n reject(error);\n }\n });\n });\n }\n\n // Create new script element\n const script = document.createElement('script');\n script.src = url;\n script.crossOrigin = 'anonymous';\n script.referrerPolicy = 'origin';\n\n const waitForLoad = new Promise<void>((resolve, reject) => {\n script.addEventListener('load', () => {\n if (!signal.aborted) {\n script.dataset.loaded = 'true';\n resolve();\n }\n });\n script.addEventListener('error', (error) => {\n if (!signal.aborted) {\n reject(error);\n }\n });\n });\n\n document.body.appendChild(script);\n\n try {\n await waitForLoad;\n } catch (error) {\n console.log(error);\n throw new Error(`Could not load LaunchDarkly developer toolbar bundle from ${url}`);\n }\n}\n","import { useEffect, useRef } from 'react';\n\nimport lazyLoadToolbar from '../core/lazyLoadToolbar';\nimport type { InitializationConfig } from '../types';\nimport packageJson from '../../package.json';\n\ninterface UseLaunchDarklyToolbarConfig extends InitializationConfig {\n /**\n * URL to load the toolbar bundle from.\n * Use this when developing the toolbar itself locally.\n *\n * Example: `'http://localhost:5764/toolbar.min.js'`\n *\n * Default: CDN URL based on package version\n */\n toolbarBundleUrl?: string;\n\n /**\n * Whether the toolbar should be loaded and displayed.\n *\n * Default: `true`\n */\n enabled?: boolean;\n}\n\nexport default function useLaunchDarklyToolbar(args: UseLaunchDarklyToolbarConfig) {\n const { toolbarBundleUrl, enabled, ...initConfig } = args;\n const configRef = useRef<InitializationConfig | null>(null);\n const url = toolbarBundleUrl ?? versionToCdn(packageJson.version);\n\n useEffect(() => {\n if (enabled === false) {\n return;\n }\n\n if (configRef.current === null) {\n configRef.current = initConfig;\n }\n }, [enabled, initConfig]);\n\n useEffect(() => {\n if (enabled === false || configRef.current === null) {\n return;\n }\n\n const controller = new AbortController();\n\n let cleanup: () => void = () => {};\n lazyLoadToolbar(controller.signal, url)\n .then((importedToolbar) => {\n if (configRef.current === null) {\n return;\n }\n\n cleanup = importedToolbar.init(configRef.current);\n })\n .catch((error) => {\n console.error('[LaunchDarkly Toolbar] Failed to initialize:', error);\n });\n\n return () => {\n controller.abort();\n cleanup();\n };\n }, [enabled, url]);\n}\n\nfunction versionToCdn(version = 'latest'): string {\n return `https://unpkg.com/@launchdarkly/toolbar@${version}/cdn/toolbar.min.js`;\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","getWindow","window","lazyLoadToolbar","signal","url","existing","Promise","lazyLoad","toolbarModule","Error","existingScript","document","resolve","reject","error","script","waitForLoad","console","useLaunchDarklyToolbar","args","toolbarBundleUrl","enabled","initConfig","configRef","useRef","versionToCdn","packageJson","useEffect","controller","AbortController","cleanup","importedToolbar","version"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;ACAA,SAASI;IACP,OAAOC;AACT;AAEe,eAAeC,gBAAgBC,MAAmB,EAAEC,GAAW;IAC5E,MAAMC,WAAWL,YAAY,mBAAmB;IAEhD,IAAIK,UACF,OAAOC,QAAQ,OAAO,CAACD;IAGzB,MAAME,SAASJ,QAAQC;IAEvB,MAAMI,gBAAgBR,YAAY,mBAAmB;IACrD,IAAI,CAACQ,eACH,MAAM,IAAIC,MAAM,CAAC,iDAAiD,EAAEL,KAAK;IAG3E,OAAOI;AACT;AAEA,eAAeD,SAASJ,MAAmB,EAAEC,GAAW;IAEtD,MAAMM,iBAAiBC,SAAS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AAA,AAAAA,EAAU;QACR,IAAIN,AAAY,UAAZA,SACF;QAGF,IAAIE,AAAsB,SAAtBA,UAAU,OAAO,EACnBA,UAAU,OAAO,GAAGD;IAExB,GAAG;QAACD;QAASC;KAAW;IAExBK,IAAAA,+BAAAA,SAAAA,AAAAA,EAAU;QACR,IAAIN,AAAY,UAAZA,WAAqBE,AAAsB,SAAtBA,UAAU,OAAO,EACxC;QAGF,MAAMK,aAAa,IAAIC;QAEvB,IAAIC,UAAsB,KAAO;QACjC5B,gBAAgB0B,WAAW,MAAM,EAAExB,KAChC,IAAI,CAAC,CAAC2B;YACL,IAAIR,AAAsB,SAAtBA,UAAU,OAAO,EACnB;YAGFO,UAAUC,gBAAgB,IAAI,CAACR,UAAU,OAAO;QAClD,GACC,KAAK,CAAC,CAACT;YACNG,QAAQ,KAAK,CAAC,gDAAgDH;QAChE;QAEF,OAAO;YACLc,WAAW,KAAK;YAChBE;QACF;IACF,GAAG;QAACT;QAASjB;KAAI;AACnB;AAEA,SAASqB,aAAaO,UAAU,QAAQ;IACtC,OAAO,CAAC,wCAAwC,EAAEA,QAAQ,mBAAmB,CAAC;AAChF"}
|
package/dist/react.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { InitializationConfig } from '../types';
|
|
2
|
+
interface UseLaunchDarklyToolbarConfig extends InitializationConfig {
|
|
3
|
+
/**
|
|
4
|
+
* URL to load the toolbar bundle from.
|
|
5
|
+
* Use this when developing the toolbar itself locally.
|
|
6
|
+
*
|
|
7
|
+
* Example: `'http://localhost:5764/toolbar.min.js'`
|
|
8
|
+
*
|
|
9
|
+
* Default: CDN URL based on package version
|
|
10
|
+
*/
|
|
11
|
+
toolbarBundleUrl?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the toolbar should be loaded and displayed.
|
|
14
|
+
*
|
|
15
|
+
* Default: `true`
|
|
16
|
+
*/
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export default function useLaunchDarklyToolbar(args: UseLaunchDarklyToolbarConfig): void;
|
|
20
|
+
export {};
|
package/dist/vue.cjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
lazyLoadToolbar: ()=>lazyLoadToolbar,
|
|
28
|
+
useLaunchDarklyToolbar: ()=>useLaunchDarklyToolbar
|
|
29
|
+
});
|
|
30
|
+
const external_vue_namespaceObject = require("vue");
|
|
31
|
+
function getWindow() {
|
|
32
|
+
return window;
|
|
33
|
+
}
|
|
34
|
+
async function lazyLoadToolbar(signal, url) {
|
|
35
|
+
const existing = getWindow().LaunchDarklyToolbar;
|
|
36
|
+
if (existing) return Promise.resolve(existing);
|
|
37
|
+
await lazyLoad(signal, url);
|
|
38
|
+
const toolbarModule = getWindow().LaunchDarklyToolbar;
|
|
39
|
+
if (!toolbarModule) throw new Error(`Unable to detect LaunchDarklyToolbar global from ${url}`);
|
|
40
|
+
return toolbarModule;
|
|
41
|
+
}
|
|
42
|
+
async function lazyLoad(signal, url) {
|
|
43
|
+
const existingScript = document.querySelector(`script[src="${url}"]`);
|
|
44
|
+
if (existingScript) {
|
|
45
|
+
if ('true' === existingScript.dataset.loaded) return Promise.resolve();
|
|
46
|
+
return new Promise((resolve, reject)=>{
|
|
47
|
+
existingScript.addEventListener('load', ()=>{
|
|
48
|
+
if (!signal.aborted) {
|
|
49
|
+
existingScript.dataset.loaded = 'true';
|
|
50
|
+
resolve();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
existingScript.addEventListener('error', (error)=>{
|
|
54
|
+
if (!signal.aborted) reject(error);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const script = document.createElement("script");
|
|
59
|
+
script.src = url;
|
|
60
|
+
script.crossOrigin = 'anonymous';
|
|
61
|
+
script.referrerPolicy = 'origin';
|
|
62
|
+
const waitForLoad = new Promise((resolve, reject)=>{
|
|
63
|
+
script.addEventListener('load', ()=>{
|
|
64
|
+
if (!signal.aborted) {
|
|
65
|
+
script.dataset.loaded = 'true';
|
|
66
|
+
resolve();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
script.addEventListener('error', (error)=>{
|
|
70
|
+
if (!signal.aborted) reject(error);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
document.body.appendChild(script);
|
|
74
|
+
try {
|
|
75
|
+
await waitForLoad;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.log(error);
|
|
78
|
+
throw new Error(`Could not load LaunchDarkly developer toolbar bundle from ${url}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
var package_namespaceObject = {
|
|
82
|
+
rE: "2.2.0"
|
|
83
|
+
};
|
|
84
|
+
function useLaunchDarklyToolbar(args) {
|
|
85
|
+
const { toolbarBundleUrl, enabled, ...initConfig } = args;
|
|
86
|
+
const configRef = (0, external_vue_namespaceObject.ref)(null);
|
|
87
|
+
const cleanupRef = (0, external_vue_namespaceObject.ref)(null);
|
|
88
|
+
const controllerRef = (0, external_vue_namespaceObject.ref)(null);
|
|
89
|
+
const url = toolbarBundleUrl ?? versionToCdn(package_namespaceObject.rE);
|
|
90
|
+
(0, external_vue_namespaceObject.onMounted)(()=>{
|
|
91
|
+
if (false === enabled) return;
|
|
92
|
+
if (null === configRef.value || null == initConfig) configRef.value = initConfig;
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
controllerRef.value = controller;
|
|
95
|
+
let cleanup = ()=>{};
|
|
96
|
+
lazyLoadToolbar(controller.signal, url).then((importedToolbar)=>{
|
|
97
|
+
if (null === configRef.value) return;
|
|
98
|
+
cleanup = importedToolbar.init(configRef.value);
|
|
99
|
+
cleanupRef.value = cleanup;
|
|
100
|
+
}).catch((error)=>{
|
|
101
|
+
console.error('[LaunchDarkly Toolbar] Failed to initialize:', error);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
(0, external_vue_namespaceObject.onUnmounted)(()=>{
|
|
105
|
+
if (controllerRef.value) controllerRef.value.abort();
|
|
106
|
+
if (cleanupRef.value) cleanupRef.value();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function versionToCdn(version = 'latest') {
|
|
110
|
+
return `https://unpkg.com/@launchdarkly/toolbar@${version}/cdn/toolbar.min.js`;
|
|
111
|
+
}
|
|
112
|
+
exports.lazyLoadToolbar = __webpack_exports__.lazyLoadToolbar;
|
|
113
|
+
exports.useLaunchDarklyToolbar = __webpack_exports__.useLaunchDarklyToolbar;
|
|
114
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
115
|
+
"lazyLoadToolbar",
|
|
116
|
+
"useLaunchDarklyToolbar"
|
|
117
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
118
|
+
Object.defineProperty(exports, '__esModule', {
|
|
119
|
+
value: true
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=vue.cjs.map
|
package/dist/vue.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.cjs","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/core/lazyLoadToolbar.ts","../src/vue/useLaunchDarklyToolbar.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { LaunchDarklyToolbar } from '../index';\n\ninterface WindowWithMaybeToolbar extends Window {\n LaunchDarklyToolbar?: LaunchDarklyToolbar;\n}\n\nfunction getWindow(): WindowWithMaybeToolbar {\n return window;\n}\n\nexport default async function lazyLoadToolbar(signal: AbortSignal, url: string): Promise<LaunchDarklyToolbar> {\n const existing = getWindow().LaunchDarklyToolbar;\n\n if (existing) {\n return Promise.resolve(existing);\n }\n\n await lazyLoad(signal, url);\n\n const toolbarModule = getWindow().LaunchDarklyToolbar;\n if (!toolbarModule) {\n throw new Error(`Unable to detect LaunchDarklyToolbar global from ${url}`);\n }\n\n return toolbarModule;\n}\n\nasync function lazyLoad(signal: AbortSignal, url: string): Promise<void> {\n // Check if a script with this URL already exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`) as HTMLScriptElement | null;\n\n if (existingScript) {\n // If script already exists and is loaded, return immediately\n if (existingScript.dataset.loaded === 'true') {\n return Promise.resolve();\n }\n\n // If script exists but is still loading, wait for it to complete\n return new Promise<void>((resolve, reject) => {\n existingScript.addEventListener('load', () => {\n if (!signal.aborted) {\n existingScript.dataset.loaded = 'true';\n resolve();\n }\n });\n existingScript.addEventListener('error', (error) => {\n if (!signal.aborted) {\n reject(error);\n }\n });\n });\n }\n\n // Create new script element\n const script = document.createElement('script');\n script.src = url;\n script.crossOrigin = 'anonymous';\n script.referrerPolicy = 'origin';\n\n const waitForLoad = new Promise<void>((resolve, reject) => {\n script.addEventListener('load', () => {\n if (!signal.aborted) {\n script.dataset.loaded = 'true';\n resolve();\n }\n });\n script.addEventListener('error', (error) => {\n if (!signal.aborted) {\n reject(error);\n }\n });\n });\n\n document.body.appendChild(script);\n\n try {\n await waitForLoad;\n } catch (error) {\n console.log(error);\n throw new Error(`Could not load LaunchDarkly developer toolbar bundle from ${url}`);\n }\n}\n","import { onMounted, onUnmounted, ref } from 'vue';\n\nimport lazyLoadToolbar from '../core/lazyLoadToolbar';\nimport type { InitializationConfig } from '../types';\nimport packageJson from '../../package.json';\n\ninterface UseLaunchDarklyToolbarConfig extends InitializationConfig {\n /**\n * URL to load the toolbar bundle from.\n * Use this when developing the toolbar itself locally.\n *\n * Example: `'http://localhost:5764/toolbar.min.js'`\n *\n * Default: CDN URL based on package version\n */\n toolbarBundleUrl?: string;\n\n /**\n * Whether the toolbar should be loaded and displayed.\n *\n * Default: `true`\n */\n enabled?: boolean;\n}\n\nexport default function useLaunchDarklyToolbar(args: UseLaunchDarklyToolbarConfig) {\n const { toolbarBundleUrl, enabled, ...initConfig } = args;\n const configRef = ref<InitializationConfig | null>(null);\n const cleanupRef = ref<(() => void) | null>(null);\n const controllerRef = ref<AbortController | null>(null);\n const url = toolbarBundleUrl ?? versionToCdn(packageJson.version);\n\n onMounted(() => {\n if (enabled === false) {\n return;\n }\n\n if (configRef.value === null || initConfig == null) {\n configRef.value = initConfig;\n }\n\n const controller = new AbortController();\n controllerRef.value = controller;\n\n let cleanup: () => void = () => {};\n lazyLoadToolbar(controller.signal, url)\n .then((importedToolbar) => {\n if (configRef.value === null) {\n return;\n }\n\n cleanup = importedToolbar.init(configRef.value);\n cleanupRef.value = cleanup;\n })\n .catch((error) => {\n console.error('[LaunchDarkly Toolbar] Failed to initialize:', error);\n });\n });\n\n onUnmounted(() => {\n if (controllerRef.value) {\n controllerRef.value.abort();\n }\n if (cleanupRef.value) {\n cleanupRef.value();\n }\n });\n}\n\nfunction versionToCdn(version = 'latest'): string {\n return `https://unpkg.com/@launchdarkly/toolbar@${version}/cdn/toolbar.min.js`;\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","getWindow","window","lazyLoadToolbar","signal","url","existing","Promise","lazyLoad","toolbarModule","Error","existingScript","document","resolve","reject","error","script","waitForLoad","console","useLaunchDarklyToolbar","args","toolbarBundleUrl","enabled","initConfig","configRef","ref","cleanupRef","controllerRef","versionToCdn","packageJson","onMounted","controller","AbortController","cleanup","importedToolbar","onUnmounted","version"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;ACAA,SAASI;IACP,OAAOC;AACT;AAEe,eAAeC,gBAAgBC,MAAmB,EAAEC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