native-document 1.0.162 → 1.0.164

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.
@@ -26,62 +26,107 @@ Object.defineProperty(NDElement.prototype, 'nd', {
26
26
  // ----------------------------------------------------------------
27
27
  EVENTS.forEach(eventSourceName => {
28
28
  const eventName = eventSourceName.toLowerCase();
29
- NDElement.prototype['on'+eventSourceName] = function(callback = null) {
30
- this.$element.addEventListener(eventName, callback);
29
+ NDElement.prototype['on'+eventSourceName] = function(callback = null, options = {}) {
30
+ this.$element.addEventListener(eventName, callback, {
31
+ signal: this.$getSignal(),
32
+ ...options
33
+ });
31
34
  return this;
32
35
  };
33
36
  })
34
37
 
35
38
  EVENTS_WITH_STOP.forEach(eventSourceName => {
36
39
  const eventName = eventSourceName.toLowerCase();
37
- NDElement.prototype['onStop'+eventSourceName] = function(callback = null) {
38
- _stop(this.$element, eventName, callback);
40
+ NDElement.prototype['onStop'+eventSourceName] = function(callback = null, options = {}) {
41
+ _stop(this.$element, eventName, callback, {
42
+ signal: this.$getSignal(),
43
+ ...options
44
+ });
39
45
  return this;
40
46
  };
41
- NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null) {
42
- _preventStop(this.$element, eventName, callback);
47
+ NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null, options = {}) {
48
+ _preventStop(this.$element, eventName, callback, {
49
+ signal: this.$getSignal(),
50
+ ...options
51
+ });
43
52
  return this;
44
53
  };
45
54
  });
46
55
 
47
56
  EVENTS_WITH_PREVENT.forEach(eventSourceName => {
48
57
  const eventName = eventSourceName.toLowerCase();
49
- NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null) {
50
- _prevent(this.$element, eventName, callback);
58
+ NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null, options = {}) {
59
+ _prevent(this.$element, eventName, callback, {
60
+ signal: this.$getSignal(),
61
+ ...options
62
+ });
51
63
  return this;
52
64
  };
53
65
  });
54
66
 
67
+ NDElement.prototype.$getSignal = function() {
68
+ if(!this.$element.__$controller) {
69
+ this.$element.__$controller = new AbortController();
70
+ }
71
+ return this.$element.__$controller.signal;
72
+ };
73
+
55
74
  NDElement.prototype.on = function(name, callback, options) {
56
- this.$element.addEventListener(name.toLowerCase(), callback, options);
75
+ this.$element.addEventListener(name.toLowerCase(), callback, {
76
+ signal: this.$getSignal(),
77
+ ...options
78
+ });
79
+ return this;
80
+ };
81
+
82
+ NDElement.prototype.off = function(name, callback) {
83
+ this.$element.removeEventListener(name.toLowerCase(), callback);
84
+ return this;
85
+ };
86
+
87
+ NDElement.prototype.once = function(name, callback) {
88
+ this.$element.addEventListener(name.toLowerCase(), callback, {
89
+ signal: this.$getSignal(),
90
+ once: true
91
+ });
92
+ return this;
93
+ };
94
+
95
+ NDElement.prototype.emit = function(name, detail = null) {
96
+ const event = new CustomEvent(name, {
97
+ detail,
98
+ bubbles: true,
99
+ cancelable: true,
100
+ });
101
+ this.$element.dispatchEvent(event);
57
102
  return this;
58
103
  };
59
104
 
60
- const _prevent = function(element, eventName, callback) {
105
+ const _prevent = function(element, eventName, callback, options) {
61
106
  const handler = (event) => {
62
107
  event.preventDefault();
63
108
  callback && callback.call(element, event);
64
109
  };
65
- element.addEventListener(eventName, handler);
110
+ element.addEventListener(eventName, handler, options);
66
111
  return this;
67
112
  }
68
113
 
69
- const _stop = function(element, eventName, callback) {
114
+ const _stop = function(element, eventName, callback, options) {
70
115
  const handler = (event) => {
71
116
  event.stopPropagation();
72
117
  callback && callback.call(element, event);
73
118
  };
74
- element.addEventListener(eventName, handler);
119
+ element.addEventListener(eventName, handler, options);
75
120
  return this;
76
121
  };
77
122
 
78
- const _preventStop = function(element, eventName, callback) {
123
+ const _preventStop = function(element, eventName, callback, options) {
79
124
  const handler = (event) => {
80
125
  event.stopPropagation();
81
126
  event.preventDefault();
82
127
  callback && callback.call(element, event);
83
128
  };
84
- element.addEventListener(eventName, handler);
129
+ element.addEventListener(eventName, handler, options);
85
130
  return this;
86
131
  };
87
132
 
@@ -9,27 +9,30 @@ export function SingletonView($viewCreator) {
9
9
  if(!$cacheNode) {
10
10
  $cacheNode = $viewCreator(this);
11
11
  }
12
- if(!$components) {
13
- return $cacheNode;
14
- }
15
- for(const index in $components) {
16
- const updater = $components[index];
17
- updater(...data);
12
+ if(!$components) return $cacheNode;
13
+
14
+ const updates = data[0];
15
+ if(updates && typeof updates === 'object') {
16
+ for(const key in updates) {
17
+ if($components[key]) {
18
+ $components[key](updates[key]);
19
+ }
20
+ }
18
21
  }
19
22
  return $cacheNode;
20
23
  };
21
24
 
22
25
  this.createSection = (name, fn) => {
23
26
  $components = $components || {};
24
- const anchor = Anchor('Component '+name);
27
+ const anchor = Anchor('Component ' + name);
25
28
 
26
- $components[name] = function(...args) {
29
+ $components[name] = function(content) {
27
30
  anchor.removeChildren();
28
31
  if(!fn) {
29
- anchor.append(args);
32
+ anchor.append(content);
30
33
  return;
31
34
  }
32
- anchor.appendChild(fn(...args));
35
+ anchor.appendChild(fn(content));
33
36
  };
34
37
  return anchor;
35
38
  };
@@ -1,7 +1,25 @@
1
1
  import {trim} from "../core/utils/helpers.js";
2
2
 
3
3
  export const RouteParamPatterns = {
4
+ id: '[0-9]+',
5
+ uuid: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',
6
+ slug: '[a-z0-9]+(?:-[a-z0-9]+)*',
7
+ hash: '[a-f0-9]{32,64}',
4
8
 
9
+ alpha: '[a-zA-Z]+',
10
+ alphanum: '[a-zA-Z0-9]+',
11
+ string: '[^/]+',
12
+ any: '.*',
13
+
14
+ int: '[0-9]+',
15
+ float: '[0-9]+\\.[0-9]+',
16
+ number: '[0-9]+(\\.[0-9]+)?',
17
+ positive: '[1-9][0-9]*',
18
+
19
+ locale: '[a-z]{2}(-[A-Z]{2})?',
20
+ lang: '[a-z]{2}',
21
+
22
+ token: '[A-Za-z0-9_\\-]+',
5
23
  };
6
24
 
7
25
  /**