@awesomeness-js/server 1.1.11 → 1.1.13
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/package.json +1 -1
- package/src/componentAndPageMemory.js +47 -19
- package/src/componentDependencies.js +2 -4
- package/tests/componentAndPageMemory.test.js +1 -0
- package/tests/fetchPage.test.js +2 -0
- package/tests/fixtures/site-and-components/components/app/cleanMain/index.js +26 -0
- package/tests/fixtures/site-and-components/components/app/cleanMain.js +14 -0
- package/tests/fixtures/site-and-components/components/app/index.css +4 -0
- package/tests/fixtures/site-and-components/components/app/index.js +42 -0
- package/tests/fixtures/site-and-components/components/app/insertIntoList.jquery.js +150 -0
- package/tests/fixtures/site-and-components/components/app/keyUpWithTimeout.jQuery.js +26 -0
- package/tests/fixtures/site-and-components/components/app/onEnter.jQuery.js +39 -0
- package/tests/fixtures/site-and-components/components/app/onResize.jQuery.js +64 -0
- package/tests/fixtures/site-and-components/components/app/pwa/_.css +305 -0
- package/tests/fixtures/site-and-components/components/app/pwa/index.js +235 -0
- package/tests/fixtures/site-and-components/components/app/pwa/updateProfileImage.js +7 -0
- package/tests/fixtures/site-and-components/components/app/shapes.css +3 -0
- package/tests/fixtures/site-and-components/components/app/simple/_.css +151 -0
- package/tests/fixtures/site-and-components/components/app/simple/index.js +170 -0
- package/tests/fixtures/site-and-components/components/app/start.js +165 -0
- package/tests/fixtures/site-and-components/components/app/vanilla/_.css +1 -0
- package/tests/fixtures/site-and-components/components/app/vanilla/index.js +27 -0
- package/tests/fixtures/site-and-components/components/scrollSpy/elm.js +172 -0
- package/tests/fixtures/site-and-components/components/scrollSpy/index.js +63 -0
- package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolGet.js +91 -0
- package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolRegistry.js +18 -0
- package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolSubscribe.js +37 -0
- package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolUnsubscribe.js +44 -0
- package/tests/fixtures/site-and-components/components/scrollSpy/top.js +86 -0
- package/tests/fixtures/site-and-components/sites/site-a/pages/home/js/index.js +41 -8
package/package.json
CHANGED
|
@@ -8,6 +8,13 @@ const REFS_CACHE_LIMIT = 5000;
|
|
|
8
8
|
const fileCache = new Map();
|
|
9
9
|
const refsCache = new Map();
|
|
10
10
|
|
|
11
|
+
const DEFAULT_EXTRACT_OPTIONS = Object.freeze({
|
|
12
|
+
namespace: "ui",
|
|
13
|
+
includeCall: true,
|
|
14
|
+
includeDotAccess: false,
|
|
15
|
+
cacheContext: "",
|
|
16
|
+
});
|
|
17
|
+
|
|
11
18
|
function toMB(bytes) {
|
|
12
19
|
|
|
13
20
|
return Number((bytes / (1024 * 1024)).toFixed(6));
|
|
@@ -62,14 +69,35 @@ function hashContent(content) {
|
|
|
62
69
|
|
|
63
70
|
}
|
|
64
71
|
|
|
65
|
-
function
|
|
72
|
+
function normalizeExtractOptions(
|
|
73
|
+
{
|
|
74
|
+
namespace = DEFAULT_EXTRACT_OPTIONS.namespace,
|
|
75
|
+
includeCall = DEFAULT_EXTRACT_OPTIONS.includeCall,
|
|
76
|
+
includeDotAccess = DEFAULT_EXTRACT_OPTIONS.includeDotAccess,
|
|
77
|
+
cacheContext,
|
|
78
|
+
} = {},
|
|
79
|
+
{
|
|
80
|
+
defaultCacheContext = DEFAULT_EXTRACT_OPTIONS.cacheContext,
|
|
81
|
+
} = {}
|
|
82
|
+
) {
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
namespace,
|
|
86
|
+
includeCall,
|
|
87
|
+
includeDotAccess,
|
|
88
|
+
cacheContext: cacheContext ?? defaultCacheContext,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function refsCacheKey(content, options = {}) {
|
|
66
94
|
|
|
67
95
|
const {
|
|
68
|
-
namespace
|
|
69
|
-
includeCall
|
|
70
|
-
includeDotAccess
|
|
71
|
-
cacheContext
|
|
72
|
-
} = options
|
|
96
|
+
namespace,
|
|
97
|
+
includeCall,
|
|
98
|
+
includeDotAccess,
|
|
99
|
+
cacheContext,
|
|
100
|
+
} = normalizeExtractOptions(options);
|
|
73
101
|
const contentHash = hashContent(content);
|
|
74
102
|
const contextPart = cacheContext ? `${cacheContext}|` : "";
|
|
75
103
|
|
|
@@ -80,11 +108,13 @@ function refsCacheKey(content, options) {
|
|
|
80
108
|
function refsCacheKeyFromFile(filePath, fileMeta, options = {}) {
|
|
81
109
|
|
|
82
110
|
const {
|
|
83
|
-
namespace
|
|
84
|
-
includeCall
|
|
85
|
-
includeDotAccess
|
|
86
|
-
cacheContext
|
|
87
|
-
} = options
|
|
111
|
+
namespace,
|
|
112
|
+
includeCall,
|
|
113
|
+
includeDotAccess,
|
|
114
|
+
cacheContext,
|
|
115
|
+
} = normalizeExtractOptions(options, {
|
|
116
|
+
defaultCacheContext: `file:${filePath}`,
|
|
117
|
+
});
|
|
88
118
|
const contextPart = cacheContext ? `${cacheContext}|` : "";
|
|
89
119
|
|
|
90
120
|
return `${contextPart}${namespace}|${includeCall}|${includeDotAccess}|mtime:${fileMeta.mtimeMs}|size:${fileMeta.size}`;
|
|
@@ -134,7 +164,8 @@ export function extractUiRefsMemoized(content, options = {}) {
|
|
|
134
164
|
|
|
135
165
|
}
|
|
136
166
|
|
|
137
|
-
const
|
|
167
|
+
const extractionOptions = normalizeExtractOptions(options);
|
|
168
|
+
const key = refsCacheKey(content, extractionOptions);
|
|
138
169
|
const existing = refsCache.get(key);
|
|
139
170
|
|
|
140
171
|
if (existing) {
|
|
@@ -143,7 +174,7 @@ export function extractUiRefsMemoized(content, options = {}) {
|
|
|
143
174
|
|
|
144
175
|
}
|
|
145
176
|
|
|
146
|
-
const refs = extractUiComponentRefs(content,
|
|
177
|
+
const refs = extractUiComponentRefs(content, extractionOptions);
|
|
147
178
|
|
|
148
179
|
refsCache.set(key, refs);
|
|
149
180
|
pruneCache(refsCache, REFS_CACHE_LIMIT);
|
|
@@ -155,12 +186,9 @@ export function extractUiRefsMemoized(content, options = {}) {
|
|
|
155
186
|
export function extractUiRefsFromFileMemoized(filePath, options = {}) {
|
|
156
187
|
|
|
157
188
|
const fileEntry = getFileCacheEntry(filePath);
|
|
158
|
-
const extractionOptions = options
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
...options,
|
|
162
|
-
cacheContext: `file:${filePath}`,
|
|
163
|
-
};
|
|
189
|
+
const extractionOptions = normalizeExtractOptions(options, {
|
|
190
|
+
defaultCacheContext: `file:${filePath}`,
|
|
191
|
+
});
|
|
164
192
|
const key = refsCacheKeyFromFile(filePath, fileEntry, extractionOptions);
|
|
165
193
|
const existing = refsCache.get(key);
|
|
166
194
|
|
|
@@ -2,10 +2,7 @@ import path from "path";
|
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import { each, getAllFiles } from "@awesomeness-js/utils";
|
|
4
4
|
import getConfig from "./getConfig.js";
|
|
5
|
-
import {
|
|
6
|
-
extractUiRefsFromFileMemoized,
|
|
7
|
-
readFileMemoized,
|
|
8
|
-
} from "./componentAndPageMemory.js";
|
|
5
|
+
import { extractUiRefsFromFileMemoized, readFileMemoized } from "./componentAndPageMemory.js";
|
|
9
6
|
|
|
10
7
|
function urlToFsPath(u) {
|
|
11
8
|
|
|
@@ -182,6 +179,7 @@ export default function componentDependencies(
|
|
|
182
179
|
|
|
183
180
|
const newTest = extractUiRefsFromFileMemoized(filePath, {
|
|
184
181
|
namespace,
|
|
182
|
+
includeDotAccess: true,
|
|
185
183
|
cacheContext: `component:${component}|file:${filePath}`,
|
|
186
184
|
});
|
|
187
185
|
|
package/tests/fetchPage.test.js
CHANGED
|
@@ -48,6 +48,7 @@ describe("fetchPage component inference", () => {
|
|
|
48
48
|
"css"
|
|
49
49
|
);
|
|
50
50
|
const expectedComponents = [
|
|
51
|
+
"app",
|
|
51
52
|
"card",
|
|
52
53
|
"cardMain",
|
|
53
54
|
"cardMount",
|
|
@@ -201,6 +202,7 @@ describe("fetchPage component inference", () => {
|
|
|
201
202
|
console.log("fetchPage inferred components (no about.components)", inferred);
|
|
202
203
|
|
|
203
204
|
expect(inferred).toEqual([
|
|
205
|
+
"app",
|
|
204
206
|
"cardMain",
|
|
205
207
|
"cardMount",
|
|
206
208
|
"pageInit",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default ({
|
|
2
|
+
withFullScreenHero = false
|
|
3
|
+
} = {}) => {
|
|
4
|
+
|
|
5
|
+
if(!app.$main){
|
|
6
|
+
|
|
7
|
+
app.$main = $('#main');
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if(withFullScreenHero){
|
|
12
|
+
|
|
13
|
+
app.$main.addClass('withFullScreenHero');
|
|
14
|
+
|
|
15
|
+
} else {
|
|
16
|
+
|
|
17
|
+
app.$main.removeClass('withFullScreenHero');
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
app.$main.empty();
|
|
22
|
+
$(document).scrollTop(0);
|
|
23
|
+
|
|
24
|
+
return app.$main;
|
|
25
|
+
|
|
26
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import ui from '#ui';
|
|
2
|
+
|
|
3
|
+
export default function silentStart({
|
|
4
|
+
theme = {
|
|
5
|
+
name: 'light',
|
|
6
|
+
neutralColor: 'zinc',
|
|
7
|
+
accentColor: 'cyan',
|
|
8
|
+
customColors: {},
|
|
9
|
+
}
|
|
10
|
+
}) {
|
|
11
|
+
|
|
12
|
+
app.theme = theme;
|
|
13
|
+
|
|
14
|
+
if(theme.customColors){
|
|
15
|
+
|
|
16
|
+
$.each(theme.customColors, (name, hexValue) => {
|
|
17
|
+
|
|
18
|
+
let inputColor;
|
|
19
|
+
let anchorShade = 600;
|
|
20
|
+
|
|
21
|
+
if(typeof hexValue === 'string'){
|
|
22
|
+
|
|
23
|
+
inputColor = hexValue;
|
|
24
|
+
|
|
25
|
+
} else if(typeof hexValue === 'object' && hexValue !== null){
|
|
26
|
+
|
|
27
|
+
inputColor = hexValue.inputColor;
|
|
28
|
+
anchorShade = hexValue.anchorShade || anchorShade;
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ui.colors.custom({
|
|
33
|
+
inputColor: inputColor,
|
|
34
|
+
anchorShade: 600,
|
|
35
|
+
name
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
(function(){
|
|
2
|
+
|
|
3
|
+
// IMPORTANT NOTE: with custom sortFn's use toLowerCase !!
|
|
4
|
+
$.fn.extend({
|
|
5
|
+
|
|
6
|
+
//Name the function
|
|
7
|
+
insertIntoList: function($ul, options) {
|
|
8
|
+
|
|
9
|
+
var defaults = {
|
|
10
|
+
'sortFn':function($elm){
|
|
11
|
+
|
|
12
|
+
return $elm.html().toLowerCase();
|
|
13
|
+
|
|
14
|
+
},
|
|
15
|
+
'insertBeforeLast':false,
|
|
16
|
+
'za':false,
|
|
17
|
+
'selector':null
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var options = $.extend(defaults, options); // jshint ignore:line
|
|
21
|
+
|
|
22
|
+
return this.each(function() {
|
|
23
|
+
|
|
24
|
+
if(!$ul){
|
|
25
|
+
|
|
26
|
+
return false;
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// From here on in, it's "normal" jQuery
|
|
31
|
+
|
|
32
|
+
var $li = $(this); // new item
|
|
33
|
+
var $lis;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if(options.selector){
|
|
37
|
+
|
|
38
|
+
$lis = $ul.children(options.selector); // existing items
|
|
39
|
+
|
|
40
|
+
} else {
|
|
41
|
+
|
|
42
|
+
$lis = $ul.children(); // existing items
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var newHtml = options.sortFn($li);
|
|
47
|
+
|
|
48
|
+
if($lis.length === 0){
|
|
49
|
+
|
|
50
|
+
$li.appendTo($ul);
|
|
51
|
+
|
|
52
|
+
return;
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
$lis.each(function(k,e){
|
|
57
|
+
|
|
58
|
+
var $t = $(this);
|
|
59
|
+
|
|
60
|
+
// meta hack for skip
|
|
61
|
+
if($t.data('insertIntoListSkip') === true){
|
|
62
|
+
|
|
63
|
+
return true;
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var isLast = $t.is( ":last-child" );
|
|
68
|
+
var current = options.sortFn($t);
|
|
69
|
+
|
|
70
|
+
if(options.insertBeforeLast && isLast){
|
|
71
|
+
|
|
72
|
+
// insert before last child
|
|
73
|
+
$li.insertBefore($t);
|
|
74
|
+
|
|
75
|
+
return false;
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if(options.za){
|
|
80
|
+
|
|
81
|
+
if(current < newHtml){
|
|
82
|
+
|
|
83
|
+
$li.insertBefore($t);
|
|
84
|
+
|
|
85
|
+
return false;
|
|
86
|
+
|
|
87
|
+
} else {
|
|
88
|
+
|
|
89
|
+
// continue if it is not the last item
|
|
90
|
+
if(!isLast){
|
|
91
|
+
|
|
92
|
+
return true;
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// it is the last item
|
|
97
|
+
if(options.insertBeforeLast){
|
|
98
|
+
|
|
99
|
+
$li.insertBefore($t);
|
|
100
|
+
|
|
101
|
+
} else {
|
|
102
|
+
|
|
103
|
+
$li.insertAfter($t);
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
} else {
|
|
110
|
+
|
|
111
|
+
if(current > newHtml){
|
|
112
|
+
|
|
113
|
+
$li.insertBefore($t);
|
|
114
|
+
|
|
115
|
+
return false;
|
|
116
|
+
|
|
117
|
+
} else {
|
|
118
|
+
|
|
119
|
+
// continue if it is not the last item
|
|
120
|
+
if(!isLast){
|
|
121
|
+
|
|
122
|
+
return true;
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// it is the last item
|
|
127
|
+
if(options.insertBeforeLast){
|
|
128
|
+
|
|
129
|
+
$li.insertBefore($t);
|
|
130
|
+
|
|
131
|
+
} else {
|
|
132
|
+
|
|
133
|
+
$li.insertAfter($t);
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
}); // each CORE
|
|
145
|
+
|
|
146
|
+
} // xoSelect Function
|
|
147
|
+
|
|
148
|
+
}); // extend
|
|
149
|
+
|
|
150
|
+
})();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
|
|
3
|
+
$.fn.keyUpWithTimeout = function(callback, timeout) {
|
|
4
|
+
|
|
5
|
+
var timer;
|
|
6
|
+
|
|
7
|
+
return this.each(function() {
|
|
8
|
+
|
|
9
|
+
let $this = $(this);
|
|
10
|
+
|
|
11
|
+
$this.on('keyup', function() {
|
|
12
|
+
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
timer = setTimeout(function() {
|
|
15
|
+
|
|
16
|
+
callback($this.val(), this);
|
|
17
|
+
|
|
18
|
+
}, timeout);
|
|
19
|
+
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
})();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
(function(){
|
|
2
|
+
|
|
3
|
+
$.fn.extend({
|
|
4
|
+
//Name the function
|
|
5
|
+
onEnter: function(fn) {
|
|
6
|
+
|
|
7
|
+
if(typeof(fn) != 'function'){
|
|
8
|
+
|
|
9
|
+
console.log('function not passed to onEnter.');
|
|
10
|
+
|
|
11
|
+
return false;
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return this.each(function() {
|
|
16
|
+
|
|
17
|
+
// From here on in, it's "normal" jQuery
|
|
18
|
+
var $t = $(this);
|
|
19
|
+
|
|
20
|
+
$t.off('keypress').on('keypress', function(e){
|
|
21
|
+
|
|
22
|
+
var keycode = (e.keyCode ? e.keyCode : e.which);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (keycode == '13') {
|
|
26
|
+
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
fn.call();
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
})();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
|
|
3
|
+
$.fn.onResize = function(callback, {
|
|
4
|
+
widthChangeOnly = true
|
|
5
|
+
} = {}) {
|
|
6
|
+
|
|
7
|
+
this.each(function() {
|
|
8
|
+
|
|
9
|
+
if (typeof callback !== 'function') {
|
|
10
|
+
|
|
11
|
+
return this;
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let lastKnownSize = 0;
|
|
16
|
+
|
|
17
|
+
function resize(entries) {
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if (!$.contains(document, $element[0])) {
|
|
21
|
+
|
|
22
|
+
resizeObserver.disconnect();
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let currentSize = $element.width();
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if(widthChangeOnly){
|
|
32
|
+
|
|
33
|
+
if (currentSize !== lastKnownSize) {
|
|
34
|
+
|
|
35
|
+
lastKnownSize = currentSize;
|
|
36
|
+
|
|
37
|
+
callback.call($element, currentSize);
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
} else {
|
|
42
|
+
|
|
43
|
+
callback.call($element, currentSize);
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var $element = $(this);
|
|
50
|
+
var resizeObserver = new ResizeObserver(resize);
|
|
51
|
+
|
|
52
|
+
// Start observing the element
|
|
53
|
+
resizeObserver.observe($element[0]);
|
|
54
|
+
|
|
55
|
+
$element.on('resize', resize );
|
|
56
|
+
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Return this for jQuery chaining
|
|
60
|
+
return this;
|
|
61
|
+
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
})();
|