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