@awesomeness-js/server 1.1.11 → 1.1.14

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/src/componentAndPageMemory.js +47 -19
  3. package/src/componentDependencies.js +211 -210
  4. package/tests/componentAndPageMemory.test.js +1 -0
  5. package/tests/componentDependencies.test.js +85 -0
  6. package/tests/fetchPage.test.js +2 -0
  7. package/tests/fixtures/site-and-components/components/app/cleanMain/index.js +26 -0
  8. package/tests/fixtures/site-and-components/components/app/cleanMain.js +14 -0
  9. package/tests/fixtures/site-and-components/components/app/index.css +4 -0
  10. package/tests/fixtures/site-and-components/components/app/index.js +42 -0
  11. package/tests/fixtures/site-and-components/components/app/insertIntoList.jquery.js +150 -0
  12. package/tests/fixtures/site-and-components/components/app/keyUpWithTimeout.jQuery.js +26 -0
  13. package/tests/fixtures/site-and-components/components/app/onEnter.jQuery.js +39 -0
  14. package/tests/fixtures/site-and-components/components/app/onResize.jQuery.js +64 -0
  15. package/tests/fixtures/site-and-components/components/app/pwa/_.css +305 -0
  16. package/tests/fixtures/site-and-components/components/app/pwa/index.js +235 -0
  17. package/tests/fixtures/site-and-components/components/app/pwa/updateProfileImage.js +7 -0
  18. package/tests/fixtures/site-and-components/components/app/shapes.css +3 -0
  19. package/tests/fixtures/site-and-components/components/app/simple/_.css +151 -0
  20. package/tests/fixtures/site-and-components/components/app/simple/index.js +170 -0
  21. package/tests/fixtures/site-and-components/components/app/start.js +165 -0
  22. package/tests/fixtures/site-and-components/components/app/vanilla/_.css +1 -0
  23. package/tests/fixtures/site-and-components/components/app/vanilla/index.js +27 -0
  24. package/tests/fixtures/site-and-components/components/scrollSpy/elm.js +172 -0
  25. package/tests/fixtures/site-and-components/components/scrollSpy/index.js +63 -0
  26. package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolGet.js +91 -0
  27. package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolRegistry.js +18 -0
  28. package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolSubscribe.js +37 -0
  29. package/tests/fixtures/site-and-components/components/scrollSpy/observerPoolUnsubscribe.js +44 -0
  30. package/tests/fixtures/site-and-components/components/scrollSpy/top.js +86 -0
  31. package/tests/fixtures/site-and-components/sites/site-a/pages/home/js/index.js +41 -8
@@ -0,0 +1,85 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+ import { pathToFileURL } from "url";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+
7
+ import { clearComponentAndPageMemory } from "../src/componentAndPageMemory.js";
8
+
9
+ const mocks = vi.hoisted(() => ({
10
+ getConfig: vi.fn(),
11
+ }));
12
+
13
+ vi.mock("../src/getConfig.js", () => ({
14
+ default: mocks.getConfig,
15
+ }));
16
+
17
+ import componentDependencies from "../src/componentDependencies.js";
18
+
19
+ describe("componentDependencies", () => {
20
+
21
+ let tempRoot;
22
+
23
+ function writeComponentFile(componentName, relativeFilePath, content) {
24
+
25
+ const filePath = path.join(tempRoot, componentName, relativeFilePath);
26
+
27
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
28
+ fs.writeFileSync(filePath, content);
29
+
30
+ }
31
+
32
+ beforeEach(() => {
33
+
34
+ clearComponentAndPageMemory();
35
+ tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "awes-component-deps-"));
36
+ mocks.getConfig.mockReturnValue({});
37
+
38
+ });
39
+
40
+ afterEach(() => {
41
+
42
+ clearComponentAndPageMemory();
43
+ fs.rmSync(tempRoot, {
44
+ recursive: true,
45
+ force: true
46
+ });
47
+ vi.clearAllMocks();
48
+
49
+ });
50
+
51
+ it("recursively resolves transitive dependencies through nested component files", () => {
52
+
53
+ writeComponentFile("alpha", "index.js", `export default function alpha() {
54
+ ui.beta.start();
55
+ return true;
56
+ }`);
57
+
58
+ writeComponentFile("beta", path.join("nested", "index.js"), `export default function betaNested() {
59
+ ui.gamma.mount();
60
+ return true;
61
+ }`);
62
+
63
+ writeComponentFile("gamma", path.join("deeper", "bridge.js"), `export default function gammaBridge() {
64
+ ui.delta.render();
65
+ return true;
66
+ }`);
67
+
68
+ writeComponentFile("delta", "index.js", `export default function delta() {
69
+ return "done";
70
+ }`);
71
+
72
+ const out = componentDependencies([ "alpha" ], {
73
+ componentLocations: [ pathToFileURL(tempRoot + path.sep) ],
74
+ namespace: "ui",
75
+ });
76
+
77
+ expect(Object.keys(out).sort()).toEqual([ "alpha", "beta", "delta", "gamma" ]);
78
+ expect(out.alpha.js).toContain("ui.alpha = function alpha()");
79
+ expect(out.beta.js).toContain("ui.beta.nested = function betaNested()");
80
+ expect(out.gamma.js).toContain("ui.gamma.deeper.bridge = function gammaBridge()");
81
+ expect(out.delta.js).toContain("ui.delta = function delta()");
82
+
83
+ });
84
+
85
+ });
@@ -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,14 @@
1
+ export default () => {
2
+
3
+ if(!app.$main){
4
+
5
+ app.$main = $('#main');
6
+
7
+ }
8
+
9
+ app.$main.empty();
10
+ $(document).scrollTop(0);
11
+
12
+ return app.$main;
13
+
14
+ };
@@ -0,0 +1,4 @@
1
+ #app {
2
+ margin: 0;
3
+ padding: 0;
4
+ }
@@ -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
+ })();