treeloom 0.0.0-stage → 2.1.0

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 (289) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +91 -2
  3. package/browser/treeloom.js +11232 -0
  4. package/browser/treeloom.min.js +1 -0
  5. package/browser/treeloomRenderOnly.js +11115 -0
  6. package/browser/treeloomRenderOnly.min.js +1 -0
  7. package/dist/deflate/domItemToJson.d.ts +14 -0
  8. package/dist/deflate/domItemToJson.js +43 -0
  9. package/dist/deflate/domItemToJson.min.js +1 -0
  10. package/dist/deflate/index.d.ts +7 -0
  11. package/dist/deflate/index.js +19 -0
  12. package/dist/deflate/index.min.js +1 -0
  13. package/dist/deflate/removeEmptyProperties.d.ts +8 -0
  14. package/dist/deflate/removeEmptyProperties.js +43 -0
  15. package/dist/deflate/removeEmptyProperties.min.js +1 -0
  16. package/dist/diff/appliedSnapshot.d.ts +34 -0
  17. package/dist/diff/appliedSnapshot.js +134 -0
  18. package/dist/diff/appliedSnapshot.min.js +1 -0
  19. package/dist/diff/createChangeList.d.ts +9 -0
  20. package/dist/diff/createChangeList.js +44 -0
  21. package/dist/diff/createChangeList.min.js +1 -0
  22. package/dist/diff/domItemChanges.d.ts +9 -0
  23. package/dist/diff/domItemChanges.js +167 -0
  24. package/dist/diff/domItemChanges.min.js +1 -0
  25. package/dist/diff/domItemHasAttribute.d.ts +11 -0
  26. package/dist/diff/domItemHasAttribute.js +63 -0
  27. package/dist/diff/domItemHasAttribute.min.js +1 -0
  28. package/dist/diff/elementChanges.d.ts +10 -0
  29. package/dist/diff/elementChanges.js +151 -0
  30. package/dist/diff/elementChanges.min.js +1 -0
  31. package/dist/diff/elementHasAttribute.d.ts +10 -0
  32. package/dist/diff/elementHasAttribute.js +70 -0
  33. package/dist/diff/elementHasAttribute.min.js +1 -0
  34. package/dist/diff/getAssignedStyles.d.ts +9 -0
  35. package/dist/diff/getAssignedStyles.js +22 -0
  36. package/dist/diff/getAssignedStyles.min.js +1 -0
  37. package/dist/diff/index.d.ts +9 -0
  38. package/dist/diff/index.js +27 -0
  39. package/dist/diff/index.min.js +1 -0
  40. package/dist/diff/types.d.ts +17 -0
  41. package/dist/diff/types.js +8 -0
  42. package/dist/diff/types.min.js +1 -0
  43. package/dist/domItem/index.d.ts +34 -0
  44. package/dist/domItem/index.js +81 -0
  45. package/dist/domItem/index.min.js +1 -0
  46. package/dist/domItem/objects/addDomItemProperties.d.ts +7 -0
  47. package/dist/domItem/objects/addDomItemProperties.js +27 -0
  48. package/dist/domItem/objects/addDomItemProperties.min.js +1 -0
  49. package/dist/domItem/objects/createCoreItem.d.ts +9 -0
  50. package/dist/domItem/objects/createCoreItem.js +53 -0
  51. package/dist/domItem/objects/createCoreItem.min.js +1 -0
  52. package/dist/domItem/objects/createDomItem.d.ts +10 -0
  53. package/dist/domItem/objects/createDomItem.js +40 -0
  54. package/dist/domItem/objects/createDomItem.min.js +1 -0
  55. package/dist/domItem/objects/documentDomItem.d.ts +12 -0
  56. package/dist/domItem/objects/documentDomItem.js +36 -0
  57. package/dist/domItem/objects/documentDomItem.min.js +1 -0
  58. package/dist/domItem/objects/documentItem.d.ts +18 -0
  59. package/dist/domItem/objects/documentItem.js +40 -0
  60. package/dist/domItem/objects/documentItem.min.js +1 -0
  61. package/dist/domItem/objects/initChildren.d.ts +6 -0
  62. package/dist/domItem/objects/initChildren.js +44 -0
  63. package/dist/domItem/objects/initChildren.min.js +1 -0
  64. package/dist/domItem/objects/initRoot.d.ts +9 -0
  65. package/dist/domItem/objects/initRoot.js +32 -0
  66. package/dist/domItem/objects/initRoot.min.js +1 -0
  67. package/dist/domItem/query/gatherChildItems.d.ts +12 -0
  68. package/dist/domItem/query/gatherChildItems.js +19 -0
  69. package/dist/domItem/query/gatherChildItems.min.js +1 -0
  70. package/dist/domItem/query/getChildTest.d.ts +8 -0
  71. package/dist/domItem/query/getChildTest.js +15 -0
  72. package/dist/domItem/query/getChildTest.min.js +1 -0
  73. package/dist/domItem/query/getChildrenByClass.d.ts +11 -0
  74. package/dist/domItem/query/getChildrenByClass.js +26 -0
  75. package/dist/domItem/query/getChildrenByClass.min.js +1 -0
  76. package/dist/domItem/query/getChildrenByName.d.ts +9 -0
  77. package/dist/domItem/query/getChildrenByName.js +23 -0
  78. package/dist/domItem/query/getChildrenByName.min.js +1 -0
  79. package/dist/domItem/query/getChildrenFromAttribute.d.ts +13 -0
  80. package/dist/domItem/query/getChildrenFromAttribute.js +28 -0
  81. package/dist/domItem/query/getChildrenFromAttribute.min.js +1 -0
  82. package/dist/domItem/query/getItemByElement.d.ts +11 -0
  83. package/dist/domItem/query/getItemByElement.js +29 -0
  84. package/dist/domItem/query/getItemByElement.min.js +1 -0
  85. package/dist/domItem/query/getParentsByClass.d.ts +12 -0
  86. package/dist/domItem/query/getParentsByClass.js +40 -0
  87. package/dist/domItem/query/getParentsByClass.min.js +1 -0
  88. package/dist/domItem/query/getParentsByName.d.ts +9 -0
  89. package/dist/domItem/query/getParentsByName.js +23 -0
  90. package/dist/domItem/query/getParentsByName.min.js +1 -0
  91. package/dist/domItem/query/getParentsByTagName.d.ts +9 -0
  92. package/dist/domItem/query/getParentsByTagName.js +23 -0
  93. package/dist/domItem/query/getParentsByTagName.min.js +1 -0
  94. package/dist/domItem/query/getParentsFromAttribute.d.ts +13 -0
  95. package/dist/domItem/query/getParentsFromAttribute.js +39 -0
  96. package/dist/domItem/query/getParentsFromAttribute.min.js +1 -0
  97. package/dist/domItem/traits/defineTrait.d.ts +10 -0
  98. package/dist/domItem/traits/defineTrait.js +26 -0
  99. package/dist/domItem/traits/defineTrait.min.js +1 -0
  100. package/dist/domItem/traits/definitions.d.ts +7 -0
  101. package/dist/domItem/traits/definitions.js +20 -0
  102. package/dist/domItem/traits/definitions.min.js +1 -0
  103. package/dist/domItem/traits/getNonSerializableKeys.d.ts +9 -0
  104. package/dist/domItem/traits/getNonSerializableKeys.js +25 -0
  105. package/dist/domItem/traits/getNonSerializableKeys.min.js +1 -0
  106. package/dist/domItem/traits/getTraitDefinition.d.ts +7 -0
  107. package/dist/domItem/traits/getTraitDefinition.js +20 -0
  108. package/dist/domItem/traits/getTraitDefinition.min.js +1 -0
  109. package/dist/domItem/traits/hasTrait.d.ts +8 -0
  110. package/dist/domItem/traits/hasTrait.js +15 -0
  111. package/dist/domItem/traits/hasTrait.min.js +1 -0
  112. package/dist/domItem/traits/hasTraits.d.ts +9 -0
  113. package/dist/domItem/traits/hasTraits.js +16 -0
  114. package/dist/domItem/traits/hasTraits.min.js +1 -0
  115. package/dist/domItem/traits/isDomItem.d.ts +8 -0
  116. package/dist/domItem/traits/isDomItem.js +21 -0
  117. package/dist/domItem/traits/isDomItem.min.js +1 -0
  118. package/dist/domItem/traits/withTrait.d.ts +11 -0
  119. package/dist/domItem/traits/withTrait.js +30 -0
  120. package/dist/domItem/traits/withTrait.min.js +1 -0
  121. package/dist/domItem/tree/appendChild.d.ts +8 -0
  122. package/dist/domItem/tree/appendChild.js +19 -0
  123. package/dist/domItem/tree/appendChild.min.js +1 -0
  124. package/dist/domItem/tree/getItemByPath.d.ts +10 -0
  125. package/dist/domItem/tree/getItemByPath.js +23 -0
  126. package/dist/domItem/tree/getItemByPath.min.js +1 -0
  127. package/dist/domItem/tree/getItemPath.d.ts +9 -0
  128. package/dist/domItem/tree/getItemPath.js +31 -0
  129. package/dist/domItem/tree/getItemPath.min.js +1 -0
  130. package/dist/domItem/tree/getTopParentItem.d.ts +8 -0
  131. package/dist/domItem/tree/getTopParentItem.js +29 -0
  132. package/dist/domItem/tree/getTopParentItem.min.js +1 -0
  133. package/dist/domItem/tree/insertChild.d.ts +11 -0
  134. package/dist/domItem/tree/insertChild.js +22 -0
  135. package/dist/domItem/tree/insertChild.min.js +1 -0
  136. package/dist/domItem/tree/itemIdIndex.d.ts +43 -0
  137. package/dist/domItem/tree/itemIdIndex.js +118 -0
  138. package/dist/domItem/tree/itemIdIndex.min.js +1 -0
  139. package/dist/domItem/tree/removeChild.d.ts +8 -0
  140. package/dist/domItem/tree/removeChild.js +21 -0
  141. package/dist/domItem/tree/removeChild.min.js +1 -0
  142. package/dist/domItem/tree/setParentItemReferences.d.ts +7 -0
  143. package/dist/domItem/tree/setParentItemReferences.js +24 -0
  144. package/dist/domItem/tree/setParentItemReferences.min.js +1 -0
  145. package/dist/domItem/types.d.ts +131 -0
  146. package/dist/domItem/types.js +8 -0
  147. package/dist/domItem/types.min.js +1 -0
  148. package/dist/events/functions/activateListener.d.ts +10 -0
  149. package/dist/events/functions/activateListener.js +45 -0
  150. package/dist/events/functions/activateListener.min.js +1 -0
  151. package/dist/events/functions/addEventListener.d.ts +23 -0
  152. package/dist/events/functions/addEventListener.js +54 -0
  153. package/dist/events/functions/addEventListener.min.js +1 -0
  154. package/dist/events/functions/applyActiveListeners.d.ts +9 -0
  155. package/dist/events/functions/applyActiveListeners.js +52 -0
  156. package/dist/events/functions/applyActiveListeners.min.js +1 -0
  157. package/dist/events/functions/assignListener.d.ts +12 -0
  158. package/dist/events/functions/assignListener.js +39 -0
  159. package/dist/events/functions/assignListener.min.js +1 -0
  160. package/dist/events/functions/bindAllListeners.d.ts +10 -0
  161. package/dist/events/functions/bindAllListeners.js +28 -0
  162. package/dist/events/functions/bindAllListeners.min.js +1 -0
  163. package/dist/events/functions/bindElementListeners.d.ts +7 -0
  164. package/dist/events/functions/bindElementListeners.js +34 -0
  165. package/dist/events/functions/bindElementListeners.min.js +1 -0
  166. package/dist/events/functions/bindListeners.d.ts +9 -0
  167. package/dist/events/functions/bindListeners.js +23 -0
  168. package/dist/events/functions/bindListeners.min.js +1 -0
  169. package/dist/events/functions/deactivateListener.d.ts +13 -0
  170. package/dist/events/functions/deactivateListener.js +58 -0
  171. package/dist/events/functions/deactivateListener.min.js +1 -0
  172. package/dist/events/functions/deactivateListeners.d.ts +7 -0
  173. package/dist/events/functions/deactivateListeners.js +22 -0
  174. package/dist/events/functions/deactivateListeners.min.js +1 -0
  175. package/dist/events/functions/findEventListener.d.ts +22 -0
  176. package/dist/events/functions/findEventListener.js +61 -0
  177. package/dist/events/functions/findEventListener.min.js +1 -0
  178. package/dist/events/functions/fullAddEventListener.d.ts +20 -0
  179. package/dist/events/functions/fullAddEventListener.js +45 -0
  180. package/dist/events/functions/fullAddEventListener.min.js +1 -0
  181. package/dist/events/functions/fullRemoveEventListener.d.ts +22 -0
  182. package/dist/events/functions/fullRemoveEventListener.js +37 -0
  183. package/dist/events/functions/fullRemoveEventListener.min.js +1 -0
  184. package/dist/events/functions/listenerOptions.d.ts +12 -0
  185. package/dist/events/functions/listenerOptions.js +31 -0
  186. package/dist/events/functions/listenerOptions.min.js +1 -0
  187. package/dist/events/functions/makeEventHandler.d.ts +10 -0
  188. package/dist/events/functions/makeEventHandler.js +23 -0
  189. package/dist/events/functions/makeEventHandler.min.js +1 -0
  190. package/dist/events/functions/makeForwardingListener.d.ts +11 -0
  191. package/dist/events/functions/makeForwardingListener.js +46 -0
  192. package/dist/events/functions/makeForwardingListener.min.js +1 -0
  193. package/dist/events/functions/receiveForwardedEvent.d.ts +23 -0
  194. package/dist/events/functions/receiveForwardedEvent.js +40 -0
  195. package/dist/events/functions/receiveForwardedEvent.min.js +1 -0
  196. package/dist/events/functions/registerListener.d.ts +11 -0
  197. package/dist/events/functions/registerListener.js +25 -0
  198. package/dist/events/functions/registerListener.min.js +1 -0
  199. package/dist/events/functions/registerListeners.d.ts +10 -0
  200. package/dist/events/functions/registerListeners.js +26 -0
  201. package/dist/events/functions/registerListeners.min.js +1 -0
  202. package/dist/events/functions/removeEventListener.d.ts +18 -0
  203. package/dist/events/functions/removeEventListener.js +42 -0
  204. package/dist/events/functions/removeEventListener.min.js +1 -0
  205. package/dist/events/functions/retrieveListener.d.ts +14 -0
  206. package/dist/events/functions/retrieveListener.js +39 -0
  207. package/dist/events/functions/retrieveListener.min.js +1 -0
  208. package/dist/events/functions/revokeActiveListeners.d.ts +12 -0
  209. package/dist/events/functions/revokeActiveListeners.js +54 -0
  210. package/dist/events/functions/revokeActiveListeners.min.js +1 -0
  211. package/dist/events/functions/setForwardEvents.d.ts +11 -0
  212. package/dist/events/functions/setForwardEvents.js +26 -0
  213. package/dist/events/functions/setForwardEvents.min.js +1 -0
  214. package/dist/events/functions/unassignListener.d.ts +12 -0
  215. package/dist/events/functions/unassignListener.js +32 -0
  216. package/dist/events/functions/unassignListener.min.js +1 -0
  217. package/dist/events/index.d.ts +37 -0
  218. package/dist/events/index.js +72 -0
  219. package/dist/events/index.min.js +1 -0
  220. package/dist/events/objects/createEventListener.d.ts +13 -0
  221. package/dist/events/objects/createEventListener.js +30 -0
  222. package/dist/events/objects/createEventListener.min.js +1 -0
  223. package/dist/events/objects/createEventProxy.d.ts +10 -0
  224. package/dist/events/objects/createEventProxy.js +48 -0
  225. package/dist/events/objects/createEventProxy.min.js +1 -0
  226. package/dist/events/objects/createEventResponder.d.ts +8 -0
  227. package/dist/events/objects/createEventResponder.js +27 -0
  228. package/dist/events/objects/createEventResponder.min.js +1 -0
  229. package/dist/events/objects/options/getListenerOptions.d.ts +6 -0
  230. package/dist/events/objects/options/getListenerOptions.js +22 -0
  231. package/dist/events/objects/options/getListenerOptions.min.js +1 -0
  232. package/dist/events/objects/options/numberToOptions.d.ts +8 -0
  233. package/dist/events/objects/options/numberToOptions.js +21 -0
  234. package/dist/events/objects/options/numberToOptions.min.js +1 -0
  235. package/dist/events/objects/options/optionsToNumber.d.ts +9 -0
  236. package/dist/events/objects/options/optionsToNumber.js +27 -0
  237. package/dist/events/objects/options/optionsToNumber.min.js +1 -0
  238. package/dist/events/objects/options.d.ts +6 -0
  239. package/dist/events/objects/options.js +24 -0
  240. package/dist/events/objects/options.min.js +1 -0
  241. package/dist/events/types.d.ts +87 -0
  242. package/dist/events/types.js +8 -0
  243. package/dist/events/types.min.js +1 -0
  244. package/dist/inflate/index.d.ts +4 -0
  245. package/dist/inflate/index.js +17 -0
  246. package/dist/inflate/index.min.js +1 -0
  247. package/dist/inflate/jsonToDomItem.d.ts +7 -0
  248. package/dist/inflate/jsonToDomItem.js +30 -0
  249. package/dist/inflate/jsonToDomItem.min.js +1 -0
  250. package/dist/main.d.ts +2 -0
  251. package/dist/main.js +24 -0
  252. package/dist/main.min.js +1 -0
  253. package/dist/render/generateElement.d.ts +7 -0
  254. package/dist/render/generateElement.js +41 -0
  255. package/dist/render/generateElement.min.js +1 -0
  256. package/dist/render/index.d.ts +9 -0
  257. package/dist/render/index.js +27 -0
  258. package/dist/render/index.min.js +1 -0
  259. package/dist/render/reconcile.d.ts +16 -0
  260. package/dist/render/reconcile.js +169 -0
  261. package/dist/render/reconcile.min.js +1 -0
  262. package/dist/render/renderHtml.d.ts +16 -0
  263. package/dist/render/renderHtml.js +57 -0
  264. package/dist/render/renderHtml.min.js +1 -0
  265. package/dist/render/updateChildNodes.d.ts +7 -0
  266. package/dist/render/updateChildNodes.js +53 -0
  267. package/dist/render/updateChildNodes.min.js +1 -0
  268. package/dist/render/updateElement.d.ts +14 -0
  269. package/dist/render/updateElement.js +113 -0
  270. package/dist/render/updateElement.min.js +1 -0
  271. package/dist/render/updateElements.d.ts +9 -0
  272. package/dist/render/updateElements.js +33 -0
  273. package/dist/render/updateElements.min.js +1 -0
  274. package/dist/renderOnly.d.ts +2 -0
  275. package/dist/renderOnly.js +27 -0
  276. package/dist/renderOnly.min.js +1 -0
  277. package/dist/sync/index.d.ts +6 -0
  278. package/dist/sync/index.js +21 -0
  279. package/dist/sync/index.min.js +1 -0
  280. package/dist/sync/updateChildren.d.ts +7 -0
  281. package/dist/sync/updateChildren.js +38 -0
  282. package/dist/sync/updateChildren.min.js +1 -0
  283. package/dist/sync/updateDomItem.d.ts +8 -0
  284. package/dist/sync/updateDomItem.js +53 -0
  285. package/dist/sync/updateDomItem.min.js +1 -0
  286. package/dist/sync/updateDomItems.d.ts +9 -0
  287. package/dist/sync/updateDomItems.js +33 -0
  288. package/dist/sync/updateDomItems.min.js +1 -0
  289. package/package.json +74 -4
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ const definitions_1 = __importDefault(require("./definitions"));
15
+ /**
16
+ * The properties an item has only because of its traits, and which do not belong in json (the element of the render
17
+ * trait, for one).
18
+ * @param item - The item to look at.
19
+ * @private
20
+ */
21
+ const getNonSerializableKeys = item => Object.keys(item.has ?? {}).flatMap(trait => {
22
+ const definition = definitions_1.default.get(trait);
23
+ return definition && definition.serializable === false ? definition.keys : [];
24
+ });
25
+ exports.default = getNonSerializableKeys;
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const definitions_1=__importDefault(require("./definitions")),getNonSerializableKeys=e=>Object.keys(e.has??{}).flatMap(e=>{const t=definitions_1.default.get(e);return t&&!1===t.serializable?t.keys:[]});exports.default=getNonSerializableKeys;
@@ -0,0 +1,7 @@
1
+ import type { TraitDefinition } from '../types';
2
+ /**
3
+ * The runtime definition of a trait, if it was defined.
4
+ * @param name - The name of the trait.
5
+ */
6
+ declare const getTraitDefinition: (name: string) => TraitDefinition | undefined;
7
+ export default getTraitDefinition;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ const definitions_1 = __importDefault(require("./definitions"));
15
+ /**
16
+ * The runtime definition of a trait, if it was defined.
17
+ * @param name - The name of the trait.
18
+ */
19
+ const getTraitDefinition = name => definitions_1.default.get(name);
20
+ exports.default = getTraitDefinition;
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const definitions_1=__importDefault(require("./definitions")),getTraitDefinition=e=>definitions_1.default.get(e);exports.default=getTraitDefinition;
@@ -0,0 +1,8 @@
1
+ import type { CoreItem, TraitName, WithTraits } from '../types';
2
+ /**
3
+ * Whether an item has a trait. It is also a type guard: after the check the trait's data is typed on the item.
4
+ * @param item - The item to check.
5
+ * @param trait - The name of the trait.
6
+ */
7
+ declare const hasTrait: <Trait extends TraitName>(item: CoreItem, trait: Trait) => item is CoreItem & WithTraits<Trait>;
8
+ export default hasTrait;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ /**
10
+ * Whether an item has a trait. It is also a type guard: after the check the trait's data is typed on the item.
11
+ * @param item - The item to check.
12
+ * @param trait - The name of the trait.
13
+ */
14
+ const hasTrait = (item, trait) => (item.has ?? {})[trait] === true;
15
+ exports.default = hasTrait;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const hasTrait=(e,t)=>!0===(e.has??{})[t];exports.default=hasTrait;
@@ -0,0 +1,9 @@
1
+ import type { CoreItem, TraitName, WithTraits } from '../types';
2
+ /**
3
+ * Whether an item has all of these traits. It is also a type guard: after the check the data of every one of the traits
4
+ * is typed on the item.
5
+ * @param item - The item to check.
6
+ * @param traits - The names of the traits.
7
+ */
8
+ declare const hasTraits: <Trait extends TraitName>(item: CoreItem, ...traits: Trait[]) => item is CoreItem & WithTraits<Trait>;
9
+ export default hasTraits;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ /**
10
+ * Whether an item has all of these traits. It is also a type guard: after the check the data of every one of the traits
11
+ * is typed on the item.
12
+ * @param item - The item to check.
13
+ * @param traits - The names of the traits.
14
+ */
15
+ const hasTraits = (item, ...traits) => traits.every(trait => (item.has ?? {})[trait] === true);
16
+ exports.default = hasTraits;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const hasTraits=(e,...s)=>s.every(s=>!0===(e.has??{})[s]);exports.default=hasTraits;
@@ -0,0 +1,8 @@
1
+ import type { CoreItem, DomItem } from '../types';
2
+ /**
3
+ * Whether an item, and every item below it, has the render trait: the tree treeloom's render and sync functions work
4
+ * on. hasTrait only checks the one item, so use this where a tree comes from somewhere else. It is also a type guard.
5
+ * @param item - The item at the top of the tree to check.
6
+ */
7
+ declare const isDomItem: (item: CoreItem) => item is DomItem;
8
+ export default isDomItem;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ const hasTrait_1 = __importDefault(require("./hasTrait"));
15
+ /**
16
+ * Whether an item, and every item below it, has the render trait: the tree treeloom's render and sync functions work
17
+ * on. hasTrait only checks the one item, so use this where a tree comes from somewhere else. It is also a type guard.
18
+ * @param item - The item at the top of the tree to check.
19
+ */
20
+ const isDomItem = item => (0, hasTrait_1.default)(item, 'render') && item.children.every(isDomItem);
21
+ exports.default = isDomItem;
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const hasTrait_1=__importDefault(require("./hasTrait")),isDomItem=e=>(0,hasTrait_1.default)(e,"render")&&e.children.every(isDomItem);exports.default=isDomItem;
@@ -0,0 +1,11 @@
1
+ import type { CoreItem, TraitName, TraitRegistry, WithTraits } from '../types';
2
+ /**
3
+ * Give an item a trait: the trait's defaults and the given data are put on the item (the same object, not a copy), and
4
+ * it is added to the item's has map.
5
+ * @param item - The item which gains the trait.
6
+ * @param trait - The name of the trait.
7
+ * @param data - The data the trait puts on the item.
8
+ * @returns The same item, now with the trait.
9
+ */
10
+ declare const withTrait: <Item extends CoreItem, Trait extends TraitName>(item: Item, trait: Trait, data: TraitRegistry[Trait]) => Item & WithTraits<Trait>;
11
+ export default withTrait;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ const definitions_1 = __importDefault(require("./definitions"));
15
+ /**
16
+ * Give an item a trait: the trait's defaults and the given data are put on the item (the same object, not a copy), and
17
+ * it is added to the item's has map.
18
+ * @param item - The item which gains the trait.
19
+ * @param trait - The name of the trait.
20
+ * @param data - The data the trait puts on the item.
21
+ * @returns The same item, now with the trait.
22
+ */
23
+ const withTrait = (item, trait, data) => {
24
+ Object.assign(item, definitions_1.default.get(trait)?.defaults?.(), data);
25
+ item.has = Object.assign(item.has ?? {}, {
26
+ [trait]: true
27
+ });
28
+ return item;
29
+ };
30
+ exports.default = withTrait;
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const definitions_1=__importDefault(require("./definitions")),withTrait=(e,t,i)=>(Object.assign(e,definitions_1.default.get(t)?.defaults?.(),i),e.has=Object.assign(e.has??{},{[t]:!0}),e);exports.default=withTrait;
@@ -0,0 +1,8 @@
1
+ import type { DomItem } from '../types';
2
+ /**
3
+ * Append a child to the end of given parent's children list.
4
+ * @param parent - The parent that will receive the child.
5
+ * @param child - The new child to attach to the parent.
6
+ */
7
+ declare const appendChild: (parent: DomItem, child: DomItem) => DomItem;
8
+ export default appendChild;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ /**
10
+ * Append a child to the end of given parent's children list.
11
+ * @param parent - The parent that will receive the child.
12
+ * @param child - The new child to attach to the parent.
13
+ */
14
+ const appendChild = (parent, child) => {
15
+ parent.children.push(child);
16
+ child.parentItem = parent;
17
+ return parent;
18
+ };
19
+ exports.default = appendChild;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const appendChild=(e,t)=>(e.children.push(t),t.parentItem=e,e);exports.default=appendChild;
@@ -0,0 +1,10 @@
1
+ import type { DomItem, ItemPath } from '../types';
2
+ /**
3
+ * Resolve a path (as built by getItemPath) back to the item it points at, starting from the root. Throws when the
4
+ * path no longer matches the tree's current shape - exactly like a stale reference to a real DOM element would, a
5
+ * path is only valid for as long as the tree it was built from keeps the same shape.
6
+ * @param root - The item the path is relative to (usually documentItem).
7
+ * @param path - The path to resolve, as returned by getItemPath.
8
+ */
9
+ declare const getItemByPath: (root: DomItem, path: ItemPath) => DomItem;
10
+ export default getItemByPath;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ /**
10
+ * Resolve a path (as built by getItemPath) back to the item it points at, starting from the root. Throws when the
11
+ * path no longer matches the tree's current shape - exactly like a stale reference to a real DOM element would, a
12
+ * path is only valid for as long as the tree it was built from keeps the same shape.
13
+ * @param root - The item the path is relative to (usually documentItem).
14
+ * @param path - The path to resolve, as returned by getItemPath.
15
+ */
16
+ const getItemByPath = (root, path) => path.reduce((item, index) => {
17
+ const child = item.children[index];
18
+ if (!child) {
19
+ throw new Error(`No item at index ${index} of path [${path.join(', ')}] - the tree may have changed shape since this path was built.`);
20
+ }
21
+ return child;
22
+ }, root);
23
+ exports.default = getItemByPath;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const getItemByPath=(e,t)=>t.reduce((e,r)=>{const a=e.children[r];if(!a)throw new Error(`No item at index ${r} of path [${t.join(", ")}] - the tree may have changed shape since this path was built.`);return a},e);exports.default=getItemByPath;
@@ -0,0 +1,9 @@
1
+ import type { DomItem, ItemPath } from '../types';
2
+ /**
3
+ * The path from the root to an item: the index of the item among its parent's children, at each level from the top
4
+ * down. An empty array means the item is the root itself.
5
+ * WARNING: This is a recursive function.
6
+ * @param item - The DomItem to find the path of.
7
+ */
8
+ declare const getItemPath: (item: DomItem) => ItemPath;
9
+ export default getItemPath;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ const si_funciona_1 = __importDefault(require("si-funciona"));
15
+ /**
16
+ * The path from the root to an item: the index of the item among its parent's children, at each level from the top
17
+ * down. An empty array means the item is the root itself.
18
+ * WARNING: This is a recursive function.
19
+ * @param item - The DomItem to find the path of.
20
+ */
21
+ const getItemPath = item => {
22
+ if (item.parentItem === null) {
23
+ throw new Error('Detached child, missing parentItem reference. Use empty object if this is the root item.');
24
+ }
25
+ if (si_funciona_1.default.emptyObject(item.parentItem)) {
26
+ return [];
27
+ }
28
+ const parent = item.parentItem;
29
+ return [...getItemPath(parent), parent.children.indexOf(item)];
30
+ };
31
+ exports.default = getItemPath;
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const si_funciona_1=__importDefault(require("si-funciona")),getItemPath=e=>{if(null===e.parentItem)throw new Error("Detached child, missing parentItem reference. Use empty object if this is the root item.");if(si_funciona_1.default.emptyObject(e.parentItem))return[];const t=e.parentItem;return[...getItemPath(t),t.children.indexOf(e)]};exports.default=getItemPath;
@@ -0,0 +1,8 @@
1
+ import type { DomItem, DomItemRoot } from '../types';
2
+ /**
3
+ * Get the upper parentItem for the provided child. (usually this is a documentItem reference)
4
+ * WARNING: This is a recursive function.
5
+ * @param item - The DomItem which we want the highest parent item of
6
+ */
7
+ declare const getTopParentItem: (item: DomItem) => DomItemRoot;
8
+ export default getTopParentItem;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ const si_funciona_1 = __importDefault(require("si-funciona"));
15
+ /**
16
+ * Get the upper parentItem for the provided child. (usually this is a documentItem reference)
17
+ * WARNING: This is a recursive function.
18
+ * @param item - The DomItem which we want the highest parent item of
19
+ */
20
+ const getTopParentItem = item => {
21
+ if (item.parentItem === null) {
22
+ if (item.nodeName === '#document') {
23
+ throw new Error('Root parent item must be an empty object, null reference found.');
24
+ }
25
+ throw new Error('Detached child, missing parentItem reference. Use empty object if this is the root item.');
26
+ }
27
+ return si_funciona_1.default.emptyObject(item.parentItem) ? item : getTopParentItem(item.parentItem);
28
+ };
29
+ exports.default = getTopParentItem;
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const si_funciona_1=__importDefault(require("si-funciona")),getTopParentItem=e=>{if(null===e.parentItem){if("#document"===e.nodeName)throw new Error("Root parent item must be an empty object, null reference found.");throw new Error("Detached child, missing parentItem reference. Use empty object if this is the root item.")}return si_funciona_1.default.emptyObject(e.parentItem)?e:getTopParentItem(e.parentItem)};exports.default=getTopParentItem;
@@ -0,0 +1,11 @@
1
+ import type { DomItem } from '../types';
2
+ /**
3
+ * Insert a child into a parent's children list at a given position (like appendChild, but positioned). Appending is
4
+ * insertChild at the end: `appendChild(parent, child)` is `insertChild(parent, child, parent.children.length)`.
5
+ * @param parent - The parent that will receive the child.
6
+ * @param child - The new child to attach to the parent.
7
+ * @param index - Where in parent's children the child goes; out of range clamps to the nearest end, so 0 is always
8
+ * the front and a large index is always the back (matching Array.prototype.splice).
9
+ */
10
+ declare const insertChild: (parent: DomItem, child: DomItem, index: number) => DomItem;
11
+ export default insertChild;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ /**
10
+ * Insert a child into a parent's children list at a given position (like appendChild, but positioned). Appending is
11
+ * insertChild at the end: `appendChild(parent, child)` is `insertChild(parent, child, parent.children.length)`.
12
+ * @param parent - The parent that will receive the child.
13
+ * @param child - The new child to attach to the parent.
14
+ * @param index - Where in parent's children the child goes; out of range clamps to the nearest end, so 0 is always
15
+ * the front and a large index is always the back (matching Array.prototype.splice).
16
+ */
17
+ const insertChild = (parent, child, index) => {
18
+ parent.children.splice(index, 0, child);
19
+ child.parentItem = parent;
20
+ return parent;
21
+ };
22
+ exports.default = insertChild;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const insertChild=(e,t,r)=>(e.children.splice(r,0,t),t.parentItem=e,e);exports.default=insertChild;
@@ -0,0 +1,43 @@
1
+ import type { DomItem, DomItemRoot } from '../types';
2
+ export declare const generateItemId: () => number;
3
+ /**
4
+ * Register an item (and, recursively, its whole subtree) in its own root's id index, so getItemById can find
5
+ * it. Call once a subtree's relationship to its parent is settled - see renderHtml, which is the one place
6
+ * that happens for a freshly-attached subtree. Does nothing when item is not under a real root yet (or ever).
7
+ *
8
+ * Repairs two ways an item can reach this point without the id createCoreItem is supposed to have already
9
+ * stamped on it, rather than requiring every consumer to avoid either:
10
+ * - No id at all (`typeof item.id !== 'number'`): a raw plain config object merged directly onto an
11
+ * already-rendered tree (si-funciona's mergeObjectsMutable, by reference, "as is", when the two sides'
12
+ * shapes do not line up index-for-index - see updatePlayerStats.ts) never passed through createCoreItem at
13
+ * all, so it has no id (or parentItem, or has map) whatsoever.
14
+ * - A collision (the id is already registered to a *different* item within this same root): a generic "build
15
+ * one item, then replicate it N times" helper (si-funciona's buildArray, cloning rather than constructing
16
+ * fresh - the shape matrix-dom's own buildMatrix uses for a grid's rows/columns/tiles) copies whatever id
17
+ * the one template already carries into every copy right along with everything else, with no way for
18
+ * treeloom to know that happened before registration.
19
+ *
20
+ * Catching both here, at the one real choke point every attached item passes through, protects against these
21
+ * patterns (and any other generic cloning or raw merging this codebase does not yet know about) without
22
+ * needing every consumer to avoid them. A real reuse of someone else's id (rather than two different items
23
+ * both starting unassigned) is not realistically distinguishable from the collision case, so the same repair
24
+ * applies regardless of cause - the alternative (leaving it in place) silently breaks resolution for one of
25
+ * the two items, which is worse than quietly handing the second one a fresh id.
26
+ * @param item - The subtree to register, root item included.
27
+ */
28
+ export declare const registerItemIds: (item: DomItem) => void;
29
+ /**
30
+ * Remove an item (and, recursively, its whole subtree) from its own root's id index - the reverse of
31
+ * registerItemIds. Call before the item is actually detached, while its parentItem chain still resolves and
32
+ * its own subtree is still intact to walk.
33
+ * @param item - The subtree to unregister, root item included.
34
+ */
35
+ export declare const unregisterItemIds: (item: DomItem) => void;
36
+ /**
37
+ * Resolve an id (as captured off a DomItem's own id) back to the item it refers to, within root's own tree.
38
+ * Throws when the id isn't registered against this root - the same "stale reference" contract getItemByPath
39
+ * already has: a silent wrong-answer resolution is worse than a loud failure.
40
+ * @param root - The tree to resolve the id against.
41
+ * @param id - The id to resolve, as read directly off a DomItem's own id property.
42
+ */
43
+ export declare const getItemById: (root: DomItemRoot, id: number) => DomItem;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ exports.getItemById = exports.unregisterItemIds = exports.registerItemIds = exports.generateItemId = void 0;
15
+ const si_funciona_1 = __importDefault(require("si-funciona"));
16
+ const collect_your_stuff_1 = require("collect-your-stuff");
17
+ /** One lookup index per treeloom process: every root's own ids live in their own scope, so two unrelated trees
18
+ * (the server's real tree and a client's independently-built one) never collide even though both number their
19
+ * items starting from the same small integers. */
20
+ const itemsById = new collect_your_stuff_1.ScopedCollection();
21
+ /** The next id to assign - a plain, process-local monotonic counter (not a UUID: cheaper to generate/compare/
22
+ * serialize, and uniqueness only ever needs to hold within one process, since nothing resolves an id against a
23
+ * different root than the one it came from). Exported for createCoreItem's own first stamp and for this
24
+ * module's own collision repair below - kept here, not there, since this module must never import back from
25
+ * createCoreItem (which already imports this one, via removeChild - see unregisterItemIds's own caller). */
26
+ let nextItemId = 0;
27
+ const generateItemId = () => nextItemId++;
28
+ exports.generateItemId = generateItemId;
29
+ /**
30
+ * The real root above item, or null when item's own parentItem chain never reaches one. That covers two
31
+ * different, both legitimate cases: an item rendered into some arbitrary, never-rooted container (see
32
+ * renderHtml's own tests - not one forwarding could ever target, so it is not an error for it to have no
33
+ * id-index entry), and an item that was never completed as a real DomItem at all - a raw plain config object
34
+ * merged directly onto an already-rendered tree (si-funciona's mergeObjectsMutable, by reference, "as is",
35
+ * when the two sides' shapes do not line up index-for-index - see updatePlayerStats.ts) carries no parentItem
36
+ * property whatsoever, `undefined` rather than this codebase's own usual `null` for "detached". Unlike
37
+ * getTopParentItem, this never throws: it is used purely to decide whether registration applies, not to
38
+ * assert that a real root exists.
39
+ * @param item
40
+ */
41
+ const tryGetRoot = item => {
42
+ let current = item;
43
+ while (current.parentItem != null) {
44
+ if (si_funciona_1.default.emptyObject(current.parentItem)) {
45
+ return current;
46
+ }
47
+ current = current.parentItem;
48
+ }
49
+ return null;
50
+ };
51
+ /**
52
+ * Register an item (and, recursively, its whole subtree) in its own root's id index, so getItemById can find
53
+ * it. Call once a subtree's relationship to its parent is settled - see renderHtml, which is the one place
54
+ * that happens for a freshly-attached subtree. Does nothing when item is not under a real root yet (or ever).
55
+ *
56
+ * Repairs two ways an item can reach this point without the id createCoreItem is supposed to have already
57
+ * stamped on it, rather than requiring every consumer to avoid either:
58
+ * - No id at all (`typeof item.id !== 'number'`): a raw plain config object merged directly onto an
59
+ * already-rendered tree (si-funciona's mergeObjectsMutable, by reference, "as is", when the two sides'
60
+ * shapes do not line up index-for-index - see updatePlayerStats.ts) never passed through createCoreItem at
61
+ * all, so it has no id (or parentItem, or has map) whatsoever.
62
+ * - A collision (the id is already registered to a *different* item within this same root): a generic "build
63
+ * one item, then replicate it N times" helper (si-funciona's buildArray, cloning rather than constructing
64
+ * fresh - the shape matrix-dom's own buildMatrix uses for a grid's rows/columns/tiles) copies whatever id
65
+ * the one template already carries into every copy right along with everything else, with no way for
66
+ * treeloom to know that happened before registration.
67
+ *
68
+ * Catching both here, at the one real choke point every attached item passes through, protects against these
69
+ * patterns (and any other generic cloning or raw merging this codebase does not yet know about) without
70
+ * needing every consumer to avoid them. A real reuse of someone else's id (rather than two different items
71
+ * both starting unassigned) is not realistically distinguishable from the collision case, so the same repair
72
+ * applies regardless of cause - the alternative (leaving it in place) silently breaks resolution for one of
73
+ * the two items, which is worse than quietly handing the second one a fresh id.
74
+ * @param item - The subtree to register, root item included.
75
+ */
76
+ const registerItemIds = item => {
77
+ const root = tryGetRoot(item);
78
+ if (!root) {
79
+ return;
80
+ }
81
+ const alreadyThere = typeof item.id === 'number' ? itemsById.get(root, item.id) : undefined;
82
+ if (typeof item.id !== 'number' || alreadyThere && alreadyThere !== item) {
83
+ item.id = (0, exports.generateItemId)();
84
+ }
85
+ itemsById.set(root, item.id, item);
86
+ (item.children || []).forEach(exports.registerItemIds);
87
+ };
88
+ exports.registerItemIds = registerItemIds;
89
+ /**
90
+ * Remove an item (and, recursively, its whole subtree) from its own root's id index - the reverse of
91
+ * registerItemIds. Call before the item is actually detached, while its parentItem chain still resolves and
92
+ * its own subtree is still intact to walk.
93
+ * @param item - The subtree to unregister, root item included.
94
+ */
95
+ const unregisterItemIds = item => {
96
+ const root = tryGetRoot(item);
97
+ if (!root) {
98
+ return;
99
+ }
100
+ itemsById.delete(root, item.id);
101
+ (item.children || []).forEach(exports.unregisterItemIds);
102
+ };
103
+ exports.unregisterItemIds = unregisterItemIds;
104
+ /**
105
+ * Resolve an id (as captured off a DomItem's own id) back to the item it refers to, within root's own tree.
106
+ * Throws when the id isn't registered against this root - the same "stale reference" contract getItemByPath
107
+ * already has: a silent wrong-answer resolution is worse than a loud failure.
108
+ * @param root - The tree to resolve the id against.
109
+ * @param id - The id to resolve, as read directly off a DomItem's own id property.
110
+ */
111
+ const getItemById = (root, id) => {
112
+ const item = itemsById.get(root, id);
113
+ if (!item) {
114
+ throw new Error(`No item with id ${id} in this tree - it may have been removed, or never belonged to it.`);
115
+ }
116
+ return item;
117
+ };
118
+ exports.getItemById = getItemById;
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getItemById=exports.unregisterItemIds=exports.registerItemIds=exports.generateItemId=void 0;const si_funciona_1=__importDefault(require("si-funciona")),collect_your_stuff_1=require("collect-your-stuff"),itemsById=new collect_your_stuff_1.ScopedCollection;let nextItemId=0;const generateItemId=()=>nextItemId++;exports.generateItemId=generateItemId;const tryGetRoot=e=>{let t=e;for(;null!=t.parentItem;){if(si_funciona_1.default.emptyObject(t.parentItem))return t;t=t.parentItem}return null},registerItemIds=e=>{const t=tryGetRoot(e);if(!t)return;const r="number"==typeof e.id?itemsById.get(t,e.id):void 0;("number"!=typeof e.id||r&&r!==e)&&(e.id=(0,exports.generateItemId)()),itemsById.set(t,e.id,e),(e.children||[]).forEach(exports.registerItemIds)};exports.registerItemIds=registerItemIds;const unregisterItemIds=e=>{const t=tryGetRoot(e);t&&(itemsById.delete(t,e.id),(e.children||[]).forEach(exports.unregisterItemIds))};exports.unregisterItemIds=unregisterItemIds;const getItemById=(e,t)=>{const r=itemsById.get(e,t);if(!r)throw new Error(`No item with id ${t} in this tree - it may have been removed, or never belonged to it.`);return r};exports.getItemById=getItemById;
@@ -0,0 +1,8 @@
1
+ import type { DomItem } from '../types';
2
+ /**
3
+ * Reverse of appendHtml, remove a DomItem and have the associated element removed.
4
+ * @param parent - The parent of the items
5
+ * @param child - The DomItem with HTMLElement to be removed
6
+ */
7
+ declare const removeChild: (parent: DomItem, child: DomItem) => DomItem[];
8
+ export default removeChild;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ /* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ const itemIdIndex_1 = require("./itemIdIndex");
10
+ /**
11
+ * Reverse of appendHtml, remove a DomItem and have the associated element removed.
12
+ * @param parent - The parent of the items
13
+ * @param child - The DomItem with HTMLElement to be removed
14
+ */
15
+ const removeChild = (parent, child) => {
16
+ // Before detaching: child's own parentItem chain (still pointing at parent) is what resolves its root.
17
+ (0, itemIdIndex_1.unregisterItemIds)(child);
18
+ parent.element.removeChild(child.element);
19
+ return parent.children.splice(parent.children.indexOf(child), 1);
20
+ };
21
+ exports.default = removeChild;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const itemIdIndex_1=require("./itemIdIndex"),removeChild=(e,d)=>((0,itemIdIndex_1.unregisterItemIds)(d),e.element.removeChild(d.element),e.children.splice(e.children.indexOf(d),1));exports.default=removeChild;
@@ -0,0 +1,7 @@
1
+ import type { DomItem } from '../types';
2
+ /**
3
+ * For each child of this item, set the parentItem references.
4
+ * @param item - The DomItem to have parent references applied.
5
+ */
6
+ declare const setParentItemReferences: (item: DomItem) => DomItem;
7
+ export default setParentItemReferences;