web-manager 3.2.75 → 4.0.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/CLAUDE.md +42 -0
- package/README.md +63 -0
- package/TODO.md +14 -0
- package/{index.js → _legacy/index.js} +2 -2
- package/_legacy/test/test.js +158 -0
- package/dist/index.js +540 -0
- package/dist/modules/auth.js +256 -0
- package/dist/modules/bindings.js +183 -0
- package/dist/modules/dom.js +102 -0
- package/dist/modules/firestore.js +242 -0
- package/dist/modules/notifications.js +285 -0
- package/dist/modules/sentry.js +166 -0
- package/dist/modules/service-worker.js +321 -0
- package/dist/modules/storage.js +132 -0
- package/dist/modules/utilities.js +143 -0
- package/package.json +9 -8
- /package/{helpers → _legacy/helpers}/auth-pages.js +0 -0
- /package/{lib → _legacy/lib}/account.js +0 -0
- /package/{lib → _legacy/lib}/debug.js +0 -0
- /package/{lib → _legacy/lib}/dom.js +0 -0
- /package/{lib → _legacy/lib}/require.js +0 -0
- /package/{lib → _legacy/lib}/storage.js +0 -0
- /package/{lib → _legacy/lib}/utilities.js +0 -0
package/CLAUDE.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
This is a helper library that I built 6 years ago in 2019 when the web landscape was very different.
|
2
|
+
|
3
|
+
I built many functionalities that I found myself writing for every project so that I could reuse them easily.
|
4
|
+
It has been a great help in my projects, but many of these things are now not needed due to webpack, and other amazing tools.
|
5
|
+
|
6
|
+
The first thing I did is move all the old code to the "legacy" folder so that we can keep it as a reference. You should reference this as your REBUILD THE NEW LIBRARY IN "src" folder. DO NOT DELETE OR CHANGE LEGACY CODE, just reference it and recreate the functioinality I want in the "src" folder.
|
7
|
+
|
8
|
+
Going forward, you can use any new JS you want like backticks and => since we are going to transpile everything to ES5.
|
9
|
+
|
10
|
+
MAKE THIS NEW VERSION OF THE LIBRARY OPTIMIZED FOR WEBPACK (but know that it WONT ALWAYS BE USED WITH WEBPACK)
|
11
|
+
|
12
|
+
We are going to completely rewrite and refactor this library. Let's start with how and where it will be used.
|
13
|
+
1. Web: It will be webpacked with a project that transpiles everything to ES5
|
14
|
+
2. Electron: It will be used in an Electron app.
|
15
|
+
3. Chrome Extension: It will be used in a Chrome extension.
|
16
|
+
|
17
|
+
Now lets go over what I want to keep.
|
18
|
+
1. Firebase
|
19
|
+
- Let's updte to use the latest version of Firebase (12)
|
20
|
+
- I want a sort of "mini firebase auth wrapper" that has some basic functions
|
21
|
+
- auth.ready(options).then(result => {})
|
22
|
+
- This should return a promise that resolves when the auth is ready OR not (so i can call it when the page loads and result will either be the signed in user or nothing if they are not signed in)
|
23
|
+
- result (AN OBJECT) = {
|
24
|
+
user: the signed in firebase user OR null
|
25
|
+
account: the signed in user's acconunt data IF requested in options.account = true
|
26
|
+
}
|
27
|
+
- We will for sure need to have Firebase auth, firestore, messaging.
|
28
|
+
2. Manager.prototype.notifications
|
29
|
+
- Easily check if subscribed and subscribe to push notifications. Keeps track in local storage.
|
30
|
+
- automatically requests permission after a click and a timeout
|
31
|
+
3. Manager.prototype.storage
|
32
|
+
- A simple wrapper around localStorage and sessionStorage that allows for easy setting, getting, and removing of items.
|
33
|
+
4. navigator.serviceWorker.register
|
34
|
+
- A simple wrapper around the service worker registration that allows for easy registration and unregistration.
|
35
|
+
|
36
|
+
Some things we can definitely remove:
|
37
|
+
1. Most of the legacy/lib/dom.js library since webpack can help me avoid this shit. BUT i do want a light helper that does some things
|
38
|
+
- loadScript so we can load and dynamically import external scripts
|
39
|
+
2. I think we can remove init_loadPolyfills since we are transpiling, correct?
|
40
|
+
3. Most of legacy/lib/utilities.js
|
41
|
+
- Keep clipboardCopy, escapeHTML, getContext
|
42
|
+
|
package/README.md
CHANGED
@@ -264,8 +264,71 @@ The Web Manager .storage() API is a wrapper for the localStorage API that automa
|
|
264
264
|
</script>
|
265
265
|
```
|
266
266
|
|
267
|
+
### Utilizing the Data Binding System
|
268
|
+
Web Manager includes a powerful data binding system that automatically updates your DOM elements based on data changes. Simply add the `data-wm-bind` attribute to any element.
|
269
|
+
|
270
|
+
#### Basic Text Binding
|
271
|
+
```html
|
272
|
+
<!-- Display user email -->
|
273
|
+
<span data-wm-bind="user.email"></span>
|
274
|
+
|
275
|
+
<!-- Display nested properties -->
|
276
|
+
<div data-wm-bind="account.subscription.plan"></div>
|
277
|
+
|
278
|
+
<!-- Works with inputs too -->
|
279
|
+
<input data-wm-bind="settings.theme" />
|
280
|
+
```
|
281
|
+
|
282
|
+
#### Conditional Visibility
|
283
|
+
```html
|
284
|
+
<!-- Show element when condition is true -->
|
285
|
+
<div data-wm-bind="@show user">Welcome!</div>
|
286
|
+
<div data-wm-bind="@show user.emailVerified">Email is verified</div>
|
287
|
+
|
288
|
+
<!-- Hide element when condition is true -->
|
289
|
+
<div data-wm-bind="@hide user">Please log in</div>
|
290
|
+
|
291
|
+
<!-- Comparisons -->
|
292
|
+
<div data-wm-bind="@show subscription.plan === 'premium'">Premium features</div>
|
293
|
+
<div data-wm-bind="@hide settings.notifications === false">Notifications enabled</div>
|
294
|
+
```
|
295
|
+
|
296
|
+
#### Usage in JavaScript
|
297
|
+
```javascript
|
298
|
+
// Auth data is automatically bound when using auth().listen()
|
299
|
+
Manager.auth().listen({ account: true }, (result) => {
|
300
|
+
// user and account data are automatically bound to the DOM
|
301
|
+
});
|
302
|
+
|
303
|
+
// Update bindings with custom data
|
304
|
+
Manager.bindings().update({
|
305
|
+
settings: { theme: 'dark', language: 'en' },
|
306
|
+
subscription: { plan: 'premium', expiresAt: '2024-12-31' }
|
307
|
+
});
|
308
|
+
|
309
|
+
// Set individual properties
|
310
|
+
Manager.bindings().set('currentPage', 'dashboard');
|
311
|
+
|
312
|
+
// Get current binding context
|
313
|
+
const context = Manager.bindings().getContext();
|
314
|
+
|
315
|
+
// Clear all bindings
|
316
|
+
Manager.bindings().clear();
|
317
|
+
```
|
318
|
+
|
319
|
+
#### Supported Actions
|
320
|
+
- **`@text`** (default): Sets the text content of the element
|
321
|
+
- **`@show`**: Shows the element when condition is true
|
322
|
+
- **`@hide`**: Hides the element when condition is true
|
323
|
+
- **`@attr`**: Sets an attribute value (format: `@attr attributeName expression`)
|
324
|
+
|
325
|
+
Future actions like `@class` and `@style` can be easily added.
|
326
|
+
|
267
327
|
### Utilizing the Firebase Auth System
|
268
328
|
The Firebase login system works like charm out of the box without you having to write a single line of code. All you have to do is add a few classes to your HTML elements and everything will work.
|
329
|
+
|
330
|
+
#### Authentication Action Classes
|
331
|
+
* `.auth-signout-btn`: Add to a button to sign out the current user (shows confirmation dialog)
|
269
332
|
* `.auth-email-input`: Add to an input for the user's email
|
270
333
|
* `.auth-password-input`: Add to an input for the user's password
|
271
334
|
* `.auth-signin-email-btn`: Add to a button to handle the signin process
|
package/TODO.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
BRING BACK THESE THINGS FROM LEGACY:
|
2
|
+
- Add back build.json fetch
|
3
|
+
|
4
|
+
Do we need to use polyfill? the project that consumes this is using webpack and compiles to es5. we need to ensure we have
|
5
|
+
- fetch api
|
6
|
+
- promises
|
7
|
+
- async
|
8
|
+
|
9
|
+
|
10
|
+
UTM management
|
11
|
+
|
12
|
+
LOCALSTORAGE
|
13
|
+
|
14
|
+
WRAPPERS FOR COMMON FUNCITONS LIKE FIRESTORE DOC READ and QUERY AND WRITE
|
@@ -1295,7 +1295,7 @@ function refreshNewVersion(self) {
|
|
1295
1295
|
}
|
1296
1296
|
|
1297
1297
|
// Make request to get the build time (live)
|
1298
|
-
fetch('
|
1298
|
+
fetch('/build.json?cb=' + new Date().getTime())
|
1299
1299
|
.then(function (res) {
|
1300
1300
|
if (res.ok) {
|
1301
1301
|
return res.json();
|
@@ -1305,7 +1305,7 @@ function refreshNewVersion(self) {
|
|
1305
1305
|
})
|
1306
1306
|
.then(function (data) {
|
1307
1307
|
var buildTimeCurrent = self.properties.global.buildTime;
|
1308
|
-
var buildTimeLive = new Date(data
|
1308
|
+
var buildTimeLive = new Date(data.timestamp);
|
1309
1309
|
|
1310
1310
|
// Set buildTimeCurrent to 1 hour ahead to account for the npm-build time which will ALWAYS be set to later since it happens later
|
1311
1311
|
buildTimeCurrent.setHours(buildTimeCurrent.getHours() + 1);
|
@@ -0,0 +1,158 @@
|
|
1
|
+
const package = require('../package.json');
|
2
|
+
const assert = require('assert');
|
3
|
+
|
4
|
+
beforeEach(() => {
|
5
|
+
});
|
6
|
+
|
7
|
+
before(() => {
|
8
|
+
});
|
9
|
+
|
10
|
+
after(() => {
|
11
|
+
});
|
12
|
+
|
13
|
+
/*
|
14
|
+
* ============
|
15
|
+
* Test Cases
|
16
|
+
* ============
|
17
|
+
*/
|
18
|
+
describe(`${package.name}`, () => {
|
19
|
+
const _ = require('../lib/utilities.js');
|
20
|
+
const lodash = require('lodash');
|
21
|
+
|
22
|
+
// Utilities
|
23
|
+
describe('.utilities()', () => {
|
24
|
+
const sample = {
|
25
|
+
main: {
|
26
|
+
true: true,
|
27
|
+
false: false,
|
28
|
+
zero: 0,
|
29
|
+
one: 1,
|
30
|
+
string: 'string',
|
31
|
+
stringEmpty: '',
|
32
|
+
object: {},
|
33
|
+
array: [],
|
34
|
+
null: null,
|
35
|
+
undefined: undefined,
|
36
|
+
nan: NaN,
|
37
|
+
infinity: Infinity,
|
38
|
+
negativeInfinity: -Infinity,
|
39
|
+
function: function () {},
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
// Normal Cases
|
44
|
+
describe('.get()', () => {
|
45
|
+
it('should return true', () => {
|
46
|
+
// console.log('---lodash', lodash.get(sample, 'main.true'));
|
47
|
+
// console.log('---_.get', _.get(sample, 'main.true'));
|
48
|
+
// console.log('---_.get2', _.get2(sample, 'main.true'));
|
49
|
+
|
50
|
+
assert.strictEqual(_.get(sample, 'main.true'), true);
|
51
|
+
});
|
52
|
+
|
53
|
+
it('should return false', () => {
|
54
|
+
assert.strictEqual(_.get(sample, 'main.false'), false);
|
55
|
+
});
|
56
|
+
|
57
|
+
it('should return 0', () => {
|
58
|
+
assert.strictEqual(_.get(sample, 'main.zero'), 0);
|
59
|
+
});
|
60
|
+
|
61
|
+
it('should return 1', () => {
|
62
|
+
assert.strictEqual(_.get(sample, 'main.one'), 1);
|
63
|
+
});
|
64
|
+
|
65
|
+
it('should return a string', () => {
|
66
|
+
assert.strictEqual(_.get(sample, 'main.string'), 'string');
|
67
|
+
});
|
68
|
+
|
69
|
+
it('should return an empty string', () => {
|
70
|
+
assert.strictEqual(_.get(sample, 'main.stringEmpty'), '');
|
71
|
+
});
|
72
|
+
|
73
|
+
it('should return an object', () => {
|
74
|
+
assert.deepStrictEqual(_.get(sample, 'main.object'), {});
|
75
|
+
});
|
76
|
+
|
77
|
+
it('should return an array', () => {
|
78
|
+
assert.deepStrictEqual(_.get(sample, 'main.array'), []);
|
79
|
+
});
|
80
|
+
|
81
|
+
it('should return null', () => {
|
82
|
+
assert.strictEqual(_.get(sample, 'main.null'), null);
|
83
|
+
});
|
84
|
+
|
85
|
+
it('should return undefined', () => {
|
86
|
+
assert.strictEqual(_.get(sample, 'main.undefined'), undefined);
|
87
|
+
});
|
88
|
+
|
89
|
+
it('should return NaN', () => {
|
90
|
+
assert.strictEqual(Number.isNaN(_.get(sample, 'main.nan')), true);
|
91
|
+
});
|
92
|
+
|
93
|
+
it('should return Infinity', () => {
|
94
|
+
assert.strictEqual(_.get(sample, 'main.infinity'), Infinity);
|
95
|
+
});
|
96
|
+
|
97
|
+
it('should return -Infinity', () => {
|
98
|
+
assert.strictEqual(_.get(sample, 'main.negativeInfinity'), -Infinity);
|
99
|
+
});
|
100
|
+
|
101
|
+
it('should return a function', () => {
|
102
|
+
assert.strictEqual(typeof _.get(sample, 'main.function'), 'function');
|
103
|
+
});
|
104
|
+
|
105
|
+
// Non-existent
|
106
|
+
it('should return undefined', () => {
|
107
|
+
assert.strictEqual(_.get(sample, 'main.nonexistent'), undefined);
|
108
|
+
});
|
109
|
+
|
110
|
+
// No path
|
111
|
+
it('should return undefined', () => {
|
112
|
+
assert.strictEqual(_.get(sample), undefined);
|
113
|
+
});
|
114
|
+
|
115
|
+
// Empty path
|
116
|
+
it('should return undefined', () => {
|
117
|
+
assert.strictEqual(_.get(sample, ''), undefined);
|
118
|
+
});
|
119
|
+
|
120
|
+
// Default value
|
121
|
+
it('should return default value', () => {
|
122
|
+
assert.strictEqual(_.get(sample, 'main.nonexistent', 'default'), 'default');
|
123
|
+
});
|
124
|
+
|
125
|
+
it('should return actual value', () => {
|
126
|
+
assert.strictEqual(_.get(sample, 'main.false', 'default'), false);
|
127
|
+
});
|
128
|
+
|
129
|
+
it('should return actual value', () => {
|
130
|
+
assert.strictEqual(_.get(sample, 'main.null', 'default'), null);
|
131
|
+
});
|
132
|
+
|
133
|
+
it('should return default value', () => {
|
134
|
+
assert.strictEqual(_.get(sample, 'main.undefined', 'default'), 'default');
|
135
|
+
});
|
136
|
+
|
137
|
+
// Non-object for object
|
138
|
+
it('should return undefined', () => {
|
139
|
+
assert.strictEqual(_.get(undefined, 'main.true'), undefined);
|
140
|
+
});
|
141
|
+
|
142
|
+
it('should return undefined', () => {
|
143
|
+
assert.strictEqual(_.get(null, 'main.true'), undefined);
|
144
|
+
});
|
145
|
+
|
146
|
+
it('should return undefined', () => {
|
147
|
+
assert.strictEqual(_.get(false, 'main.true'), undefined);
|
148
|
+
});
|
149
|
+
|
150
|
+
it('should return undefined', () => {
|
151
|
+
assert.strictEqual(_.get('', 'main.true'), undefined);
|
152
|
+
});
|
153
|
+
|
154
|
+
});
|
155
|
+
|
156
|
+
});
|
157
|
+
|
158
|
+
})
|