@onetype/framework 2.0.43 → 2.0.44

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.
@@ -10,7 +10,7 @@ onetype.AddonReady('html', (html) =>
10
10
  order: 90,
11
11
  attributes: {
12
12
  rel: 'stylesheet',
13
- href: onetype.StateGet('base', '') + '/assets/build.css?v=18'
13
+ href: onetype.Base() + '/assets/build.css?v=18'
14
14
  }
15
15
  });
16
16
  });
@@ -9,7 +9,7 @@ onetype.AddonReady('html', (html) =>
9
9
  position: 'head',
10
10
  order: 90,
11
11
  attributes: {
12
- src: onetype.StateGet('base', '') + '/assets/build.js?v=18',
12
+ src: onetype.Base() + '/assets/build.js?v=18',
13
13
  defer: null
14
14
  }
15
15
  });
@@ -23,9 +23,7 @@ const commands = onetype.Addon('commands', (addon) =>
23
23
  return null;
24
24
  }
25
25
 
26
- const base = onetype.StateGet('base', '');
27
-
28
- return base + '/' + value.replace(/^\/+/, '').replace(/\/+/g, '/').toLowerCase();
26
+ return onetype.Base() + '/' + value.replace(/^\/+/, '').replace(/\/+/g, '/').toLowerCase();
29
27
  });
30
28
  });
31
29
 
@@ -34,9 +34,14 @@ directives.Fn('process.match', function(d, node)
34
34
  }
35
35
  });
36
36
 
37
+ if(matches.total === 0 && d.trigger !== 'node')
38
+ {
39
+ return true;
40
+ }
41
+
37
42
  if(d.strict)
38
43
  {
39
- return matches.count === matches.total && matches.total > 0;
44
+ return matches.count === matches.total;
40
45
  }
41
46
 
42
47
  return matches.count > 0;
@@ -0,0 +1,45 @@
1
+ directives.ItemAdd({
2
+ id: 'ot-base',
3
+ trigger: 'after',
4
+ order: 2000,
5
+ code: function(data, item, compile, node)
6
+ {
7
+ const base = onetype.Base();
8
+
9
+ if(!base)
10
+ {
11
+ return;
12
+ }
13
+
14
+ const walk = (parent) =>
15
+ {
16
+ for(let i = 0; i < parent.childNodes.length; i++)
17
+ {
18
+ const child = parent.childNodes[i];
19
+
20
+ if(child.nodeType !== 1)
21
+ {
22
+ continue;
23
+ }
24
+
25
+ if(child.tagName === 'A')
26
+ {
27
+ const href = child.getAttribute('href');
28
+
29
+ if(href && href.startsWith('/') && !child.__base)
30
+ {
31
+ child.setAttribute('href', base + href);
32
+ child.__base = base;
33
+ }
34
+ }
35
+
36
+ if(child.childNodes.length)
37
+ {
38
+ walk(child);
39
+ }
40
+ }
41
+ };
42
+
43
+ walk(node);
44
+ }
45
+ });
@@ -6,7 +6,7 @@ onetype.AddonReady('directives', function()
6
6
  name: 'Node Mount',
7
7
  description: 'Mount a DOM node into the element.',
8
8
  trigger: 'node',
9
- order: 50,
9
+ order: 750,
10
10
  strict: false,
11
11
  attributes: {
12
12
  'ot-node': ['string', null, true]
@@ -21,6 +21,5 @@ import '#html/items/fonts/outfit.js';
21
21
 
22
22
  /* Essential Items - SEO */
23
23
  import '#html/items/seo/robots.js';
24
- import '#html/items/seo/theme-color.js';
25
24
 
26
25
  export default html;
@@ -3,7 +3,22 @@ import onetype from '#framework/load.js';
3
3
  const pages = onetype.Addon('pages', (addon) =>
4
4
  {
5
5
  addon.Field('id', ['string']);
6
- addon.Field('route', ['string|array']);
6
+ addon.Field('route', ['string|array'], null, (value) =>
7
+ {
8
+ const base = onetype.Base();
9
+
10
+ if(!base)
11
+ {
12
+ return value;
13
+ }
14
+
15
+ if(Array.isArray(value))
16
+ {
17
+ return value.map(route => base + route);
18
+ }
19
+
20
+ return base + value;
21
+ });
7
22
  addon.Field('title', ['string|function']);
8
23
  addon.Field('meta', ['object', {}]);
9
24
  addon.Field('data', ['function']);
@@ -24,4 +24,4 @@ document.addEventListener('click', (e) =>
24
24
  e.preventDefault();
25
25
 
26
26
  pages.Fn('change', match.page.Get('id'), null, match.parameters, true, url.search);
27
- });
27
+ });
package/lib/browser.js CHANGED
@@ -1,2 +1,17 @@
1
1
  window.onetype = new OneType();
2
- window.$ot = onetype.$ot;
2
+ window.$ot = onetype.$ot;
3
+
4
+ if(onetype.Base())
5
+ {
6
+ const original = window.fetch;
7
+
8
+ window.fetch = function(url, options)
9
+ {
10
+ if(typeof url === 'string' && url.startsWith('/'))
11
+ {
12
+ url = onetype.Base() + url;
13
+ }
14
+
15
+ return original.call(this, url, options);
16
+ };
17
+ }
@@ -0,0 +1,14 @@
1
+ const OneTypeBase =
2
+ {
3
+ Base(value)
4
+ {
5
+ if(typeof value === 'undefined')
6
+ {
7
+ return this.StateGet('base', '');
8
+ }
9
+
10
+ this.StateSet('base', value);
11
+ }
12
+ };
13
+
14
+ export default OneTypeBase;
@@ -162,15 +162,7 @@ const OneTypeRoute =
162
162
  return '/';
163
163
  }
164
164
 
165
- const base = this.StateGet('base', '');
166
- let path = window.location.pathname;
167
-
168
- if(base && path.startsWith(base))
169
- {
170
- path = path.slice(base.length) || '/';
171
- }
172
-
173
- return this.RouteNormalize(path);
165
+ return this.RouteNormalize(window.location.pathname);
174
166
  },
175
167
 
176
168
  RouteNavigate(pathname, state = {})
@@ -180,8 +172,7 @@ const OneTypeRoute =
180
172
  return;
181
173
  }
182
174
 
183
- const base = this.StateGet('base', '');
184
- const normalized = this.RouteNormalize(base + pathname);
175
+ const normalized = this.RouteNormalize(pathname);
185
176
 
186
177
  if (window.history && window.history.pushState)
187
178
  {
@@ -21,6 +21,7 @@ import OneTypeState from './mixins/state.js';
21
21
  import OneTypeAssets from './mixins/assets.js';
22
22
  import OneTypeObserver from './mixins/observer.js';
23
23
  import OneTypeMarkdown from './mixins/markdown.js';
24
+ import OneTypeBase from './mixins/base.js';
24
25
 
25
26
  class OneType
26
27
  {
@@ -57,7 +58,7 @@ class OneType
57
58
 
58
59
  this.$ot =
59
60
  {
60
- get: (key) => this.StateGet(key),
61
+ get: (key, value = undefined) => this.StateGet(key, undefined),
61
62
  set: (key, value) => this.StateSet(key, value)
62
63
  };
63
64
 
@@ -88,5 +89,6 @@ Object.assign(OneType.prototype, OneTypeState);
88
89
  Object.assign(OneType.prototype, OneTypeAssets);
89
90
  Object.assign(OneType.prototype, OneTypeObserver);
90
91
  Object.assign(OneType.prototype, OneTypeMarkdown);
92
+ Object.assign(OneType.prototype, OneTypeBase);
91
93
 
92
94
  export default OneType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onetype/framework",
3
- "version": "2.0.43",
3
+ "version": "2.0.44",
4
4
  "description": "OneType Framework — Full-stack isomorphic JavaScript framework built from scratch. One addon abstraction powers databases, servers, commands, pages, directives, queues, and more.",
5
5
  "type": "module",
6
6
  "main": "lib/load.js",
@@ -1,12 +0,0 @@
1
- import html from '#html/addon.js';
2
-
3
- html.Item({
4
- id: 'seo-theme-color',
5
- tag: 'meta',
6
- position: 'head',
7
- priority: -20,
8
- attributes: {
9
- name: 'theme-color',
10
- content: '#000000'
11
- }
12
- });