@zag-js/tree-view
Advanced tools
Comparing version 0.70.0 to 0.71.0
@@ -1,32 +0,11 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
'use strict'; | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
anatomy: () => anatomy, | ||
connect: () => connect, | ||
machine: () => machine | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var anatomy$1 = require('@zag-js/anatomy'); | ||
var domEvent = require('@zag-js/dom-event'); | ||
var domQuery = require('@zag-js/dom-query'); | ||
var core = require('@zag-js/core'); | ||
var utils = require('@zag-js/utils'); | ||
// src/tree-view.anatomy.ts | ||
var import_anatomy = require("@zag-js/anatomy"); | ||
var anatomy = (0, import_anatomy.createAnatomy)("tree-view").parts( | ||
var anatomy = anatomy$1.createAnatomy("tree-view").parts( | ||
"root", | ||
@@ -46,10 +25,3 @@ "label", | ||
var parts = anatomy.build(); | ||
// src/tree-view.connect.ts | ||
var import_dom_event = require("@zag-js/dom-event"); | ||
var import_dom_query2 = require("@zag-js/dom-query"); | ||
// src/tree-view.dom.ts | ||
var import_dom_query = require("@zag-js/dom-query"); | ||
var dom = (0, import_dom_query.createScope)({ | ||
var dom = domQuery.createScope({ | ||
getRootId: (ctx) => ctx.ids?.root ?? `tree-root:${ctx.id}`, | ||
@@ -59,3 +31,3 @@ getLabelId: (ctx) => ctx.ids?.label ?? `tree-label:${ctx.id}`, | ||
getNodeId(node) { | ||
if (!(0, import_dom_query.isHTMLElement)(node)) return null; | ||
if (!domQuery.isHTMLElement(node)) return null; | ||
return node.dataset.branch ?? node.dataset.item ?? null; | ||
@@ -66,3 +38,3 @@ }, | ||
if (node?.dataset.part === "branch") { | ||
return (0, import_dom_query.query)(node, "[data-part=branch-control]"); | ||
return domQuery.query(node, "[data-part=branch-control]"); | ||
} | ||
@@ -76,11 +48,11 @@ return node; | ||
const selector = `[role=treeitem][data-branch="${id}"]`; | ||
return (0, import_dom_query.query)(dom.getTreeEl(ctx), selector); | ||
return domQuery.query(dom.getTreeEl(ctx), selector); | ||
}, | ||
getItemEl(ctx, id) { | ||
const selector = `[role=treeitem][data-item="${id}"]`; | ||
return (0, import_dom_query.query)(dom.getTreeEl(ctx), selector); | ||
return domQuery.query(dom.getTreeEl(ctx), selector); | ||
}, | ||
getBranchControlEl(ctx, id) { | ||
const selector = "[data-part=branch-control]"; | ||
return (0, import_dom_query.query)(dom.getBranchEl(ctx, id), selector); | ||
return domQuery.query(dom.getBranchEl(ctx, id), selector); | ||
}, | ||
@@ -92,3 +64,3 @@ getFocusedEl(ctx) { | ||
focusNode(node, options) { | ||
if ((0, import_dom_query.isHTMLElement)(node)) node.focus(options); | ||
if (domQuery.isHTMLElement(node)) node.focus(options); | ||
}, | ||
@@ -105,3 +77,3 @@ getNodeDepth(node) { | ||
acceptNode(node) { | ||
if (skipHidden && (0, import_dom_query.isHiddenElement)(node)) { | ||
if (skipHidden && domQuery.isHiddenElement(node)) { | ||
return NodeFilter.FILTER_REJECT; | ||
@@ -124,6 +96,6 @@ } | ||
while (node) { | ||
if ((0, import_dom_query.isHTMLElement)(node)) elements.push(node); | ||
if (domQuery.isHTMLElement(node)) elements.push(node); | ||
node = walker.nextNode(); | ||
} | ||
return (0, import_dom_query.getByTypeahead)(elements, { | ||
return domQuery.getByTypeahead(elements, { | ||
state: ctx.typeaheadState, | ||
@@ -140,3 +112,3 @@ key, | ||
while (node) { | ||
if ((0, import_dom_query.isHTMLElement)(node)) { | ||
if (domQuery.isHTMLElement(node)) { | ||
nodes.push(node); | ||
@@ -150,3 +122,3 @@ } | ||
if (depth === -1) return []; | ||
return (0, import_dom_query.queryAll)(dom.getTreeEl(ctx), `[role=treeitem][data-part=branch][data-depth="${depth}"]`); | ||
return domQuery.queryAll(dom.getTreeEl(ctx), `[role=treeitem][data-part=branch][data-depth="${depth}"]`); | ||
}, | ||
@@ -277,5 +249,5 @@ getNodesInRange(nodes, startNode, endNode) { | ||
if (event.defaultPrevented) return; | ||
if ((0, import_dom_query2.isComposingEvent)(event)) return; | ||
const target = (0, import_dom_query2.getEventTarget)(event); | ||
if ((0, import_dom_query2.isEditableElement)(target)) return; | ||
if (domQuery.isComposingEvent(event)) return; | ||
const target = domQuery.getEventTarget(event); | ||
if (domQuery.isEditableElement(target)) return; | ||
const node = target?.closest("[role=treeitem]"); | ||
@@ -291,3 +263,3 @@ if (!node) return; | ||
ArrowDown(event2) { | ||
if ((0, import_dom_event.isModifierKey)(event2)) return; | ||
if (domEvent.isModifierKey(event2)) return; | ||
event2.preventDefault(); | ||
@@ -297,3 +269,3 @@ send({ type: "ITEM.ARROW_DOWN", id: nodeId, shiftKey: event2.shiftKey }); | ||
ArrowUp(event2) { | ||
if ((0, import_dom_event.isModifierKey)(event2)) return; | ||
if (domEvent.isModifierKey(event2)) return; | ||
event2.preventDefault(); | ||
@@ -303,3 +275,3 @@ send({ type: "ITEM.ARROW_UP", id: nodeId, shiftKey: event2.shiftKey }); | ||
ArrowLeft(event2) { | ||
if ((0, import_dom_event.isModifierKey)(event2) || node.dataset.disabled) return; | ||
if (domEvent.isModifierKey(event2) || node.dataset.disabled) return; | ||
event2.preventDefault(); | ||
@@ -314,3 +286,3 @@ send({ type: isBranchNode ? "BRANCH.ARROW_LEFT" : "ITEM.ARROW_LEFT", id: nodeId }); | ||
Home(event2) { | ||
if ((0, import_dom_event.isModifierKey)(event2)) return; | ||
if (domEvent.isModifierKey(event2)) return; | ||
event2.preventDefault(); | ||
@@ -320,3 +292,3 @@ send({ type: "ITEM.HOME", id: nodeId, shiftKey: event2.shiftKey }); | ||
End(event2) { | ||
if ((0, import_dom_event.isModifierKey)(event2)) return; | ||
if (domEvent.isModifierKey(event2)) return; | ||
event2.preventDefault(); | ||
@@ -350,3 +322,3 @@ send({ type: "ITEM.END", id: nodeId, shiftKey: event2.shiftKey }); | ||
}; | ||
const key = (0, import_dom_event.getEventKey)(event, state.context); | ||
const key = domEvent.getEventKey(event, state.context); | ||
const exec = keyMap[key]; | ||
@@ -358,3 +330,3 @@ if (exec) { | ||
if (!state.context.typeahead) return; | ||
const isValidTypeahead = event.key.length === 1 && !(0, import_dom_event.isModifierKey)(event); | ||
const isValidTypeahead = event.key.length === 1 && !domEvent.isModifierKey(event); | ||
if (!isValidTypeahead) return; | ||
@@ -365,3 +337,3 @@ send({ type: "TREE.TYPEAHEAD", key: event.key, id: nodeId }); | ||
onBlur(event) { | ||
if ((0, import_dom_query2.contains)(event.currentTarget, event.relatedTarget)) return; | ||
if (domQuery.contains(event.currentTarget, event.relatedTarget)) return; | ||
send({ type: "TREE.BLUR" }); | ||
@@ -380,9 +352,9 @@ } | ||
tabIndex: itemState.focused ? 0 : -1, | ||
"data-focus": (0, import_dom_query2.dataAttr)(itemState.focused), | ||
"data-focus": domQuery.dataAttr(itemState.focused), | ||
role: "treeitem", | ||
"aria-current": itemState.selected ? "true" : void 0, | ||
"aria-selected": itemState.disabled ? void 0 : itemState.selected, | ||
"data-selected": (0, import_dom_query2.dataAttr)(itemState.selected), | ||
"data-selected": domQuery.dataAttr(itemState.selected), | ||
"aria-disabled": itemState.disabled, | ||
"data-disabled": (0, import_dom_query2.dataAttr)(itemState.disabled), | ||
"data-disabled": domQuery.dataAttr(itemState.disabled), | ||
"aria-level": props.depth, | ||
@@ -411,5 +383,5 @@ "data-depth": props.depth, | ||
...parts.itemText.attrs, | ||
"data-disabled": (0, import_dom_query2.dataAttr)(itemState.disabled), | ||
"data-selected": (0, import_dom_query2.dataAttr)(itemState.selected), | ||
"data-focus": (0, import_dom_query2.dataAttr)(itemState.focused) | ||
"data-disabled": domQuery.dataAttr(itemState.disabled), | ||
"data-selected": domQuery.dataAttr(itemState.selected), | ||
"data-focus": domQuery.dataAttr(itemState.focused) | ||
}); | ||
@@ -422,5 +394,5 @@ }, | ||
"aria-hidden": true, | ||
"data-disabled": (0, import_dom_query2.dataAttr)(itemState.disabled), | ||
"data-selected": (0, import_dom_query2.dataAttr)(itemState.selected), | ||
"data-focus": (0, import_dom_query2.dataAttr)(itemState.focused), | ||
"data-disabled": domQuery.dataAttr(itemState.disabled), | ||
"data-selected": domQuery.dataAttr(itemState.selected), | ||
"data-focus": domQuery.dataAttr(itemState.focused), | ||
hidden: !itemState.selected | ||
@@ -441,7 +413,7 @@ }); | ||
"aria-selected": branchState.disabled ? void 0 : branchState.selected, | ||
"data-selected": (0, import_dom_query2.dataAttr)(branchState.selected), | ||
"data-selected": domQuery.dataAttr(branchState.selected), | ||
"aria-expanded": branchState.expanded, | ||
"data-state": branchState.expanded ? "open" : "closed", | ||
"aria-disabled": branchState.disabled, | ||
"data-disabled": (0, import_dom_query2.dataAttr)(branchState.disabled), | ||
"data-disabled": domQuery.dataAttr(branchState.disabled), | ||
style: { | ||
@@ -458,5 +430,5 @@ "--depth": props.depth | ||
"data-state": branchState.expanded ? "open" : "closed", | ||
"data-disabled": (0, import_dom_query2.dataAttr)(branchState.disabled), | ||
"data-selected": (0, import_dom_query2.dataAttr)(branchState.selected), | ||
"data-focus": (0, import_dom_query2.dataAttr)(branchState.focused) | ||
"data-disabled": domQuery.dataAttr(branchState.disabled), | ||
"data-selected": domQuery.dataAttr(branchState.selected), | ||
"data-focus": domQuery.dataAttr(branchState.focused) | ||
}); | ||
@@ -470,3 +442,3 @@ }, | ||
dir: state.context.dir, | ||
"data-disabled": (0, import_dom_query2.dataAttr)(branchState.disabled), | ||
"data-disabled": domQuery.dataAttr(branchState.disabled), | ||
"data-state": branchState.expanded ? "open" : "closed", | ||
@@ -488,4 +460,4 @@ onClick(event) { | ||
"data-state": branchState.expanded ? "open" : "closed", | ||
"data-disabled": (0, import_dom_query2.dataAttr)(branchState.disabled), | ||
"data-selected": (0, import_dom_query2.dataAttr)(branchState.selected), | ||
"data-disabled": domQuery.dataAttr(branchState.disabled), | ||
"data-selected": domQuery.dataAttr(branchState.selected), | ||
"data-branch": branchState.value, | ||
@@ -511,3 +483,3 @@ "data-depth": props.depth, | ||
"data-branch": branchState.value, | ||
"data-disabled": (0, import_dom_query2.dataAttr)(branchState.disabled), | ||
"data-disabled": domQuery.dataAttr(branchState.disabled), | ||
"data-state": branchState.expanded ? "open" : "closed" | ||
@@ -529,11 +501,6 @@ }); | ||
} | ||
// src/tree-view.machine.ts | ||
var import_core = require("@zag-js/core"); | ||
var import_dom_query3 = require("@zag-js/dom-query"); | ||
var import_utils = require("@zag-js/utils"); | ||
var { and } = import_core.guards; | ||
var { and } = core.guards; | ||
function machine(userContext) { | ||
const ctx = (0, import_utils.compact)(userContext); | ||
return (0, import_core.createMachine)( | ||
const ctx = utils.compact(userContext); | ||
return core.createMachine( | ||
{ | ||
@@ -550,3 +517,3 @@ id: "tree-view", | ||
...ctx, | ||
typeaheadState: import_dom_query3.getByTypeahead.defaultOptions | ||
typeaheadState: domQuery.getByTypeahead.defaultOptions | ||
}, | ||
@@ -702,6 +669,6 @@ computed: { | ||
const treeEl = dom.getTreeEl(ctx2); | ||
return (0, import_dom_query3.observeChildren)(treeEl, { | ||
return domQuery.observeChildren(treeEl, { | ||
callback(records) { | ||
const removedNodes = records.flatMap((r) => Array.from(r.removedNodes)).filter((node) => { | ||
if (!(0, import_dom_query3.isHTMLElement)(node)) return false; | ||
if (!domQuery.isHTMLElement(node)) return false; | ||
return node.matches("[role=treeitem]") || node.matches("[role=group]"); | ||
@@ -712,5 +679,5 @@ }); | ||
records.forEach((record) => { | ||
if ((0, import_dom_query3.isHTMLElement)(record.nextSibling)) { | ||
if (domQuery.isHTMLElement(record.nextSibling)) { | ||
elementToFocus = record.nextSibling; | ||
} else if ((0, import_dom_query3.isHTMLElement)(record.previousSibling)) { | ||
} else if (domQuery.isHTMLElement(record.previousSibling)) { | ||
elementToFocus = record.previousSibling; | ||
@@ -725,3 +692,3 @@ } | ||
const nodeId = dom.getNodeId(node); | ||
if ((0, import_dom_query3.isHTMLElement)(node) && nodeId != null) { | ||
if (domQuery.isHTMLElement(node) && nodeId != null) { | ||
removedIds.add(nodeId); | ||
@@ -747,3 +714,3 @@ } | ||
const firstItem = walker.firstChild(); | ||
if (!(0, import_dom_query3.isHTMLElement)(firstItem)) return; | ||
if (!domQuery.isHTMLElement(firstItem)) return; | ||
ctx2.focusedValue = dom.getNodeId(firstItem); | ||
@@ -843,3 +810,3 @@ }, | ||
const nodeId = dom.getNodeId(node); | ||
if ((0, import_dom_query3.isHTMLElement)(node) && nodeId != null) { | ||
if (domQuery.isHTMLElement(node) && nodeId != null) { | ||
nextSet.add(nodeId); | ||
@@ -873,3 +840,3 @@ } | ||
const nodeId = dom.getNodeId(node); | ||
if ((0, import_dom_query3.isHTMLElement)(node) && node.dataset.part === "branch-control" && nodeId != null) { | ||
if (domQuery.isHTMLElement(node) && node.dataset.part === "branch-control" && nodeId != null) { | ||
nextSet.add(nodeId); | ||
@@ -985,8 +952,5 @@ } | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
anatomy, | ||
connect, | ||
machine | ||
}); | ||
//# sourceMappingURL=index.js.map | ||
exports.anatomy = anatomy; | ||
exports.connect = connect; | ||
exports.machine = machine; |
{ | ||
"name": "@zag-js/tree-view", | ||
"version": "0.70.0", | ||
"version": "0.71.0", | ||
"description": "Core logic for the tree-view widget implemented as a state machine", | ||
@@ -21,4 +21,3 @@ "keywords": [ | ||
"files": [ | ||
"dist", | ||
"src" | ||
"dist" | ||
], | ||
@@ -32,8 +31,8 @@ "publishConfig": { | ||
"dependencies": { | ||
"@zag-js/anatomy": "0.70.0", | ||
"@zag-js/core": "0.70.0", | ||
"@zag-js/dom-query": "0.70.0", | ||
"@zag-js/dom-event": "0.70.0", | ||
"@zag-js/utils": "0.70.0", | ||
"@zag-js/types": "0.70.0" | ||
"@zag-js/anatomy": "0.71.0", | ||
"@zag-js/core": "0.71.0", | ||
"@zag-js/dom-query": "0.71.0", | ||
"@zag-js/dom-event": "0.71.0", | ||
"@zag-js/utils": "0.71.0", | ||
"@zag-js/types": "0.71.0" | ||
}, | ||
@@ -40,0 +39,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80464
7
2016
+ Added@zag-js/anatomy@0.71.0(transitive)
+ Added@zag-js/core@0.71.0(transitive)
+ Added@zag-js/dom-event@0.71.0(transitive)
+ Added@zag-js/dom-query@0.71.0(transitive)
+ Added@zag-js/store@0.71.0(transitive)
+ Added@zag-js/text-selection@0.71.0(transitive)
+ Added@zag-js/types@0.71.0(transitive)
+ Added@zag-js/utils@0.71.0(transitive)
- Removed@zag-js/anatomy@0.70.0(transitive)
- Removed@zag-js/core@0.70.0(transitive)
- Removed@zag-js/dom-event@0.70.0(transitive)
- Removed@zag-js/dom-query@0.70.0(transitive)
- Removed@zag-js/store@0.70.0(transitive)
- Removed@zag-js/text-selection@0.70.0(transitive)
- Removed@zag-js/types@0.70.0(transitive)
- Removed@zag-js/utils@0.70.0(transitive)
Updated@zag-js/anatomy@0.71.0
Updated@zag-js/core@0.71.0
Updated@zag-js/dom-event@0.71.0
Updated@zag-js/dom-query@0.71.0
Updated@zag-js/types@0.71.0
Updated@zag-js/utils@0.71.0