reactpy_django 5.0.0__py3-none-any.whl

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 (118) hide show
  1. js/node_modules/@pyscript/core/src/stdlib/pyscript/__init__.py +61 -0
  2. js/node_modules/@pyscript/core/src/stdlib/pyscript/display.py +177 -0
  3. js/node_modules/@pyscript/core/src/stdlib/pyscript/event_handling.py +76 -0
  4. js/node_modules/@pyscript/core/src/stdlib/pyscript/fetch.py +87 -0
  5. js/node_modules/@pyscript/core/src/stdlib/pyscript/ffi.py +18 -0
  6. js/node_modules/@pyscript/core/src/stdlib/pyscript/flatted.py +148 -0
  7. js/node_modules/@pyscript/core/src/stdlib/pyscript/magic_js.py +79 -0
  8. js/node_modules/@pyscript/core/src/stdlib/pyscript/storage.py +60 -0
  9. js/node_modules/@pyscript/core/src/stdlib/pyscript/util.py +33 -0
  10. js/node_modules/@pyscript/core/src/stdlib/pyscript/web.py +1176 -0
  11. js/node_modules/@pyscript/core/src/stdlib/pyscript/websocket.py +71 -0
  12. js/node_modules/@pyscript/core/src/stdlib/pyscript/workers.py +43 -0
  13. js/node_modules/flatted/python/flatted.py +149 -0
  14. js/node_modules/flatted/python/test.py +63 -0
  15. js/node_modules/polyscript/python/mip.py +288 -0
  16. reactpy_django/__init__.py +32 -0
  17. reactpy_django/apps.py +11 -0
  18. reactpy_django/checks.py +558 -0
  19. reactpy_django/clean.py +141 -0
  20. reactpy_django/components.py +284 -0
  21. reactpy_django/config.py +128 -0
  22. reactpy_django/database.py +31 -0
  23. reactpy_django/decorators.py +65 -0
  24. reactpy_django/exceptions.py +34 -0
  25. reactpy_django/hooks.py +469 -0
  26. reactpy_django/html.py +3 -0
  27. reactpy_django/http/__init__.py +0 -0
  28. reactpy_django/http/urls.py +18 -0
  29. reactpy_django/http/views.py +62 -0
  30. reactpy_django/management/__init__.py +0 -0
  31. reactpy_django/management/commands/__init__.py +0 -0
  32. reactpy_django/management/commands/clean_reactpy.py +37 -0
  33. reactpy_django/migrations/0001_initial.py +25 -0
  34. reactpy_django/migrations/0002_rename_created_at_componentparams_last_accessed.py +17 -0
  35. reactpy_django/migrations/0003_componentsession_delete_componentparams.py +28 -0
  36. reactpy_django/migrations/0004_config.py +27 -0
  37. reactpy_django/migrations/0005_alter_componentsession_last_accessed.py +17 -0
  38. reactpy_django/migrations/0006_userdatamodel.py +28 -0
  39. reactpy_django/migrations/__init__.py +0 -0
  40. reactpy_django/models.py +48 -0
  41. reactpy_django/py.typed +1 -0
  42. reactpy_django/pyscript/__init__.py +0 -0
  43. reactpy_django/pyscript/component_template.py +26 -0
  44. reactpy_django/pyscript/layout_handler.py +139 -0
  45. reactpy_django/router/__init__.py +5 -0
  46. reactpy_django/router/converters.py +8 -0
  47. reactpy_django/router/resolvers.py +22 -0
  48. reactpy_django/static/reactpy_django/client.js +1 -0
  49. reactpy_django/static/reactpy_django/morphdom/morphdom-esm.js +769 -0
  50. reactpy_django/static/reactpy_django/morphdom/morphdom-factory.js +705 -0
  51. reactpy_django/static/reactpy_django/morphdom/morphdom-umd.js +777 -0
  52. reactpy_django/static/reactpy_django/morphdom/morphdom-umd.min.js +1 -0
  53. reactpy_django/static/reactpy_django/morphdom/morphdom.js +771 -0
  54. reactpy_django/static/reactpy_django/pyscript/codemirror-BEtcgaoQ.js +2 -0
  55. reactpy_django/static/reactpy_django/pyscript/codemirror-BEtcgaoQ.js.map +1 -0
  56. reactpy_django/static/reactpy_django/pyscript/codemirror_commands-DDxffOmd.js +2 -0
  57. reactpy_django/static/reactpy_django/pyscript/codemirror_commands-DDxffOmd.js.map +1 -0
  58. reactpy_django/static/reactpy_django/pyscript/codemirror_lang-python-CnWnFqxD.js +2 -0
  59. reactpy_django/static/reactpy_django/pyscript/codemirror_lang-python-CnWnFqxD.js.map +1 -0
  60. reactpy_django/static/reactpy_django/pyscript/codemirror_language-CjmvX4ix.js +2 -0
  61. reactpy_django/static/reactpy_django/pyscript/codemirror_language-CjmvX4ix.js.map +1 -0
  62. reactpy_django/static/reactpy_django/pyscript/codemirror_state-D1qTXrff.js +2 -0
  63. reactpy_django/static/reactpy_django/pyscript/codemirror_state-D1qTXrff.js.map +1 -0
  64. reactpy_django/static/reactpy_django/pyscript/codemirror_view-DVb8uYMr.js +2 -0
  65. reactpy_django/static/reactpy_django/pyscript/codemirror_view-DVb8uYMr.js.map +1 -0
  66. reactpy_django/static/reactpy_django/pyscript/core-CjO3FOKB.js +2 -0
  67. reactpy_django/static/reactpy_django/pyscript/core-CjO3FOKB.js.map +1 -0
  68. reactpy_django/static/reactpy_django/pyscript/core.css +1 -0
  69. reactpy_django/static/reactpy_django/pyscript/core.js +2 -0
  70. reactpy_django/static/reactpy_django/pyscript/core.js.map +1 -0
  71. reactpy_django/static/reactpy_django/pyscript/deprecations-manager-pFtn19mE.js +2 -0
  72. reactpy_django/static/reactpy_django/pyscript/deprecations-manager-pFtn19mE.js.map +1 -0
  73. reactpy_django/static/reactpy_django/pyscript/error-tq-z48YI.js +2 -0
  74. reactpy_django/static/reactpy_django/pyscript/error-tq-z48YI.js.map +1 -0
  75. reactpy_django/static/reactpy_django/pyscript/index-S1Do43bx.js +2 -0
  76. reactpy_django/static/reactpy_django/pyscript/index-S1Do43bx.js.map +1 -0
  77. reactpy_django/static/reactpy_django/pyscript/mpy-DovD7Qjy.js +2 -0
  78. reactpy_django/static/reactpy_django/pyscript/mpy-DovD7Qjy.js.map +1 -0
  79. reactpy_django/static/reactpy_django/pyscript/py-BUsUWVJg.js +2 -0
  80. reactpy_django/static/reactpy_django/pyscript/py-BUsUWVJg.js.map +1 -0
  81. reactpy_django/static/reactpy_django/pyscript/py-editor-CeySmmer.js +2 -0
  82. reactpy_django/static/reactpy_django/pyscript/py-editor-CeySmmer.js.map +1 -0
  83. reactpy_django/static/reactpy_django/pyscript/py-terminal-CH_wV7wQ.js +2 -0
  84. reactpy_django/static/reactpy_django/pyscript/py-terminal-CH_wV7wQ.js.map +1 -0
  85. reactpy_django/static/reactpy_django/pyscript/storage.js +2 -0
  86. reactpy_django/static/reactpy_django/pyscript/storage.js.map +1 -0
  87. reactpy_django/static/reactpy_django/pyscript/toml-CvAfdf9_.js +3 -0
  88. reactpy_django/static/reactpy_django/pyscript/toml-CvAfdf9_.js.map +1 -0
  89. reactpy_django/static/reactpy_django/pyscript/toml-DiUM0_qs.js +3 -0
  90. reactpy_django/static/reactpy_django/pyscript/toml-DiUM0_qs.js.map +1 -0
  91. reactpy_django/static/reactpy_django/pyscript/xterm-BY7uk_OU.js +2 -0
  92. reactpy_django/static/reactpy_django/pyscript/xterm-BY7uk_OU.js.map +1 -0
  93. reactpy_django/static/reactpy_django/pyscript/xterm-readline-CZfBw7ic.js +2 -0
  94. reactpy_django/static/reactpy_django/pyscript/xterm-readline-CZfBw7ic.js.map +1 -0
  95. reactpy_django/static/reactpy_django/pyscript/xterm.css +7 -0
  96. reactpy_django/static/reactpy_django/pyscript/xterm_addon-fit--gyF3PcZ.js +2 -0
  97. reactpy_django/static/reactpy_django/pyscript/xterm_addon-fit--gyF3PcZ.js.map +1 -0
  98. reactpy_django/static/reactpy_django/pyscript/xterm_addon-web-links-Cnej-nJ6.js +2 -0
  99. reactpy_django/static/reactpy_django/pyscript/xterm_addon-web-links-Cnej-nJ6.js.map +1 -0
  100. reactpy_django/static/reactpy_django/pyscript/zip-DrwYHuF9.js +2 -0
  101. reactpy_django/static/reactpy_django/pyscript/zip-DrwYHuF9.js.map +1 -0
  102. reactpy_django/static/reactpy_django/pyscript-custom.css +3 -0
  103. reactpy_django/static/reactpy_django/pyscript-hide-debug.css +3 -0
  104. reactpy_django/templates/reactpy/component.html +27 -0
  105. reactpy_django/templates/reactpy/pyscript_component.html +2 -0
  106. reactpy_django/templates/reactpy/pyscript_setup.html +8 -0
  107. reactpy_django/templatetags/__init__.py +0 -0
  108. reactpy_django/templatetags/reactpy.py +250 -0
  109. reactpy_django/types.py +81 -0
  110. reactpy_django/utils.py +560 -0
  111. reactpy_django/websocket/__init__.py +0 -0
  112. reactpy_django/websocket/consumer.py +227 -0
  113. reactpy_django/websocket/paths.py +15 -0
  114. reactpy_django-5.0.0.dist-info/LICENSE.md +9 -0
  115. reactpy_django-5.0.0.dist-info/METADATA +152 -0
  116. reactpy_django-5.0.0.dist-info/RECORD +118 -0
  117. reactpy_django-5.0.0.dist-info/WHEEL +5 -0
  118. reactpy_django-5.0.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,771 @@
1
+ 'use strict';
2
+
3
+ var DOCUMENT_FRAGMENT_NODE = 11;
4
+
5
+ function morphAttrs(fromNode, toNode) {
6
+ var toNodeAttrs = toNode.attributes;
7
+ var attr;
8
+ var attrName;
9
+ var attrNamespaceURI;
10
+ var attrValue;
11
+ var fromValue;
12
+
13
+ // document-fragments dont have attributes so lets not do anything
14
+ if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE || fromNode.nodeType === DOCUMENT_FRAGMENT_NODE) {
15
+ return;
16
+ }
17
+
18
+ // update attributes on original DOM element
19
+ for (var i = toNodeAttrs.length - 1; i >= 0; i--) {
20
+ attr = toNodeAttrs[i];
21
+ attrName = attr.name;
22
+ attrNamespaceURI = attr.namespaceURI;
23
+ attrValue = attr.value;
24
+
25
+ if (attrNamespaceURI) {
26
+ attrName = attr.localName || attrName;
27
+ fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName);
28
+
29
+ if (fromValue !== attrValue) {
30
+ if (attr.prefix === 'xmlns'){
31
+ attrName = attr.name; // It's not allowed to set an attribute with the XMLNS namespace without specifying the `xmlns` prefix
32
+ }
33
+ fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue);
34
+ }
35
+ } else {
36
+ fromValue = fromNode.getAttribute(attrName);
37
+
38
+ if (fromValue !== attrValue) {
39
+ fromNode.setAttribute(attrName, attrValue);
40
+ }
41
+ }
42
+ }
43
+
44
+ // Remove any extra attributes found on the original DOM element that
45
+ // weren't found on the target element.
46
+ var fromNodeAttrs = fromNode.attributes;
47
+
48
+ for (var d = fromNodeAttrs.length - 1; d >= 0; d--) {
49
+ attr = fromNodeAttrs[d];
50
+ attrName = attr.name;
51
+ attrNamespaceURI = attr.namespaceURI;
52
+
53
+ if (attrNamespaceURI) {
54
+ attrName = attr.localName || attrName;
55
+
56
+ if (!toNode.hasAttributeNS(attrNamespaceURI, attrName)) {
57
+ fromNode.removeAttributeNS(attrNamespaceURI, attrName);
58
+ }
59
+ } else {
60
+ if (!toNode.hasAttribute(attrName)) {
61
+ fromNode.removeAttribute(attrName);
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ var range; // Create a range object for efficently rendering strings to elements.
68
+ var NS_XHTML = 'http://www.w3.org/1999/xhtml';
69
+
70
+ var doc = typeof document === 'undefined' ? undefined : document;
71
+ var HAS_TEMPLATE_SUPPORT = !!doc && 'content' in doc.createElement('template');
72
+ var HAS_RANGE_SUPPORT = !!doc && doc.createRange && 'createContextualFragment' in doc.createRange();
73
+
74
+ function createFragmentFromTemplate(str) {
75
+ var template = doc.createElement('template');
76
+ template.innerHTML = str;
77
+ return template.content.childNodes[0];
78
+ }
79
+
80
+ function createFragmentFromRange(str) {
81
+ if (!range) {
82
+ range = doc.createRange();
83
+ range.selectNode(doc.body);
84
+ }
85
+
86
+ var fragment = range.createContextualFragment(str);
87
+ return fragment.childNodes[0];
88
+ }
89
+
90
+ function createFragmentFromWrap(str) {
91
+ var fragment = doc.createElement('body');
92
+ fragment.innerHTML = str;
93
+ return fragment.childNodes[0];
94
+ }
95
+
96
+ /**
97
+ * This is about the same
98
+ * var html = new DOMParser().parseFromString(str, 'text/html');
99
+ * return html.body.firstChild;
100
+ *
101
+ * @method toElement
102
+ * @param {String} str
103
+ */
104
+ function toElement(str) {
105
+ str = str.trim();
106
+ if (HAS_TEMPLATE_SUPPORT) {
107
+ // avoid restrictions on content for things like `<tr><th>Hi</th></tr>` which
108
+ // createContextualFragment doesn't support
109
+ // <template> support not available in IE
110
+ return createFragmentFromTemplate(str);
111
+ } else if (HAS_RANGE_SUPPORT) {
112
+ return createFragmentFromRange(str);
113
+ }
114
+
115
+ return createFragmentFromWrap(str);
116
+ }
117
+
118
+ /**
119
+ * Returns true if two node's names are the same.
120
+ *
121
+ * NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
122
+ * nodeName and different namespace URIs.
123
+ *
124
+ * @param {Element} a
125
+ * @param {Element} b The target element
126
+ * @return {boolean}
127
+ */
128
+ function compareNodeNames(fromEl, toEl) {
129
+ var fromNodeName = fromEl.nodeName;
130
+ var toNodeName = toEl.nodeName;
131
+ var fromCodeStart, toCodeStart;
132
+
133
+ if (fromNodeName === toNodeName) {
134
+ return true;
135
+ }
136
+
137
+ fromCodeStart = fromNodeName.charCodeAt(0);
138
+ toCodeStart = toNodeName.charCodeAt(0);
139
+
140
+ // If the target element is a virtual DOM node or SVG node then we may
141
+ // need to normalize the tag name before comparing. Normal HTML elements that are
142
+ // in the "http://www.w3.org/1999/xhtml"
143
+ // are converted to upper case
144
+ if (fromCodeStart <= 90 && toCodeStart >= 97) { // from is upper and to is lower
145
+ return fromNodeName === toNodeName.toUpperCase();
146
+ } else if (toCodeStart <= 90 && fromCodeStart >= 97) { // to is upper and from is lower
147
+ return toNodeName === fromNodeName.toUpperCase();
148
+ } else {
149
+ return false;
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Create an element, optionally with a known namespace URI.
155
+ *
156
+ * @param {string} name the element name, e.g. 'div' or 'svg'
157
+ * @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
158
+ * its `xmlns` attribute or its inferred namespace.
159
+ *
160
+ * @return {Element}
161
+ */
162
+ function createElementNS(name, namespaceURI) {
163
+ return !namespaceURI || namespaceURI === NS_XHTML ?
164
+ doc.createElement(name) :
165
+ doc.createElementNS(namespaceURI, name);
166
+ }
167
+
168
+ /**
169
+ * Copies the children of one DOM element to another DOM element
170
+ */
171
+ function moveChildren(fromEl, toEl) {
172
+ var curChild = fromEl.firstChild;
173
+ while (curChild) {
174
+ var nextChild = curChild.nextSibling;
175
+ toEl.appendChild(curChild);
176
+ curChild = nextChild;
177
+ }
178
+ return toEl;
179
+ }
180
+
181
+ function syncBooleanAttrProp(fromEl, toEl, name) {
182
+ if (fromEl[name] !== toEl[name]) {
183
+ fromEl[name] = toEl[name];
184
+ if (fromEl[name]) {
185
+ fromEl.setAttribute(name, '');
186
+ } else {
187
+ fromEl.removeAttribute(name);
188
+ }
189
+ }
190
+ }
191
+
192
+ var specialElHandlers = {
193
+ OPTION: function(fromEl, toEl) {
194
+ var parentNode = fromEl.parentNode;
195
+ if (parentNode) {
196
+ var parentName = parentNode.nodeName.toUpperCase();
197
+ if (parentName === 'OPTGROUP') {
198
+ parentNode = parentNode.parentNode;
199
+ parentName = parentNode && parentNode.nodeName.toUpperCase();
200
+ }
201
+ if (parentName === 'SELECT' && !parentNode.hasAttribute('multiple')) {
202
+ if (fromEl.hasAttribute('selected') && !toEl.selected) {
203
+ // Workaround for MS Edge bug where the 'selected' attribute can only be
204
+ // removed if set to a non-empty value:
205
+ // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12087679/
206
+ fromEl.setAttribute('selected', 'selected');
207
+ fromEl.removeAttribute('selected');
208
+ }
209
+ // We have to reset select element's selectedIndex to -1, otherwise setting
210
+ // fromEl.selected using the syncBooleanAttrProp below has no effect.
211
+ // The correct selectedIndex will be set in the SELECT special handler below.
212
+ parentNode.selectedIndex = -1;
213
+ }
214
+ }
215
+ syncBooleanAttrProp(fromEl, toEl, 'selected');
216
+ },
217
+ /**
218
+ * The "value" attribute is special for the <input> element since it sets
219
+ * the initial value. Changing the "value" attribute without changing the
220
+ * "value" property will have no effect since it is only used to the set the
221
+ * initial value. Similar for the "checked" attribute, and "disabled".
222
+ */
223
+ INPUT: function(fromEl, toEl) {
224
+ syncBooleanAttrProp(fromEl, toEl, 'checked');
225
+ syncBooleanAttrProp(fromEl, toEl, 'disabled');
226
+
227
+ if (fromEl.value !== toEl.value) {
228
+ fromEl.value = toEl.value;
229
+ }
230
+
231
+ if (!toEl.hasAttribute('value')) {
232
+ fromEl.removeAttribute('value');
233
+ }
234
+ },
235
+
236
+ TEXTAREA: function(fromEl, toEl) {
237
+ var newValue = toEl.value;
238
+ if (fromEl.value !== newValue) {
239
+ fromEl.value = newValue;
240
+ }
241
+
242
+ var firstChild = fromEl.firstChild;
243
+ if (firstChild) {
244
+ // Needed for IE. Apparently IE sets the placeholder as the
245
+ // node value and vise versa. This ignores an empty update.
246
+ var oldValue = firstChild.nodeValue;
247
+
248
+ if (oldValue == newValue || (!newValue && oldValue == fromEl.placeholder)) {
249
+ return;
250
+ }
251
+
252
+ firstChild.nodeValue = newValue;
253
+ }
254
+ },
255
+ SELECT: function(fromEl, toEl) {
256
+ if (!toEl.hasAttribute('multiple')) {
257
+ var selectedIndex = -1;
258
+ var i = 0;
259
+ // We have to loop through children of fromEl, not toEl since nodes can be moved
260
+ // from toEl to fromEl directly when morphing.
261
+ // At the time this special handler is invoked, all children have already been morphed
262
+ // and appended to / removed from fromEl, so using fromEl here is safe and correct.
263
+ var curChild = fromEl.firstChild;
264
+ var optgroup;
265
+ var nodeName;
266
+ while(curChild) {
267
+ nodeName = curChild.nodeName && curChild.nodeName.toUpperCase();
268
+ if (nodeName === 'OPTGROUP') {
269
+ optgroup = curChild;
270
+ curChild = optgroup.firstChild;
271
+ } else {
272
+ if (nodeName === 'OPTION') {
273
+ if (curChild.hasAttribute('selected')) {
274
+ selectedIndex = i;
275
+ break;
276
+ }
277
+ i++;
278
+ }
279
+ curChild = curChild.nextSibling;
280
+ if (!curChild && optgroup) {
281
+ curChild = optgroup.nextSibling;
282
+ optgroup = null;
283
+ }
284
+ }
285
+ }
286
+
287
+ fromEl.selectedIndex = selectedIndex;
288
+ }
289
+ }
290
+ };
291
+
292
+ var ELEMENT_NODE = 1;
293
+ var DOCUMENT_FRAGMENT_NODE$1 = 11;
294
+ var TEXT_NODE = 3;
295
+ var COMMENT_NODE = 8;
296
+
297
+ function noop() {}
298
+
299
+ function defaultGetNodeKey(node) {
300
+ if (node) {
301
+ return (node.getAttribute && node.getAttribute('id')) || node.id;
302
+ }
303
+ }
304
+
305
+ function morphdomFactory(morphAttrs) {
306
+
307
+ return function morphdom(fromNode, toNode, options) {
308
+ if (!options) {
309
+ options = {};
310
+ }
311
+
312
+ if (typeof toNode === 'string') {
313
+ if (fromNode.nodeName === '#document' || fromNode.nodeName === 'HTML' || fromNode.nodeName === 'BODY') {
314
+ var toNodeHtml = toNode;
315
+ toNode = doc.createElement('html');
316
+ toNode.innerHTML = toNodeHtml;
317
+ } else {
318
+ toNode = toElement(toNode);
319
+ }
320
+ } else if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE$1) {
321
+ toNode = toNode.firstElementChild;
322
+ }
323
+
324
+ var getNodeKey = options.getNodeKey || defaultGetNodeKey;
325
+ var onBeforeNodeAdded = options.onBeforeNodeAdded || noop;
326
+ var onNodeAdded = options.onNodeAdded || noop;
327
+ var onBeforeElUpdated = options.onBeforeElUpdated || noop;
328
+ var onElUpdated = options.onElUpdated || noop;
329
+ var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;
330
+ var onNodeDiscarded = options.onNodeDiscarded || noop;
331
+ var onBeforeElChildrenUpdated = options.onBeforeElChildrenUpdated || noop;
332
+ var skipFromChildren = options.skipFromChildren || noop;
333
+ var addChild = options.addChild || function(parent, child){ return parent.appendChild(child); };
334
+ var childrenOnly = options.childrenOnly === true;
335
+
336
+ // This object is used as a lookup to quickly find all keyed elements in the original DOM tree.
337
+ var fromNodesLookup = Object.create(null);
338
+ var keyedRemovalList = [];
339
+
340
+ function addKeyedRemoval(key) {
341
+ keyedRemovalList.push(key);
342
+ }
343
+
344
+ function walkDiscardedChildNodes(node, skipKeyedNodes) {
345
+ if (node.nodeType === ELEMENT_NODE) {
346
+ var curChild = node.firstChild;
347
+ while (curChild) {
348
+
349
+ var key = undefined;
350
+
351
+ if (skipKeyedNodes && (key = getNodeKey(curChild))) {
352
+ // If we are skipping keyed nodes then we add the key
353
+ // to a list so that it can be handled at the very end.
354
+ addKeyedRemoval(key);
355
+ } else {
356
+ // Only report the node as discarded if it is not keyed. We do this because
357
+ // at the end we loop through all keyed elements that were unmatched
358
+ // and then discard them in one final pass.
359
+ onNodeDiscarded(curChild);
360
+ if (curChild.firstChild) {
361
+ walkDiscardedChildNodes(curChild, skipKeyedNodes);
362
+ }
363
+ }
364
+
365
+ curChild = curChild.nextSibling;
366
+ }
367
+ }
368
+ }
369
+
370
+ /**
371
+ * Removes a DOM node out of the original DOM
372
+ *
373
+ * @param {Node} node The node to remove
374
+ * @param {Node} parentNode The nodes parent
375
+ * @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
376
+ * @return {undefined}
377
+ */
378
+ function removeNode(node, parentNode, skipKeyedNodes) {
379
+ if (onBeforeNodeDiscarded(node) === false) {
380
+ return;
381
+ }
382
+
383
+ if (parentNode) {
384
+ parentNode.removeChild(node);
385
+ }
386
+
387
+ onNodeDiscarded(node);
388
+ walkDiscardedChildNodes(node, skipKeyedNodes);
389
+ }
390
+
391
+ // // TreeWalker implementation is no faster, but keeping this around in case this changes in the future
392
+ // function indexTree(root) {
393
+ // var treeWalker = document.createTreeWalker(
394
+ // root,
395
+ // NodeFilter.SHOW_ELEMENT);
396
+ //
397
+ // var el;
398
+ // while((el = treeWalker.nextNode())) {
399
+ // var key = getNodeKey(el);
400
+ // if (key) {
401
+ // fromNodesLookup[key] = el;
402
+ // }
403
+ // }
404
+ // }
405
+
406
+ // // NodeIterator implementation is no faster, but keeping this around in case this changes in the future
407
+ //
408
+ // function indexTree(node) {
409
+ // var nodeIterator = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT);
410
+ // var el;
411
+ // while((el = nodeIterator.nextNode())) {
412
+ // var key = getNodeKey(el);
413
+ // if (key) {
414
+ // fromNodesLookup[key] = el;
415
+ // }
416
+ // }
417
+ // }
418
+
419
+ function indexTree(node) {
420
+ if (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE$1) {
421
+ var curChild = node.firstChild;
422
+ while (curChild) {
423
+ var key = getNodeKey(curChild);
424
+ if (key) {
425
+ fromNodesLookup[key] = curChild;
426
+ }
427
+
428
+ // Walk recursively
429
+ indexTree(curChild);
430
+
431
+ curChild = curChild.nextSibling;
432
+ }
433
+ }
434
+ }
435
+
436
+ indexTree(fromNode);
437
+
438
+ function handleNodeAdded(el) {
439
+ onNodeAdded(el);
440
+
441
+ var curChild = el.firstChild;
442
+ while (curChild) {
443
+ var nextSibling = curChild.nextSibling;
444
+
445
+ var key = getNodeKey(curChild);
446
+ if (key) {
447
+ var unmatchedFromEl = fromNodesLookup[key];
448
+ // if we find a duplicate #id node in cache, replace `el` with cache value
449
+ // and morph it to the child node.
450
+ if (unmatchedFromEl && compareNodeNames(curChild, unmatchedFromEl)) {
451
+ curChild.parentNode.replaceChild(unmatchedFromEl, curChild);
452
+ morphEl(unmatchedFromEl, curChild);
453
+ } else {
454
+ handleNodeAdded(curChild);
455
+ }
456
+ } else {
457
+ // recursively call for curChild and it's children to see if we find something in
458
+ // fromNodesLookup
459
+ handleNodeAdded(curChild);
460
+ }
461
+
462
+ curChild = nextSibling;
463
+ }
464
+ }
465
+
466
+ function cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey) {
467
+ // We have processed all of the "to nodes". If curFromNodeChild is
468
+ // non-null then we still have some from nodes left over that need
469
+ // to be removed
470
+ while (curFromNodeChild) {
471
+ var fromNextSibling = curFromNodeChild.nextSibling;
472
+ if ((curFromNodeKey = getNodeKey(curFromNodeChild))) {
473
+ // Since the node is keyed it might be matched up later so we defer
474
+ // the actual removal to later
475
+ addKeyedRemoval(curFromNodeKey);
476
+ } else {
477
+ // NOTE: we skip nested keyed nodes from being removed since there is
478
+ // still a chance they will be matched up later
479
+ removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
480
+ }
481
+ curFromNodeChild = fromNextSibling;
482
+ }
483
+ }
484
+
485
+ function morphEl(fromEl, toEl, childrenOnly) {
486
+ var toElKey = getNodeKey(toEl);
487
+
488
+ if (toElKey) {
489
+ // If an element with an ID is being morphed then it will be in the final
490
+ // DOM so clear it out of the saved elements collection
491
+ delete fromNodesLookup[toElKey];
492
+ }
493
+
494
+ if (!childrenOnly) {
495
+ // optional
496
+ var beforeUpdateResult = onBeforeElUpdated(fromEl, toEl);
497
+ if (beforeUpdateResult === false) {
498
+ return;
499
+ } else if (beforeUpdateResult instanceof HTMLElement) {
500
+ fromEl = beforeUpdateResult;
501
+ // reindex the new fromEl in case it's not in the same
502
+ // tree as the original fromEl
503
+ // (Phoenix LiveView sometimes returns a cloned tree,
504
+ // but keyed lookups would still point to the original tree)
505
+ indexTree(fromEl);
506
+ }
507
+
508
+ // update attributes on original DOM element first
509
+ morphAttrs(fromEl, toEl);
510
+ // optional
511
+ onElUpdated(fromEl);
512
+
513
+ if (onBeforeElChildrenUpdated(fromEl, toEl) === false) {
514
+ return;
515
+ }
516
+ }
517
+
518
+ if (fromEl.nodeName !== 'TEXTAREA') {
519
+ morphChildren(fromEl, toEl);
520
+ } else {
521
+ specialElHandlers.TEXTAREA(fromEl, toEl);
522
+ }
523
+ }
524
+
525
+ function morphChildren(fromEl, toEl) {
526
+ var skipFrom = skipFromChildren(fromEl, toEl);
527
+ var curToNodeChild = toEl.firstChild;
528
+ var curFromNodeChild = fromEl.firstChild;
529
+ var curToNodeKey;
530
+ var curFromNodeKey;
531
+
532
+ var fromNextSibling;
533
+ var toNextSibling;
534
+ var matchingFromEl;
535
+
536
+ // walk the children
537
+ outer: while (curToNodeChild) {
538
+ toNextSibling = curToNodeChild.nextSibling;
539
+ curToNodeKey = getNodeKey(curToNodeChild);
540
+
541
+ // walk the fromNode children all the way through
542
+ while (!skipFrom && curFromNodeChild) {
543
+ fromNextSibling = curFromNodeChild.nextSibling;
544
+
545
+ if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) {
546
+ curToNodeChild = toNextSibling;
547
+ curFromNodeChild = fromNextSibling;
548
+ continue outer;
549
+ }
550
+
551
+ curFromNodeKey = getNodeKey(curFromNodeChild);
552
+
553
+ var curFromNodeType = curFromNodeChild.nodeType;
554
+
555
+ // this means if the curFromNodeChild doesnt have a match with the curToNodeChild
556
+ var isCompatible = undefined;
557
+
558
+ if (curFromNodeType === curToNodeChild.nodeType) {
559
+ if (curFromNodeType === ELEMENT_NODE) {
560
+ // Both nodes being compared are Element nodes
561
+
562
+ if (curToNodeKey) {
563
+ // The target node has a key so we want to match it up with the correct element
564
+ // in the original DOM tree
565
+ if (curToNodeKey !== curFromNodeKey) {
566
+ // The current element in the original DOM tree does not have a matching key so
567
+ // let's check our lookup to see if there is a matching element in the original
568
+ // DOM tree
569
+ if ((matchingFromEl = fromNodesLookup[curToNodeKey])) {
570
+ if (fromNextSibling === matchingFromEl) {
571
+ // Special case for single element removals. To avoid removing the original
572
+ // DOM node out of the tree (since that can break CSS transitions, etc.),
573
+ // we will instead discard the current node and wait until the next
574
+ // iteration to properly match up the keyed target element with its matching
575
+ // element in the original tree
576
+ isCompatible = false;
577
+ } else {
578
+ // We found a matching keyed element somewhere in the original DOM tree.
579
+ // Let's move the original DOM node into the current position and morph
580
+ // it.
581
+
582
+ // NOTE: We use insertBefore instead of replaceChild because we want to go through
583
+ // the `removeNode()` function for the node that is being discarded so that
584
+ // all lifecycle hooks are correctly invoked
585
+ fromEl.insertBefore(matchingFromEl, curFromNodeChild);
586
+
587
+ // fromNextSibling = curFromNodeChild.nextSibling;
588
+
589
+ if (curFromNodeKey) {
590
+ // Since the node is keyed it might be matched up later so we defer
591
+ // the actual removal to later
592
+ addKeyedRemoval(curFromNodeKey);
593
+ } else {
594
+ // NOTE: we skip nested keyed nodes from being removed since there is
595
+ // still a chance they will be matched up later
596
+ removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
597
+ }
598
+
599
+ curFromNodeChild = matchingFromEl;
600
+ curFromNodeKey = getNodeKey(curFromNodeChild);
601
+ }
602
+ } else {
603
+ // The nodes are not compatible since the "to" node has a key and there
604
+ // is no matching keyed node in the source tree
605
+ isCompatible = false;
606
+ }
607
+ }
608
+ } else if (curFromNodeKey) {
609
+ // The original has a key
610
+ isCompatible = false;
611
+ }
612
+
613
+ isCompatible = isCompatible !== false && compareNodeNames(curFromNodeChild, curToNodeChild);
614
+ if (isCompatible) {
615
+ // We found compatible DOM elements so transform
616
+ // the current "from" node to match the current
617
+ // target DOM node.
618
+ // MORPH
619
+ morphEl(curFromNodeChild, curToNodeChild);
620
+ }
621
+
622
+ } else if (curFromNodeType === TEXT_NODE || curFromNodeType == COMMENT_NODE) {
623
+ // Both nodes being compared are Text or Comment nodes
624
+ isCompatible = true;
625
+ // Simply update nodeValue on the original node to
626
+ // change the text value
627
+ if (curFromNodeChild.nodeValue !== curToNodeChild.nodeValue) {
628
+ curFromNodeChild.nodeValue = curToNodeChild.nodeValue;
629
+ }
630
+
631
+ }
632
+ }
633
+
634
+ if (isCompatible) {
635
+ // Advance both the "to" child and the "from" child since we found a match
636
+ // Nothing else to do as we already recursively called morphChildren above
637
+ curToNodeChild = toNextSibling;
638
+ curFromNodeChild = fromNextSibling;
639
+ continue outer;
640
+ }
641
+
642
+ // No compatible match so remove the old node from the DOM and continue trying to find a
643
+ // match in the original DOM. However, we only do this if the from node is not keyed
644
+ // since it is possible that a keyed node might match up with a node somewhere else in the
645
+ // target tree and we don't want to discard it just yet since it still might find a
646
+ // home in the final DOM tree. After everything is done we will remove any keyed nodes
647
+ // that didn't find a home
648
+ if (curFromNodeKey) {
649
+ // Since the node is keyed it might be matched up later so we defer
650
+ // the actual removal to later
651
+ addKeyedRemoval(curFromNodeKey);
652
+ } else {
653
+ // NOTE: we skip nested keyed nodes from being removed since there is
654
+ // still a chance they will be matched up later
655
+ removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
656
+ }
657
+
658
+ curFromNodeChild = fromNextSibling;
659
+ } // END: while(curFromNodeChild) {}
660
+
661
+ // If we got this far then we did not find a candidate match for
662
+ // our "to node" and we exhausted all of the children "from"
663
+ // nodes. Therefore, we will just append the current "to" node
664
+ // to the end
665
+ if (curToNodeKey && (matchingFromEl = fromNodesLookup[curToNodeKey]) && compareNodeNames(matchingFromEl, curToNodeChild)) {
666
+ // MORPH
667
+ if(!skipFrom){ addChild(fromEl, matchingFromEl); }
668
+ morphEl(matchingFromEl, curToNodeChild);
669
+ } else {
670
+ var onBeforeNodeAddedResult = onBeforeNodeAdded(curToNodeChild);
671
+ if (onBeforeNodeAddedResult !== false) {
672
+ if (onBeforeNodeAddedResult) {
673
+ curToNodeChild = onBeforeNodeAddedResult;
674
+ }
675
+
676
+ if (curToNodeChild.actualize) {
677
+ curToNodeChild = curToNodeChild.actualize(fromEl.ownerDocument || doc);
678
+ }
679
+ addChild(fromEl, curToNodeChild);
680
+ handleNodeAdded(curToNodeChild);
681
+ }
682
+ }
683
+
684
+ curToNodeChild = toNextSibling;
685
+ curFromNodeChild = fromNextSibling;
686
+ }
687
+
688
+ cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey);
689
+
690
+ var specialElHandler = specialElHandlers[fromEl.nodeName];
691
+ if (specialElHandler) {
692
+ specialElHandler(fromEl, toEl);
693
+ }
694
+ } // END: morphChildren(...)
695
+
696
+ var morphedNode = fromNode;
697
+ var morphedNodeType = morphedNode.nodeType;
698
+ var toNodeType = toNode.nodeType;
699
+
700
+ if (!childrenOnly) {
701
+ // Handle the case where we are given two DOM nodes that are not
702
+ // compatible (e.g. <div> --> <span> or <div> --> TEXT)
703
+ if (morphedNodeType === ELEMENT_NODE) {
704
+ if (toNodeType === ELEMENT_NODE) {
705
+ if (!compareNodeNames(fromNode, toNode)) {
706
+ onNodeDiscarded(fromNode);
707
+ morphedNode = moveChildren(fromNode, createElementNS(toNode.nodeName, toNode.namespaceURI));
708
+ }
709
+ } else {
710
+ // Going from an element node to a text node
711
+ morphedNode = toNode;
712
+ }
713
+ } else if (morphedNodeType === TEXT_NODE || morphedNodeType === COMMENT_NODE) { // Text or comment node
714
+ if (toNodeType === morphedNodeType) {
715
+ if (morphedNode.nodeValue !== toNode.nodeValue) {
716
+ morphedNode.nodeValue = toNode.nodeValue;
717
+ }
718
+
719
+ return morphedNode;
720
+ } else {
721
+ // Text node to something else
722
+ morphedNode = toNode;
723
+ }
724
+ }
725
+ }
726
+
727
+ if (morphedNode === toNode) {
728
+ // The "to node" was not compatible with the "from node" so we had to
729
+ // toss out the "from node" and use the "to node"
730
+ onNodeDiscarded(fromNode);
731
+ } else {
732
+ if (toNode.isSameNode && toNode.isSameNode(morphedNode)) {
733
+ return;
734
+ }
735
+
736
+ morphEl(morphedNode, toNode, childrenOnly);
737
+
738
+ // We now need to loop over any keyed nodes that might need to be
739
+ // removed. We only do the removal if we know that the keyed node
740
+ // never found a match. When a keyed node is matched up we remove
741
+ // it out of fromNodesLookup and we use fromNodesLookup to determine
742
+ // if a keyed node has been matched up or not
743
+ if (keyedRemovalList) {
744
+ for (var i=0, len=keyedRemovalList.length; i<len; i++) {
745
+ var elToRemove = fromNodesLookup[keyedRemovalList[i]];
746
+ if (elToRemove) {
747
+ removeNode(elToRemove, elToRemove.parentNode, false);
748
+ }
749
+ }
750
+ }
751
+ }
752
+
753
+ if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {
754
+ if (morphedNode.actualize) {
755
+ morphedNode = morphedNode.actualize(fromNode.ownerDocument || doc);
756
+ }
757
+ // If we had to swap out the from node with a new node because the old
758
+ // node was not compatible with the target node then we need to
759
+ // replace the old DOM node in the original DOM tree. This is only
760
+ // possible if the original DOM node was part of a DOM tree which
761
+ // we know is the case if it has a parent node.
762
+ fromNode.parentNode.replaceChild(morphedNode, fromNode);
763
+ }
764
+
765
+ return morphedNode;
766
+ };
767
+ }
768
+
769
+ var morphdom = morphdomFactory(morphAttrs);
770
+
771
+ module.exports = morphdom;