treeloom 0.0.0-stage → 2.0.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.
- package/LICENSE +373 -0
- package/README.md +72 -2
- package/browser/treeloom.js +11006 -0
- package/browser/treeloom.min.js +1 -0
- package/browser/treeloomRenderOnly.js +10530 -0
- package/browser/treeloomRenderOnly.min.js +1 -0
- package/dist/deflate/domItemToJson.d.ts +14 -0
- package/dist/deflate/domItemToJson.js +43 -0
- package/dist/deflate/domItemToJson.min.js +1 -0
- package/dist/deflate/index.d.ts +7 -0
- package/dist/deflate/index.js +19 -0
- package/dist/deflate/index.min.js +1 -0
- package/dist/deflate/removeEmptyProperties.d.ts +8 -0
- package/dist/deflate/removeEmptyProperties.js +43 -0
- package/dist/deflate/removeEmptyProperties.min.js +1 -0
- package/dist/diff/createChangeList.d.ts +9 -0
- package/dist/diff/createChangeList.js +44 -0
- package/dist/diff/createChangeList.min.js +1 -0
- package/dist/diff/domItemChanges.d.ts +9 -0
- package/dist/diff/domItemChanges.js +154 -0
- package/dist/diff/domItemChanges.min.js +1 -0
- package/dist/diff/domItemHasAttribute.d.ts +11 -0
- package/dist/diff/domItemHasAttribute.js +63 -0
- package/dist/diff/domItemHasAttribute.min.js +1 -0
- package/dist/diff/elementChanges.d.ts +10 -0
- package/dist/diff/elementChanges.js +151 -0
- package/dist/diff/elementChanges.min.js +1 -0
- package/dist/diff/elementHasAttribute.d.ts +10 -0
- package/dist/diff/elementHasAttribute.js +70 -0
- package/dist/diff/elementHasAttribute.min.js +1 -0
- package/dist/diff/getAssignedStyles.d.ts +9 -0
- package/dist/diff/getAssignedStyles.js +22 -0
- package/dist/diff/getAssignedStyles.min.js +1 -0
- package/dist/diff/index.d.ts +9 -0
- package/dist/diff/index.js +27 -0
- package/dist/diff/index.min.js +1 -0
- package/dist/diff/types.d.ts +17 -0
- package/dist/diff/types.js +8 -0
- package/dist/diff/types.min.js +1 -0
- package/dist/domItem/index.d.ts +34 -0
- package/dist/domItem/index.js +81 -0
- package/dist/domItem/index.min.js +1 -0
- package/dist/domItem/objects/addDomItemProperties.d.ts +7 -0
- package/dist/domItem/objects/addDomItemProperties.js +27 -0
- package/dist/domItem/objects/addDomItemProperties.min.js +1 -0
- package/dist/domItem/objects/createCoreItem.d.ts +9 -0
- package/dist/domItem/objects/createCoreItem.js +53 -0
- package/dist/domItem/objects/createCoreItem.min.js +1 -0
- package/dist/domItem/objects/createDomItem.d.ts +10 -0
- package/dist/domItem/objects/createDomItem.js +40 -0
- package/dist/domItem/objects/createDomItem.min.js +1 -0
- package/dist/domItem/objects/documentDomItem.d.ts +12 -0
- package/dist/domItem/objects/documentDomItem.js +36 -0
- package/dist/domItem/objects/documentDomItem.min.js +1 -0
- package/dist/domItem/objects/documentItem.d.ts +18 -0
- package/dist/domItem/objects/documentItem.js +40 -0
- package/dist/domItem/objects/documentItem.min.js +1 -0
- package/dist/domItem/objects/initChildren.d.ts +6 -0
- package/dist/domItem/objects/initChildren.js +44 -0
- package/dist/domItem/objects/initChildren.min.js +1 -0
- package/dist/domItem/objects/initRoot.d.ts +9 -0
- package/dist/domItem/objects/initRoot.js +32 -0
- package/dist/domItem/objects/initRoot.min.js +1 -0
- package/dist/domItem/query/gatherChildItems.d.ts +12 -0
- package/dist/domItem/query/gatherChildItems.js +19 -0
- package/dist/domItem/query/gatherChildItems.min.js +1 -0
- package/dist/domItem/query/getChildTest.d.ts +8 -0
- package/dist/domItem/query/getChildTest.js +15 -0
- package/dist/domItem/query/getChildTest.min.js +1 -0
- package/dist/domItem/query/getChildrenByClass.d.ts +11 -0
- package/dist/domItem/query/getChildrenByClass.js +26 -0
- package/dist/domItem/query/getChildrenByClass.min.js +1 -0
- package/dist/domItem/query/getChildrenByName.d.ts +9 -0
- package/dist/domItem/query/getChildrenByName.js +23 -0
- package/dist/domItem/query/getChildrenByName.min.js +1 -0
- package/dist/domItem/query/getChildrenFromAttribute.d.ts +13 -0
- package/dist/domItem/query/getChildrenFromAttribute.js +28 -0
- package/dist/domItem/query/getChildrenFromAttribute.min.js +1 -0
- package/dist/domItem/query/getItemByElement.d.ts +11 -0
- package/dist/domItem/query/getItemByElement.js +29 -0
- package/dist/domItem/query/getItemByElement.min.js +1 -0
- package/dist/domItem/query/getParentsByClass.d.ts +12 -0
- package/dist/domItem/query/getParentsByClass.js +40 -0
- package/dist/domItem/query/getParentsByClass.min.js +1 -0
- package/dist/domItem/query/getParentsByName.d.ts +9 -0
- package/dist/domItem/query/getParentsByName.js +23 -0
- package/dist/domItem/query/getParentsByName.min.js +1 -0
- package/dist/domItem/query/getParentsByTagName.d.ts +9 -0
- package/dist/domItem/query/getParentsByTagName.js +23 -0
- package/dist/domItem/query/getParentsByTagName.min.js +1 -0
- package/dist/domItem/query/getParentsFromAttribute.d.ts +13 -0
- package/dist/domItem/query/getParentsFromAttribute.js +39 -0
- package/dist/domItem/query/getParentsFromAttribute.min.js +1 -0
- package/dist/domItem/traits/defineTrait.d.ts +10 -0
- package/dist/domItem/traits/defineTrait.js +26 -0
- package/dist/domItem/traits/defineTrait.min.js +1 -0
- package/dist/domItem/traits/definitions.d.ts +7 -0
- package/dist/domItem/traits/definitions.js +20 -0
- package/dist/domItem/traits/definitions.min.js +1 -0
- package/dist/domItem/traits/getNonSerializableKeys.d.ts +9 -0
- package/dist/domItem/traits/getNonSerializableKeys.js +25 -0
- package/dist/domItem/traits/getNonSerializableKeys.min.js +1 -0
- package/dist/domItem/traits/getTraitDefinition.d.ts +7 -0
- package/dist/domItem/traits/getTraitDefinition.js +20 -0
- package/dist/domItem/traits/getTraitDefinition.min.js +1 -0
- package/dist/domItem/traits/hasTrait.d.ts +8 -0
- package/dist/domItem/traits/hasTrait.js +15 -0
- package/dist/domItem/traits/hasTrait.min.js +1 -0
- package/dist/domItem/traits/hasTraits.d.ts +9 -0
- package/dist/domItem/traits/hasTraits.js +16 -0
- package/dist/domItem/traits/hasTraits.min.js +1 -0
- package/dist/domItem/traits/isDomItem.d.ts +8 -0
- package/dist/domItem/traits/isDomItem.js +21 -0
- package/dist/domItem/traits/isDomItem.min.js +1 -0
- package/dist/domItem/traits/withTrait.d.ts +11 -0
- package/dist/domItem/traits/withTrait.js +30 -0
- package/dist/domItem/traits/withTrait.min.js +1 -0
- package/dist/domItem/tree/appendChild.d.ts +8 -0
- package/dist/domItem/tree/appendChild.js +19 -0
- package/dist/domItem/tree/appendChild.min.js +1 -0
- package/dist/domItem/tree/getItemByPath.d.ts +10 -0
- package/dist/domItem/tree/getItemByPath.js +23 -0
- package/dist/domItem/tree/getItemByPath.min.js +1 -0
- package/dist/domItem/tree/getItemPath.d.ts +9 -0
- package/dist/domItem/tree/getItemPath.js +31 -0
- package/dist/domItem/tree/getItemPath.min.js +1 -0
- package/dist/domItem/tree/getTopParentItem.d.ts +8 -0
- package/dist/domItem/tree/getTopParentItem.js +29 -0
- package/dist/domItem/tree/getTopParentItem.min.js +1 -0
- package/dist/domItem/tree/insertChild.d.ts +11 -0
- package/dist/domItem/tree/insertChild.js +22 -0
- package/dist/domItem/tree/insertChild.min.js +1 -0
- package/dist/domItem/tree/itemIdIndex.d.ts +43 -0
- package/dist/domItem/tree/itemIdIndex.js +118 -0
- package/dist/domItem/tree/itemIdIndex.min.js +1 -0
- package/dist/domItem/tree/removeChild.d.ts +8 -0
- package/dist/domItem/tree/removeChild.js +21 -0
- package/dist/domItem/tree/removeChild.min.js +1 -0
- package/dist/domItem/tree/setParentItemReferences.d.ts +7 -0
- package/dist/domItem/tree/setParentItemReferences.js +24 -0
- package/dist/domItem/tree/setParentItemReferences.min.js +1 -0
- package/dist/domItem/types.d.ts +131 -0
- package/dist/domItem/types.js +8 -0
- package/dist/domItem/types.min.js +1 -0
- package/dist/events/functions/activateListener.d.ts +10 -0
- package/dist/events/functions/activateListener.js +45 -0
- package/dist/events/functions/activateListener.min.js +1 -0
- package/dist/events/functions/addEventListener.d.ts +23 -0
- package/dist/events/functions/addEventListener.js +54 -0
- package/dist/events/functions/addEventListener.min.js +1 -0
- package/dist/events/functions/applyActiveListeners.d.ts +9 -0
- package/dist/events/functions/applyActiveListeners.js +52 -0
- package/dist/events/functions/applyActiveListeners.min.js +1 -0
- package/dist/events/functions/assignListener.d.ts +12 -0
- package/dist/events/functions/assignListener.js +39 -0
- package/dist/events/functions/assignListener.min.js +1 -0
- package/dist/events/functions/bindAllListeners.d.ts +10 -0
- package/dist/events/functions/bindAllListeners.js +28 -0
- package/dist/events/functions/bindAllListeners.min.js +1 -0
- package/dist/events/functions/bindElementListeners.d.ts +7 -0
- package/dist/events/functions/bindElementListeners.js +34 -0
- package/dist/events/functions/bindElementListeners.min.js +1 -0
- package/dist/events/functions/bindListeners.d.ts +9 -0
- package/dist/events/functions/bindListeners.js +23 -0
- package/dist/events/functions/bindListeners.min.js +1 -0
- package/dist/events/functions/deactivateListener.d.ts +13 -0
- package/dist/events/functions/deactivateListener.js +58 -0
- package/dist/events/functions/deactivateListener.min.js +1 -0
- package/dist/events/functions/deactivateListeners.d.ts +7 -0
- package/dist/events/functions/deactivateListeners.js +22 -0
- package/dist/events/functions/deactivateListeners.min.js +1 -0
- package/dist/events/functions/findEventListener.d.ts +22 -0
- package/dist/events/functions/findEventListener.js +61 -0
- package/dist/events/functions/findEventListener.min.js +1 -0
- package/dist/events/functions/fullAddEventListener.d.ts +20 -0
- package/dist/events/functions/fullAddEventListener.js +45 -0
- package/dist/events/functions/fullAddEventListener.min.js +1 -0
- package/dist/events/functions/fullRemoveEventListener.d.ts +22 -0
- package/dist/events/functions/fullRemoveEventListener.js +37 -0
- package/dist/events/functions/fullRemoveEventListener.min.js +1 -0
- package/dist/events/functions/listenerOptions.d.ts +12 -0
- package/dist/events/functions/listenerOptions.js +31 -0
- package/dist/events/functions/listenerOptions.min.js +1 -0
- package/dist/events/functions/makeEventHandler.d.ts +10 -0
- package/dist/events/functions/makeEventHandler.js +23 -0
- package/dist/events/functions/makeEventHandler.min.js +1 -0
- package/dist/events/functions/makeForwardingListener.d.ts +11 -0
- package/dist/events/functions/makeForwardingListener.js +46 -0
- package/dist/events/functions/makeForwardingListener.min.js +1 -0
- package/dist/events/functions/receiveForwardedEvent.d.ts +23 -0
- package/dist/events/functions/receiveForwardedEvent.js +40 -0
- package/dist/events/functions/receiveForwardedEvent.min.js +1 -0
- package/dist/events/functions/registerListener.d.ts +11 -0
- package/dist/events/functions/registerListener.js +25 -0
- package/dist/events/functions/registerListener.min.js +1 -0
- package/dist/events/functions/registerListeners.d.ts +10 -0
- package/dist/events/functions/registerListeners.js +26 -0
- package/dist/events/functions/registerListeners.min.js +1 -0
- package/dist/events/functions/removeEventListener.d.ts +18 -0
- package/dist/events/functions/removeEventListener.js +42 -0
- package/dist/events/functions/removeEventListener.min.js +1 -0
- package/dist/events/functions/retrieveListener.d.ts +14 -0
- package/dist/events/functions/retrieveListener.js +39 -0
- package/dist/events/functions/retrieveListener.min.js +1 -0
- package/dist/events/functions/revokeActiveListeners.d.ts +12 -0
- package/dist/events/functions/revokeActiveListeners.js +54 -0
- package/dist/events/functions/revokeActiveListeners.min.js +1 -0
- package/dist/events/functions/setForwardEvents.d.ts +11 -0
- package/dist/events/functions/setForwardEvents.js +26 -0
- package/dist/events/functions/setForwardEvents.min.js +1 -0
- package/dist/events/functions/unassignListener.d.ts +12 -0
- package/dist/events/functions/unassignListener.js +32 -0
- package/dist/events/functions/unassignListener.min.js +1 -0
- package/dist/events/index.d.ts +37 -0
- package/dist/events/index.js +72 -0
- package/dist/events/index.min.js +1 -0
- package/dist/events/objects/createEventListener.d.ts +13 -0
- package/dist/events/objects/createEventListener.js +30 -0
- package/dist/events/objects/createEventListener.min.js +1 -0
- package/dist/events/objects/createEventProxy.d.ts +10 -0
- package/dist/events/objects/createEventProxy.js +48 -0
- package/dist/events/objects/createEventProxy.min.js +1 -0
- package/dist/events/objects/createEventResponder.d.ts +8 -0
- package/dist/events/objects/createEventResponder.js +27 -0
- package/dist/events/objects/createEventResponder.min.js +1 -0
- package/dist/events/objects/options/getListenerOptions.d.ts +6 -0
- package/dist/events/objects/options/getListenerOptions.js +22 -0
- package/dist/events/objects/options/getListenerOptions.min.js +1 -0
- package/dist/events/objects/options/numberToOptions.d.ts +8 -0
- package/dist/events/objects/options/numberToOptions.js +21 -0
- package/dist/events/objects/options/numberToOptions.min.js +1 -0
- package/dist/events/objects/options/optionsToNumber.d.ts +9 -0
- package/dist/events/objects/options/optionsToNumber.js +27 -0
- package/dist/events/objects/options/optionsToNumber.min.js +1 -0
- package/dist/events/objects/options.d.ts +6 -0
- package/dist/events/objects/options.js +24 -0
- package/dist/events/objects/options.min.js +1 -0
- package/dist/events/types.d.ts +87 -0
- package/dist/events/types.js +8 -0
- package/dist/events/types.min.js +1 -0
- package/dist/inflate/index.d.ts +4 -0
- package/dist/inflate/index.js +17 -0
- package/dist/inflate/index.min.js +1 -0
- package/dist/inflate/jsonToDomItem.d.ts +7 -0
- package/dist/inflate/jsonToDomItem.js +30 -0
- package/dist/inflate/jsonToDomItem.min.js +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +24 -0
- package/dist/main.min.js +1 -0
- package/dist/render/generateElement.d.ts +7 -0
- package/dist/render/generateElement.js +41 -0
- package/dist/render/generateElement.min.js +1 -0
- package/dist/render/index.d.ts +8 -0
- package/dist/render/index.js +25 -0
- package/dist/render/index.min.js +1 -0
- package/dist/render/renderHtml.d.ts +16 -0
- package/dist/render/renderHtml.js +57 -0
- package/dist/render/renderHtml.min.js +1 -0
- package/dist/render/updateChildNodes.d.ts +7 -0
- package/dist/render/updateChildNodes.js +56 -0
- package/dist/render/updateChildNodes.min.js +1 -0
- package/dist/render/updateElement.d.ts +14 -0
- package/dist/render/updateElement.js +110 -0
- package/dist/render/updateElement.min.js +1 -0
- package/dist/render/updateElements.d.ts +9 -0
- package/dist/render/updateElements.js +33 -0
- package/dist/render/updateElements.min.js +1 -0
- package/dist/renderOnly.d.ts +2 -0
- package/dist/renderOnly.js +27 -0
- package/dist/renderOnly.min.js +1 -0
- package/dist/sync/index.d.ts +6 -0
- package/dist/sync/index.js +21 -0
- package/dist/sync/index.min.js +1 -0
- package/dist/sync/updateChildren.d.ts +7 -0
- package/dist/sync/updateChildren.js +38 -0
- package/dist/sync/updateChildren.min.js +1 -0
- package/dist/sync/updateDomItem.d.ts +8 -0
- package/dist/sync/updateDomItem.js +49 -0
- package/dist/sync/updateDomItem.min.js +1 -0
- package/dist/sync/updateDomItems.d.ts +9 -0
- package/dist/sync/updateDomItems.js +33 -0
- package/dist/sync/updateDomItems.min.js +1 -0
- package/package.json +74 -4
|
@@ -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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* For each child of this item, set the parentItem references.
|
|
11
|
+
* @param item - The DomItem to have parent references applied.
|
|
12
|
+
*/
|
|
13
|
+
const setParentItemReferences = item => {
|
|
14
|
+
if (!item.children || !item.children.length) {
|
|
15
|
+
item.children = [];
|
|
16
|
+
return item;
|
|
17
|
+
}
|
|
18
|
+
item.children.forEach(child => {
|
|
19
|
+
child.parentItem = item;
|
|
20
|
+
setParentItemReferences(child);
|
|
21
|
+
});
|
|
22
|
+
return item;
|
|
23
|
+
};
|
|
24
|
+
exports.default = setParentItemReferences;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const setParentItemReferences=e=>e.children&&e.children.length?(e.children.forEach(t=>{t.parentItem=e,setParentItemReferences(t)}),e):(e.children=[],e);exports.default=setParentItemReferences;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { EventListeners, EventName, EventResponder, ForwardEventsFunction, ListenerFunction } from '../events/types';
|
|
2
|
+
/** CSS property names (written in camelCase, like element.style) and their values. */
|
|
3
|
+
export type StyleValues = {
|
|
4
|
+
[property: string]: string;
|
|
5
|
+
};
|
|
6
|
+
/** A value an attribute can have. Objects are only used for the style attribute. */
|
|
7
|
+
export type AttributeValue = string | number | boolean | StyleValues | null | undefined;
|
|
8
|
+
/** All the HTML attributes of an element (className, style, id, innerHTML, data attributes, ...). */
|
|
9
|
+
export type Attributes = {
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: StyleValues;
|
|
12
|
+
/** The native custom element name (a customized built-in): <button is="fancy-button">. */
|
|
13
|
+
is?: string;
|
|
14
|
+
[attribute: string]: AttributeValue;
|
|
15
|
+
};
|
|
16
|
+
/** A real node which a DomItem is mirrored onto. */
|
|
17
|
+
export type DomElement = HTMLElement | Text | Comment | Document;
|
|
18
|
+
/** The path from the root to an item: each level's index among its parent's children, top-down. An empty array
|
|
19
|
+
* means the item is the root itself. See getItemPath, getItemByPath. */
|
|
20
|
+
export type ItemPath = number[];
|
|
21
|
+
/** The parent of the root DomItem is an empty object (a null parent means the item is detached). */
|
|
22
|
+
export type EmptyParent = Record<string, never>;
|
|
23
|
+
/**
|
|
24
|
+
* The traits an item can have, and the data each one puts on it. treeloom has one - render - and other libraries
|
|
25
|
+
* add theirs by declaration merging:
|
|
26
|
+
*
|
|
27
|
+
* declare module 'treeloom/dist/domItem/types' {
|
|
28
|
+
* interface TraitRegistry { 'matrix.row': { axis: 'y' } }
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
export interface TraitRegistry {
|
|
32
|
+
/** The item has a place for a real element (it stays null until the item is rendered). */
|
|
33
|
+
render: RenderProperties;
|
|
34
|
+
}
|
|
35
|
+
/** The name of a trait. */
|
|
36
|
+
export type TraitName = keyof TraitRegistry;
|
|
37
|
+
/** The traits an item has: a map of trait name to true. */
|
|
38
|
+
export type HasMap = {
|
|
39
|
+
[Trait in TraitName]?: true;
|
|
40
|
+
};
|
|
41
|
+
/** What the render trait puts on an item. */
|
|
42
|
+
export type RenderProperties = {
|
|
43
|
+
/** The real node this item is mirrored onto, or null while there is none. */
|
|
44
|
+
element: DomElement | null;
|
|
45
|
+
/** Generated: the listeners which are attached to the element, by event name. */
|
|
46
|
+
activeListeners?: Record<EventName, Record<number, EventResponder[]>>;
|
|
47
|
+
};
|
|
48
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (member: Union) => void : never) extends (member: infer All) => void ? All : never;
|
|
49
|
+
/** What an item gains from having all of these traits: they are in its has map, and their data is on it. */
|
|
50
|
+
export type WithTraits<Trait extends TraitName> = {
|
|
51
|
+
has: {
|
|
52
|
+
[Name in Trait]: true;
|
|
53
|
+
};
|
|
54
|
+
} & UnionToIntersection<TraitRegistry[Trait]>;
|
|
55
|
+
/** The properties every item has, whatever traits it carries. */
|
|
56
|
+
export type CoreProperties = {
|
|
57
|
+
attributes: Attributes;
|
|
58
|
+
/** All the events to be registered for the element. */
|
|
59
|
+
eventListeners: Record<EventName, EventListeners>;
|
|
60
|
+
/** The traits this item has (see TraitRegistry). */
|
|
61
|
+
has: HasMap;
|
|
62
|
+
/** Assigned once at creation (see createCoreItem) and never reassigned, including across a clone or a JSON
|
|
63
|
+
* round-trip: the stable identity getItemById resolves by, independent of the item's current position in
|
|
64
|
+
* the tree (which a client's own tree may not match exactly - see ForwardedEvent's itemId). */
|
|
65
|
+
id: number;
|
|
66
|
+
/** Property names to leave out when converting to json. */
|
|
67
|
+
jsonExclusions: string[];
|
|
68
|
+
/** Any document node name: a tag name, #text, #comment or #document. */
|
|
69
|
+
nodeName: string;
|
|
70
|
+
/** The text of a text or comment node, null for elements. */
|
|
71
|
+
nodeValue: string | null;
|
|
72
|
+
/** Attach a child to this item. */
|
|
73
|
+
appendChild(child: CoreItem): CoreItem;
|
|
74
|
+
/** Detach a child from this item (and its element, when it has one). */
|
|
75
|
+
removeChild(child: CoreItem): CoreItem[];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The generic item: one node of a tree, with the traits it carries. A back-end item which is never rendered is a
|
|
79
|
+
* CoreItem; use hasTrait to find out what else it has.
|
|
80
|
+
*/
|
|
81
|
+
export type CoreItem = CoreProperties & {
|
|
82
|
+
children: CoreItem[];
|
|
83
|
+
/** The parent item: an empty object for the root, null for an item which is not attached. */
|
|
84
|
+
parentItem: CoreItem | EmptyParent | null;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* An item with the render trait: the item treeloom mirrors onto a real element (render) and reads back from one
|
|
88
|
+
* (sync). Its children have the render trait too.
|
|
89
|
+
*/
|
|
90
|
+
export type DomItem = CoreProperties & WithTraits<'render'> & {
|
|
91
|
+
children: DomItem[];
|
|
92
|
+
parentItem: DomItem | EmptyParent | null;
|
|
93
|
+
appendChild(child: DomItem): DomItem;
|
|
94
|
+
removeChild(child: DomItem): DomItem[];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* What can be given to build an item: any of its properties (the children may be plain configs as well), plus any
|
|
98
|
+
* custom data. Whatever is left out gets its default.
|
|
99
|
+
*/
|
|
100
|
+
export type DomItemConfig = Partial<Omit<CoreProperties, 'appendChild' | 'removeChild'>> & Partial<RenderProperties> & {
|
|
101
|
+
children?: DomItemConfig[];
|
|
102
|
+
parentItem?: CoreItem | EmptyParent | null;
|
|
103
|
+
[custom: string]: unknown;
|
|
104
|
+
};
|
|
105
|
+
/** The extra properties of the root of a Virtual DOM. */
|
|
106
|
+
export type RootProperties = {
|
|
107
|
+
/** Registered listener functions, by name. */
|
|
108
|
+
eventActions: Record<string, ListenerFunction>;
|
|
109
|
+
/** Set with setForwardEvents to switch into render-only mode: every listener name resolves to a forwarder which
|
|
110
|
+
* sends this function an envelope instead of running local logic. See retrieveListener. */
|
|
111
|
+
forwardEvents?: ForwardEventsFunction;
|
|
112
|
+
head: DomItem;
|
|
113
|
+
body: DomItem;
|
|
114
|
+
};
|
|
115
|
+
/** The root of a Virtual DOM (the #document): the head and body items and the registered named listeners. */
|
|
116
|
+
export type DomItemRoot = DomItem & RootProperties;
|
|
117
|
+
/** What a trait is at runtime: which properties it puts on an item, and whether they belong in json. */
|
|
118
|
+
export type TraitDefinition = {
|
|
119
|
+
/** The properties the trait puts on an item. */
|
|
120
|
+
keys: string[];
|
|
121
|
+
/** False for properties which only make sense where the item lives (an element): they are left out of json. */
|
|
122
|
+
serializable?: boolean;
|
|
123
|
+
/** The data a new item gets when it is given the trait. */
|
|
124
|
+
defaults?: () => Record<string, unknown>;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Decides which items below (and including) an item are wanted. It receives the item being tested and everything
|
|
128
|
+
* gathered so far, and returns the gathered results with the item added if it qualifies.
|
|
129
|
+
*/
|
|
130
|
+
export type ChildTest = (item: DomItem, gatheredResults: DomItem[]) => DomItem[];
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DomItem } from '../../domItem/types';
|
|
2
|
+
import type { EventName, ListenerDescriptor } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Activate listener by pushing it to activeListeners.
|
|
5
|
+
* @param eventName
|
|
6
|
+
* @param eventListener
|
|
7
|
+
* @param item
|
|
8
|
+
*/
|
|
9
|
+
declare const activateListener: (eventName: EventName, eventListener: ListenerDescriptor, item: DomItem) => DomItem;
|
|
10
|
+
export default activateListener;
|
|
@@ -0,0 +1,45 @@
|
|
|
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 getTopParentItem_1 = __importDefault(require("../../domItem/tree/getTopParentItem"));
|
|
15
|
+
const makeEventHandler_1 = __importDefault(require("./makeEventHandler"));
|
|
16
|
+
const createEventResponder_1 = __importDefault(require("../objects/createEventResponder"));
|
|
17
|
+
const getListenerOptions_1 = __importDefault(require("../objects/options/getListenerOptions"));
|
|
18
|
+
const optionsToNumber_1 = __importDefault(require("../objects/options/optionsToNumber"));
|
|
19
|
+
const retrieveListener_1 = __importDefault(require("./retrieveListener"));
|
|
20
|
+
/**
|
|
21
|
+
* Activate listener by pushing it to activeListeners.
|
|
22
|
+
* @param eventName
|
|
23
|
+
* @param eventListener
|
|
24
|
+
* @param item
|
|
25
|
+
*/
|
|
26
|
+
const activateListener = (eventName, eventListener, item) => {
|
|
27
|
+
const listenerOptions = (0, getListenerOptions_1.default)();
|
|
28
|
+
if (typeof item.activeListeners === 'undefined') {
|
|
29
|
+
item.activeListeners = {};
|
|
30
|
+
}
|
|
31
|
+
if (!(eventName in item.activeListeners)) {
|
|
32
|
+
item.activeListeners[eventName] = {};
|
|
33
|
+
}
|
|
34
|
+
const optionIdentifier = (0, optionsToNumber_1.default)(listenerOptions, eventListener.listenerOptions);
|
|
35
|
+
if (!(optionIdentifier in item.activeListeners[eventName])) {
|
|
36
|
+
item.activeListeners[eventName][optionIdentifier] = [];
|
|
37
|
+
}
|
|
38
|
+
const listenerFunc = (0, retrieveListener_1.default)(eventListener.listenerFunc, (0, getTopParentItem_1.default)(item));
|
|
39
|
+
const eventHandler = (0, makeEventHandler_1.default)(listenerFunc, item, eventListener.listenerArgs);
|
|
40
|
+
const eventResponder = (0, createEventResponder_1.default)(eventHandler, !!(optionIdentifier & listenerOptions.signal));
|
|
41
|
+
item.activeListeners[eventName][optionIdentifier].push(eventResponder);
|
|
42
|
+
eventListener.activeResponder = eventResponder;
|
|
43
|
+
return item;
|
|
44
|
+
};
|
|
45
|
+
exports.default = activateListener;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const getTopParentItem_1=__importDefault(require("../../domItem/tree/getTopParentItem")),makeEventHandler_1=__importDefault(require("./makeEventHandler")),createEventResponder_1=__importDefault(require("../objects/createEventResponder")),getListenerOptions_1=__importDefault(require("../objects/options/getListenerOptions")),optionsToNumber_1=__importDefault(require("../objects/options/optionsToNumber")),retrieveListener_1=__importDefault(require("./retrieveListener")),activateListener=(e,t,r)=>{const i=(0,getListenerOptions_1.default)();void 0===r.activeListeners&&(r.activeListeners={}),e in r.activeListeners||(r.activeListeners[e]={});const n=(0,optionsToNumber_1.default)(i,t.listenerOptions);n in r.activeListeners[e]||(r.activeListeners[e][n]=[]);const s=(0,retrieveListener_1.default)(t.listenerFunc,(0,getTopParentItem_1.default)(r)),o=(0,makeEventHandler_1.default)(s,r,t.listenerArgs),a=(0,createEventResponder_1.default)(o,!!(n&i.signal));return r.activeListeners[e][n].push(a),t.activeResponder=a,r};exports.default=activateListener;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DomItem } from '../../domItem/types';
|
|
2
|
+
import type { EventName, ListenerFunction, ListenerOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Create an EventListener descriptor and push it onto a DomItem's eventListeners for the given event name.
|
|
5
|
+
* Does not attach anything to the real element - see {@link bindListeners} or {@link fullAddEventListener} for that.
|
|
6
|
+
*
|
|
7
|
+
* item is the last parameter (instead of customArgs/options having literal defaults) so this can be curried and
|
|
8
|
+
* piped directly - see {@link fullAddEventListener} for an example.
|
|
9
|
+
*
|
|
10
|
+
* Prefer calling this through {@link fullAddEventListener} with a registered name (see {@link registerListener}).
|
|
11
|
+
* Passing a raw function directly here works, but logs a console warning - see {@link EventListener}'s
|
|
12
|
+
* listenerFunc property for what that discretionary path gives up.
|
|
13
|
+
* @param eventName - The name of the trigger event (e.g. 'click').
|
|
14
|
+
* @param listenerFunction - Preferably a name registered via
|
|
15
|
+
* {@link registerListener}; a raw listener function is also accepted, at the caller's discretion.
|
|
16
|
+
* @param customArgs - Additional args passed through to the listener when called.
|
|
17
|
+
* @param options - Options to be used when the listener is attached
|
|
18
|
+
* to the element.
|
|
19
|
+
* @param item - The DomItem which will receive the event listener.
|
|
20
|
+
* @returns The same DomItem, with the new EventListener descriptor appended.
|
|
21
|
+
*/
|
|
22
|
+
declare const addEventListener: (eventName: EventName, listenerFunction: string | ListenerFunction, customArgs: object | null | undefined, options: ListenerOptions | null | undefined, item: DomItem) => DomItem;
|
|
23
|
+
export default addEventListener;
|