@sectile/core 0.11.1 → 0.12.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/dist/internal/composites/linear-action.js +1 -1
- package/dist/internal/composites/linear-action.js.map +1 -1
- package/dist/internal/composites/linear-choice.js +1 -1
- package/dist/internal/composites/linear-choice.js.map +1 -1
- package/dist/internal/composites/listbox.js +1 -1
- package/dist/internal/composites/listbox.js.map +1 -1
- package/dist/internal/composites/tree-grid.js +1 -1
- package/dist/internal/composites/tree-grid.js.map +1 -1
- package/dist/internal/composites/tree-view.js +1 -1
- package/dist/internal/composites/tree-view.js.map +1 -1
- package/dist/internal/kernel/foundation.d.ts +2 -1
- package/dist/internal/kernel/foundation.js +1 -1
- package/dist/internal/kernel/foundation.js.map +1 -1
- package/dist/internal/kernel/indexed-sequence.d.ts +2 -0
- package/dist/internal/kernel/indexed-sequence.js +1 -1
- package/dist/internal/kernel/indexed-sequence.js.map +1 -1
- package/dist/shared.d.ts +1 -1
- package/dist/structures/sequence.js +1 -1
- package/dist/structures/sequence.js.map +1 -1
- package/dist/units.d.ts +4 -4
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{unwrap}from"../../result.js";import{bindCanonicalState,fail,hasCanonicalState,ok}from"../kernel/foundation.js";import{findEligibleFromEdge}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";function createLinearActionState(domain,input={}){return unwrap(tryCreateLinearActionState(domain,input))}function tryCreateLinearActionState(domain,input={}){const current=input.current??null;if(current!==null&&!domain.contains(current)){return fail("construction","linear-action-cursor-outside-domain","Linear action cursor must exist in the sequence domain.",{current})}return ok(linearActionState(domain,current))}function applyLinearActionEvent(domain,state,event,policies={}){const stateError=hasCanonicalState(domain,state)?null:validateState(domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isLinearActionEvent(event)){return fail("transition-rejection","invalid-linear-action-event","Linear action event is not part of the accepted vocabulary.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap"){return fail("transition-rejection","invalid-linear-action-boundary","Linear action boundary must be stop or wrap.",{boundary})}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Linear action eligibility policy must be a function.")}if(typeof event==="object"){if(!domain.contains(event.id)||policies.eligible?.(event.id)===false){return fail("transition-rejection","linear-action-target-unavailable","Direct linear action events require an eligible identity in the domain.",{id:event.id})}return event.type==="focus"?focus(domain,event.id):invoke(domain,state,event.id,true)}if(event==="invoke"){return state.cursor.current===null?fail("transition-rejection","no-cursor","Linear action invocation requires a cursor."):invoke(domain,state,state.cursor.current,false)}const direction=event==="next"||event==="first"?1:-1;const eligible=policies.eligible??(()=>true);let target;if(event==="first"||event==="last"||state.cursor.current===null){const edge=findEligibleFromEdge(domain,direction,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!edge.ok)return edge;target=edge.value}else{const movement=domain.move(state.cursor.current,direction,boundary,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}return target===null?createMachineUpdate(state):focus(domain,target)}function focus(domain,id){return createMachineUpdate(linearActionState(domain,id),[{type:"focus",id}])}function invoke(domain,state,id,direct){const commands=[];if(direct&&state.cursor.current!==id)commands.push({type:"focus",id});commands.push({type:"invoke",id});return createMachineUpdate(linearActionState(domain,id),commands)}function linearActionState(domain,current){return bindCanonicalState(domain,Object.freeze({cursor:createCursorState(current)}))}function validateState(domain,state){return state.cursor.current===null||domain.contains(state.cursor.current)?null:{class:"transition-rejection",code:"linear-action-cursor-outside-domain",message:"Linear action cursor must exist in the sequence domain."}}function isLinearActionEvent(value){if(typeof value==="string"){return value==="next"||value==="previous"||value==="first"||value==="last"||value==="invoke"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&
|
|
1
|
+
import{unwrap}from"../../result.js";import{bindCanonicalState,fail,hasCanonicalState,isStableID,ok}from"../kernel/foundation.js";import{findEligibleFromEdge}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";function createLinearActionState(domain,input={}){return unwrap(tryCreateLinearActionState(domain,input))}function tryCreateLinearActionState(domain,input={}){const current=input.current??null;if(current!==null&&!domain.contains(current)){return fail("construction","linear-action-cursor-outside-domain","Linear action cursor must exist in the sequence domain.",{current})}return ok(linearActionState(domain,current))}function applyLinearActionEvent(domain,state,event,policies={}){const stateError=hasCanonicalState(domain,state)?null:validateState(domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isLinearActionEvent(event)){return fail("transition-rejection","invalid-linear-action-event","Linear action event is not part of the accepted vocabulary.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap"){return fail("transition-rejection","invalid-linear-action-boundary","Linear action boundary must be stop or wrap.",{boundary})}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Linear action eligibility policy must be a function.")}if(typeof event==="object"){if(!domain.contains(event.id)||policies.eligible?.(event.id)===false){return fail("transition-rejection","linear-action-target-unavailable","Direct linear action events require an eligible identity in the domain.",{id:event.id})}return event.type==="focus"?focus(domain,event.id):invoke(domain,state,event.id,true)}if(event==="invoke"){return state.cursor.current===null?fail("transition-rejection","no-cursor","Linear action invocation requires a cursor."):invoke(domain,state,state.cursor.current,false)}const direction=event==="next"||event==="first"?1:-1;const eligible=policies.eligible??(()=>true);let target;if(event==="first"||event==="last"||state.cursor.current===null){const edge=findEligibleFromEdge(domain,direction,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!edge.ok)return edge;target=edge.value}else{const movement=domain.move(state.cursor.current,direction,boundary,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}return target===null?createMachineUpdate(state):focus(domain,target)}function focus(domain,id){return createMachineUpdate(linearActionState(domain,id),[{type:"focus",id}])}function invoke(domain,state,id,direct){const commands=[];if(direct&&state.cursor.current!==id)commands.push({type:"focus",id});commands.push({type:"invoke",id});return createMachineUpdate(linearActionState(domain,id),commands)}function linearActionState(domain,current){return bindCanonicalState(domain,Object.freeze({cursor:createCursorState(current)}))}function validateState(domain,state){return state.cursor.current===null||domain.contains(state.cursor.current)?null:{class:"transition-rejection",code:"linear-action-cursor-outside-domain",message:"Linear action cursor must exist in the sequence domain."}}function isLinearActionEvent(value){if(typeof value==="string"){return value==="next"||value==="previous"||value==="first"||value==="last"||value==="invoke"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&isStableID(value.id)&&(value.type==="focus"||value.type==="invoke")}export{applyLinearActionEvent,createLinearActionState,tryCreateLinearActionState};
|
|
2
2
|
//# sourceMappingURL=linear-action.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/composites/linear-action.ts"],"mappings":"AAAA,OAAS,WAAc,kBAGvB,OAAS,mBAAoB,KAAM,kBAAmB,OAAU,
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/composites/linear-action.ts"],"mappings":"AAAA,OAAS,WAAc,kBAGvB,OAAS,mBAAoB,KAAM,kBAAmB,WAAY,OAAU,0BAC5E,OAAS,yBAA4B,gCACrC,OAAS,wBAA2B,uBACpC,OAAS,sBAA2C,qBAkC9C,SAAU,wBACd,OACA,MAAoC,CAAA,EAAE,CAEtC,OAAO,OAAO,2BAA2B,OAAQ,KAAK,CAAC,CACzD,CAEM,SAAU,2BACd,OACA,MAAoC,CAAA,EAAE,CAEtC,MAAM,QAAU,MAAM,SAAW,KACjC,GAAI,UAAY,MAAQ,CAAC,OAAO,SAAS,OAAO,EAAG,CACjD,OAAO,KACL,eACA,sCACA,0DACA,CAAE,OAAO,CAAE,CAEf,CACA,OAAO,GAAG,kBAAkB,OAAQ,OAA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,SAAU,OAAS,OAAQ,OAAS,WAAW,MAAM,EAAE,IACtD,MAAM,OAAS,SAAW,MAAM,OAAS,SACjD","names":[],"file":"linear-action.js"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{bindCanonicalState,fail,hasCanonicalState,ok}from"../kernel/foundation.js";import{findEligibleFromEdge}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";import{createSelectionState,selectOne}from"../state/selection.js";function createLinearChoiceState(domain,input={}){const current=input.current??null;if(current!==null&&!domain.contains(current)){return fail("construction","linear-choice-cursor-outside-domain","Linear choice cursor must exist in the sequence domain.",{current})}const selection=createSelectionState(domain,"single",input);if(!selection.ok)return selection;return ok(linearChoiceState(domain,createCursorState(current),selection.value))}function applyLinearChoiceEvent(domain,state,event,policies={}){const stateError=hasCanonicalState(domain,state)?null:validateLinearChoiceState(domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isLinearChoiceEvent(event)){return fail("transition-rejection","invalid-linear-choice-event","Linear choice event is not part of the accepted vocabulary.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap"){return fail("transition-rejection","invalid-linear-choice-boundary","Linear choice boundary must be stop or wrap.",{boundary})}const follows=policies.selectionFollowsFocus??false;if(typeof follows!=="boolean"){return fail("transition-rejection","invalid-selection-follows-focus","selectionFollowsFocus must be boolean.")}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Linear choice eligibility policy must be a function.")}if(typeof event==="object"){if(!isAvailable(domain,event.id,policies))return unavailable(event.id);if(event.type==="focus"){return focusTarget(domain,state,event.id,follows)}return chooseTarget(domain,state,event.id,event.type==="activate")}if(event==="next"||event==="previous"||event==="first"||event==="last"){return moveLinearChoice(domain,state,event,boundary,follows,policies)}const current=state.cursor.current;if(current===null){return fail("transition-rejection","no-cursor","Linear choice selection requires a cursor.")}return chooseTarget(domain,state,current,event==="activate",false)}function moveLinearChoice(domain,state,event,boundary,follows,policies){const direction=event==="next"||event==="first"?1:-1;const eligible=policies.eligible??(()=>true);let target;if(event==="first"||event==="last"||state.cursor.current===null){const edge=findEligibleFromEdge(domain,direction,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!edge.ok)return edge;target=edge.value}else{const movement=domain.move(state.cursor.current,direction,boundary,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}return target===null?createMachineUpdate(state):focusTarget(domain,state,target,follows)}function focusTarget(domain,state,id,follows){const selection=follows?selectOne(state.selection,id,domain):state.selection;return createMachineUpdate(linearChoiceState(domain,createCursorState(id),selection),[{type:"focus",id}])}function chooseTarget(domain,state,id,activate,focus=true){const commands=[];if(focus&&state.cursor.current!==id)commands.push({type:"focus",id});if(activate)commands.push({type:"activate",id});return createMachineUpdate(linearChoiceState(domain,createCursorState(id),selectOne(state.selection,id,domain)),commands)}function validateLinearChoiceState(domain,state){if(state.cursor.current!==null&&!domain.contains(state.cursor.current)){return{class:"transition-rejection",code:"linear-choice-cursor-outside-domain",message:"Linear choice cursor must exist in the sequence domain."}}if(state.selection.size>1||state.selection.selected.length!==state.selection.size){return{class:"transition-rejection",code:"invalid-linear-choice-selection",message:"Linear choice selection must contain at most one identity."}}for(const id of state.selection.selected){if(!domain.contains(id)||!state.selection.has(id)){return{class:"transition-rejection",code:"linear-choice-selection-outside-domain",message:"Linear choice selection must agree with the sequence domain."}}}if(state.selection.anchor!==null&&!domain.contains(state.selection.anchor)){return{class:"transition-rejection",code:"linear-choice-anchor-outside-domain",message:"Linear choice anchor must exist in the sequence domain."}}return null}function linearChoiceState(domain,cursor,selection){return bindCanonicalState(domain,Object.freeze({cursor,selection}))}function isAvailable(domain,id,policies){return domain.contains(id)&&policies.eligible?.(id)!==false}function unavailable(id){return fail("transition-rejection","linear-choice-target-unavailable","Direct linear choice events require an eligible identity in the domain.",{id})}function isLinearChoiceEvent(value){if(typeof value==="string"){return value==="next"||value==="previous"||value==="first"||value==="last"||value==="select"||value==="activate"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&
|
|
1
|
+
import{bindCanonicalState,fail,hasCanonicalState,isStableID,ok}from"../kernel/foundation.js";import{findEligibleFromEdge}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";import{createSelectionState,selectOne}from"../state/selection.js";function createLinearChoiceState(domain,input={}){const current=input.current??null;if(current!==null&&!domain.contains(current)){return fail("construction","linear-choice-cursor-outside-domain","Linear choice cursor must exist in the sequence domain.",{current})}const selection=createSelectionState(domain,"single",input);if(!selection.ok)return selection;return ok(linearChoiceState(domain,createCursorState(current),selection.value))}function applyLinearChoiceEvent(domain,state,event,policies={}){const stateError=hasCanonicalState(domain,state)?null:validateLinearChoiceState(domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isLinearChoiceEvent(event)){return fail("transition-rejection","invalid-linear-choice-event","Linear choice event is not part of the accepted vocabulary.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap"){return fail("transition-rejection","invalid-linear-choice-boundary","Linear choice boundary must be stop or wrap.",{boundary})}const follows=policies.selectionFollowsFocus??false;if(typeof follows!=="boolean"){return fail("transition-rejection","invalid-selection-follows-focus","selectionFollowsFocus must be boolean.")}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Linear choice eligibility policy must be a function.")}if(typeof event==="object"){if(!isAvailable(domain,event.id,policies))return unavailable(event.id);if(event.type==="focus"){return focusTarget(domain,state,event.id,follows)}return chooseTarget(domain,state,event.id,event.type==="activate")}if(event==="next"||event==="previous"||event==="first"||event==="last"){return moveLinearChoice(domain,state,event,boundary,follows,policies)}const current=state.cursor.current;if(current===null){return fail("transition-rejection","no-cursor","Linear choice selection requires a cursor.")}return chooseTarget(domain,state,current,event==="activate",false)}function moveLinearChoice(domain,state,event,boundary,follows,policies){const direction=event==="next"||event==="first"?1:-1;const eligible=policies.eligible??(()=>true);let target;if(event==="first"||event==="last"||state.cursor.current===null){const edge=findEligibleFromEdge(domain,direction,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!edge.ok)return edge;target=edge.value}else{const movement=domain.move(state.cursor.current,direction,boundary,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}return target===null?createMachineUpdate(state):focusTarget(domain,state,target,follows)}function focusTarget(domain,state,id,follows){const selection=follows?selectOne(state.selection,id,domain):state.selection;return createMachineUpdate(linearChoiceState(domain,createCursorState(id),selection),[{type:"focus",id}])}function chooseTarget(domain,state,id,activate,focus=true){const commands=[];if(focus&&state.cursor.current!==id)commands.push({type:"focus",id});if(activate)commands.push({type:"activate",id});return createMachineUpdate(linearChoiceState(domain,createCursorState(id),selectOne(state.selection,id,domain)),commands)}function validateLinearChoiceState(domain,state){if(state.cursor.current!==null&&!domain.contains(state.cursor.current)){return{class:"transition-rejection",code:"linear-choice-cursor-outside-domain",message:"Linear choice cursor must exist in the sequence domain."}}if(state.selection.size>1||state.selection.selected.length!==state.selection.size){return{class:"transition-rejection",code:"invalid-linear-choice-selection",message:"Linear choice selection must contain at most one identity."}}for(const id of state.selection.selected){if(!domain.contains(id)||!state.selection.has(id)){return{class:"transition-rejection",code:"linear-choice-selection-outside-domain",message:"Linear choice selection must agree with the sequence domain."}}}if(state.selection.anchor!==null&&!domain.contains(state.selection.anchor)){return{class:"transition-rejection",code:"linear-choice-anchor-outside-domain",message:"Linear choice anchor must exist in the sequence domain."}}return null}function linearChoiceState(domain,cursor,selection){return bindCanonicalState(domain,Object.freeze({cursor,selection}))}function isAvailable(domain,id,policies){return domain.contains(id)&&policies.eligible?.(id)!==false}function unavailable(id){return fail("transition-rejection","linear-choice-target-unavailable","Direct linear choice events require an eligible identity in the domain.",{id})}function isLinearChoiceEvent(value){if(typeof value==="string"){return value==="next"||value==="previous"||value==="first"||value==="last"||value==="select"||value==="activate"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&isStableID(value.id)&&(value.type==="focus"||value.type==="select"||value.type==="activate")}export{applyLinearChoiceEvent,createLinearChoiceState};
|
|
2
2
|
//# sourceMappingURL=linear-choice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/composites/linear-choice.ts"],"mappings":"AAEA,OAAS,mBAAoB,KAAM,kBAAmB,OAAU,
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/composites/linear-choice.ts"],"mappings":"AAEA,OAAS,mBAAoB,KAAM,kBAAmB,WAAY,OAAU,0BAC5E,OAAS,yBAA4B,gCACrC,OAAS,wBAA2B,uBACpC,OAAS,sBAA2C,qBACpD,OACE,qBACA,cAGK,wBAuCD,SAAU,wBACd,OACA,MAAoC,CAAA,EAAE,CAEtC,MAAM,QAAU,MAAM,SAAW,KACjC,GAAI,UAAY,MAAQ,CAAC,OAAO,SAAS,OAAO,EAAG,CACjD,OAAO,KACL,eACA,sCACA,0DACA,CAAE,OAAO,CAAE,CAEf,CACA,MAAM,UAAY,qBAAqB,OAAQ,SAAU,KAAK,EAC9D,GAAI,CAAC,UAAU,GAAI,OAAO,UAC1B,OAAO,GAAG,kBAAkB,OAAQ,kBAAkB,OAAO,EAAG,UAAU,KAAK,CAAC,CAClF,CAEM,SAAU,uBACd,OACA,MACA,MACA,SAAqC,CAAA,EAAE,CAEvC,MAAM,WAAa,kBAAkB,OAAQ,KAAK,EAC9C,KACA,0BAA0B,OAAQ,KAAK,EAC3C,GAAI,aAAe,KAAM,MAAO,CAAE,GAAI,MAAO,MAAO,UAAU,EAC9D,GAAI,CAAC,oBAAoB,KAAK,EAAG,CAC/B,OAAO,KACL,uBACA,8BACA,8DACA,CAAE,KAAK,CAAE,CAEb,CACA,MAAM,SAAW,SAAS,UAAY,OACtC,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U,CACzC,GAAI,CAAC,OAAO,SAAS,EAAE,GAAK,CAAC,MAAM,UAAU,IAAI,EAAE,EAAG,CACpD,MAAO,CACL,MAAO,uBACP,KAAM,yCACN,QAAS,+DAEb,CACF,CACA,GAAI,MAAM,UAAU,SAAW,MAAQ,CAAC,OAAO,SAAS,MAAM,UAAU,MAAM,EAAG,CAC/E,MAAO,CACL,MAAO,uBACP,KAAM,sCACN,QAAS,0DAEb,CACA,OAAO,IACT,CAEA,SAAS,kBACP,OACA,OACA,UAA6B,CAE7B,OAAO,mBAAmB,OAAQ,OAAO,OAAO,CAAE,OAAQ,SAAS,CAAE,CAAC,CACxE,CAEA,SAAS,YACP,OACA,GACA,SAAkC,CAElC,OAAO,OAAO,SAAS,EAAE,GAAK,SAAS,WAAW,EAAE,IAAM,KAC5D,CAEA,SAAS,YAAiC,GAAM,CAC9C,OAAO,KACL,uBACA,mCACA,0EACA,CAAE,EAAE,CAAE,CAEV,CAEA,SAAS,oBAAoB,MAAc,CACzC,GAAI,OAAO,QAAU,SAAU,CAC7B,OAAO,QAAU,QACZ,QAAU,YACV,QAAU,SACV,QAAU,QACV,QAAU,UACV,QAAU,UACjB,CACA,OAAO,OAAO,QAAU,UAAY,QAAU,MACzC,SAAU,OAAS,OAAQ,OAAS,WAAW,MAAM,EAAE,IACtD,MAAM,OAAS,SAAW,MAAM,OAAS,UAAY,MAAM,OAAS,WAC5E","names":[],"file":"linear-choice.js"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{unwrap}from"../../result.js";import{createCursorState}from"../state/cursor.js";import{bindCanonicalState,fail,hasCanonicalState,ok}from"../kernel/foundation.js";import{findEligibleFromEdge}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{clearSelection,createSelectionState,selectOne,toggleMultipleSelection}from"../state/selection.js";const DEFAULT_LISTBOX_SELECTION_MODE="single";function createListboxState(domain,input={},selectionMode=DEFAULT_LISTBOX_SELECTION_MODE){return unwrap(tryCreateListboxState(domain,input,selectionMode))}function tryCreateListboxState(domain,input={},selectionMode=DEFAULT_LISTBOX_SELECTION_MODE){const current=input.current??null;if(current!==null&&!domain.contains(current)){return fail("construction","listbox-cursor-outside-domain","Listbox cursor must exist in the sequence domain.",{current})}const selection=createSelectionState(domain,selectionMode,input);if(!selection.ok)return selection;return ok(listboxState(domain,createCursorState(current),selection.value))}function applyListboxEvent(domain,state,event,policies={}){const stateError=hasCanonicalState(domain,state)?null:validateListboxState(domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isListboxEvent(event)){return fail("transition-rejection","invalid-listbox-event","Listbox event must be next, previous, first, last, toggle, activate, or clear.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap"){return fail("transition-rejection","invalid-listbox-boundary","Listbox boundary must be stop or wrap.",{boundary})}const selectionFollowsFocus=policies.selectionFollowsFocus??false;if(typeof selectionFollowsFocus!=="boolean"){return fail("transition-rejection","invalid-selection-follows-focus","selectionFollowsFocus must be boolean.",{selectionFollowsFocus})}const deselectable=policies.deselectable??false;if(typeof deselectable!=="boolean"){return fail("transition-rejection","invalid-deselectable-policy","deselectable must be boolean.",{deselectable})}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Listbox eligibility policy must be a function.")}const selectionMode=policies.selectionMode??DEFAULT_LISTBOX_SELECTION_MODE;if(selectionMode!=="single"&&selectionMode!=="multiple"){return fail("transition-rejection","invalid-selection-mode","Listbox selection mode must be single or multiple.",{selectionMode})}if(selectionMode==="single"&&state.selection.size>1){return fail("transition-rejection","invalid-selection-cardinality","Single-selection listbox state permits at most one selected identity.",{selectedCount:state.selection.size})}if(typeof event==="object"){if(!domain.contains(event.id)||policies.eligible?.(event.id)===false){return fail("transition-rejection","listbox-target-unavailable","Direct listbox events require an eligible identity in the domain.",{id:event.id})}if(event.type==="focus"){const selection=selectionFollowsFocus?selectOne(state.selection,event.id,domain):state.selection;return createMachineUpdate(listboxState(domain,createCursorState(event.id),selection),[{type:"focus",id:event.id}])}if(event.type==="toggle"){return createMachineUpdate(listboxState(domain,createCursorState(event.id),selectForMode(state.selection,event.id,domain,selectionMode,deselectable)),[{type:"focus",id:event.id}])}return createMachineUpdate(listboxState(domain,createCursorState(event.id),selectOne(state.selection,event.id,domain)),[{type:"focus",id:event.id},{type:"activate",id:event.id}])}switch(event){case"next":return moveListbox(domain,state,1,boundary,selectionFollowsFocus,policies);case"previous":return moveListbox(domain,state,-1,boundary,selectionFollowsFocus,policies);case"first":return moveListboxToEdge(domain,state,1,selectionFollowsFocus,policies);case"last":return moveListboxToEdge(domain,state,-1,selectionFollowsFocus,policies);case"toggle":{const current=state.cursor.current;if(current===null)return noCursor();return createMachineUpdate(listboxState(domain,state.cursor,selectForMode(state.selection,current,domain,selectionMode,deselectable)))}case"activate":{const current=state.cursor.current;if(current===null)return noCursor();return createMachineUpdate(listboxState(domain,state.cursor,selectOne(state.selection,current,domain)),[{type:"activate",id:current}])}case"clear":{const selection=clearSelection(state.selection);return createMachineUpdate(selection===state.selection?state:listboxState(domain,state.cursor,selection))}}}function findListboxTypeaheadMatch(domain,current,query,options){if(typeof query!=="string"||query.length===0)return ok(null);if(typeof options.textValue!=="function"){return fail("transition-rejection","invalid-typeahead-text-value","Listbox typeahead requires a textValue function.")}if(options.eligible!==void 0&&typeof options.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Listbox typeahead eligibility must be a function.")}if(options.normalize!==void 0&&typeof options.normalize!=="function"){return fail("transition-rejection","invalid-typeahead-normalizer","Listbox typeahead normalize must be a function.")}if(options.maxScan!==void 0&&(!Number.isSafeInteger(options.maxScan)||options.maxScan<0)){return fail("resource-rejection","invalid-scan-ceiling","Listbox typeahead maxScan must be a non-negative safe integer.")}if(current!==null&&!domain.contains(current)){return fail("transition-rejection","listbox-cursor-outside-domain","Listbox typeahead cursor must exist in the sequence domain.",{current})}const normalize=options.normalize??(text=>text.toLowerCase());const needle=normalize(query);if(needle.length===0||domain.size===0)return ok(null);const eligible=options.eligible??(()=>true);const maxScan=options.maxScan??Number.MAX_SAFE_INTEGER;const start=current===null?0:(domain.indexOf(current)+1)%domain.size;let scanned=0;for(let offset=0;offset<domain.size;offset+=1){if(scanned===maxScan){return fail("resource-rejection","scan-ceiling-reached","Listbox typeahead reached maxScan before its result was determined.",{maxScan})}const id=domain.at((start+offset)%domain.size);scanned+=1;if(id!==null&&eligible(id)&&normalize(options.textValue(id)).startsWith(needle)){return ok(id)}}return ok(null)}function moveListbox(domain,state,direction,boundary,selectionFollowsFocus,policies){const eligible=policies.eligible??(()=>true);const current=state.cursor.current;let target;if(current===null){const initial=findEligibleFromEdge(domain,direction,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!initial.ok)return initial;target=initial.value}else{const movement=domain.move(current,direction,boundary,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}if(target===null)return createMachineUpdate(state);const cursor=createCursorState(target);const selection=selectionFollowsFocus?selectOne(state.selection,target,domain):state.selection;return createMachineUpdate(listboxState(domain,cursor,selection),[{type:"focus",id:target}])}function moveListboxToEdge(domain,state,direction,selectionFollowsFocus,policies){const target=findEligibleFromEdge(domain,direction,{eligible:policies.eligible??(()=>true),...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!target.ok)return target;if(target.value===null||target.value===state.cursor.current){return createMachineUpdate(state)}return createMachineUpdate(listboxState(domain,createCursorState(target.value),selectionFollowsFocus?selectOne(state.selection,target.value,domain):state.selection),[{type:"focus",id:target.value}])}function selectForMode(state,id,domain,selectionMode,deselectable){return selectionMode==="single"?deselectable&&state.has(id)?clearSelection(state):selectOne(state,id,domain):toggleMultipleSelection(state,id,domain)}function validateListboxState(domain,state){if(state.cursor.current!==null&&!domain.contains(state.cursor.current)){return{class:"transition-rejection",code:"listbox-cursor-outside-domain",message:"Listbox cursor must exist in the sequence domain.",details:{current:state.cursor.current}}}const unique=new Set(state.selection.selected);if(unique.size!==state.selection.selected.length||state.selection.size!==unique.size){return{class:"transition-rejection",code:"invalid-listbox-selection",message:"Listbox selection must contain unique identities with a matching size."}}let previousIndex=-1;for(const id of unique){const index=domain.indexOf(id);if(index===null){return{class:"transition-rejection",code:"listbox-selection-outside-domain",message:"Listbox selection identities must exist in the sequence domain.",details:{id}}}if(index<=previousIndex||!state.selection.has(id)){return{class:"transition-rejection",code:"invalid-listbox-selection",message:"Listbox selection observations must match canonical sequence order."}}previousIndex=index}for(const id of domain.ids){if(state.selection.has(id)!==unique.has(id)){return{class:"transition-rejection",code:"invalid-listbox-selection",message:"Listbox selection membership observations must agree."}}}if(state.selection.anchor!==null&&!domain.contains(state.selection.anchor)){return{class:"transition-rejection",code:"listbox-anchor-outside-domain",message:"Listbox selection anchor must exist in the sequence domain.",details:{anchor:state.selection.anchor}}}return null}function listboxState(domain,cursor,selection){return bindCanonicalState(domain,Object.freeze({cursor,selection}))}function noCursor(){return fail("transition-rejection","no-cursor","Listbox toggle and activate require a current cursor.")}function isListboxEvent(value){return typeof value==="string"?value==="next"||value==="previous"||value==="first"||value==="last"||value==="toggle"||value==="activate"||value==="clear":typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&(value.type==="focus"||value.type==="toggle"||value.type==="activate")&&typeof value.id==="string"}export{DEFAULT_LISTBOX_SELECTION_MODE,applyListboxEvent,createListboxState,findListboxTypeaheadMatch,tryCreateListboxState};
|
|
1
|
+
import{unwrap}from"../../result.js";import{createCursorState}from"../state/cursor.js";import{bindCanonicalState,fail,hasCanonicalState,isStableID,ok}from"../kernel/foundation.js";import{findEligibleFromEdge}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{clearSelection,createSelectionState,selectOne,toggleMultipleSelection}from"../state/selection.js";const DEFAULT_LISTBOX_SELECTION_MODE="single";function createListboxState(domain,input={},selectionMode=DEFAULT_LISTBOX_SELECTION_MODE){return unwrap(tryCreateListboxState(domain,input,selectionMode))}function tryCreateListboxState(domain,input={},selectionMode=DEFAULT_LISTBOX_SELECTION_MODE){const current=input.current??null;if(current!==null&&!domain.contains(current)){return fail("construction","listbox-cursor-outside-domain","Listbox cursor must exist in the sequence domain.",{current})}const selection=createSelectionState(domain,selectionMode,input);if(!selection.ok)return selection;return ok(listboxState(domain,createCursorState(current),selection.value))}function applyListboxEvent(domain,state,event,policies={}){const stateError=hasCanonicalState(domain,state)?null:validateListboxState(domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isListboxEvent(event)){return fail("transition-rejection","invalid-listbox-event","Listbox event must be next, previous, first, last, toggle, activate, or clear.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap"){return fail("transition-rejection","invalid-listbox-boundary","Listbox boundary must be stop or wrap.",{boundary})}const selectionFollowsFocus=policies.selectionFollowsFocus??false;if(typeof selectionFollowsFocus!=="boolean"){return fail("transition-rejection","invalid-selection-follows-focus","selectionFollowsFocus must be boolean.",{selectionFollowsFocus})}const deselectable=policies.deselectable??false;if(typeof deselectable!=="boolean"){return fail("transition-rejection","invalid-deselectable-policy","deselectable must be boolean.",{deselectable})}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Listbox eligibility policy must be a function.")}const selectionMode=policies.selectionMode??DEFAULT_LISTBOX_SELECTION_MODE;if(selectionMode!=="single"&&selectionMode!=="multiple"){return fail("transition-rejection","invalid-selection-mode","Listbox selection mode must be single or multiple.",{selectionMode})}if(selectionMode==="single"&&state.selection.size>1){return fail("transition-rejection","invalid-selection-cardinality","Single-selection listbox state permits at most one selected identity.",{selectedCount:state.selection.size})}if(typeof event==="object"){if(!domain.contains(event.id)||policies.eligible?.(event.id)===false){return fail("transition-rejection","listbox-target-unavailable","Direct listbox events require an eligible identity in the domain.",{id:event.id})}if(event.type==="focus"){const selection=selectionFollowsFocus?selectOne(state.selection,event.id,domain):state.selection;return createMachineUpdate(listboxState(domain,createCursorState(event.id),selection),[{type:"focus",id:event.id}])}if(event.type==="toggle"){return createMachineUpdate(listboxState(domain,createCursorState(event.id),selectForMode(state.selection,event.id,domain,selectionMode,deselectable)),[{type:"focus",id:event.id}])}return createMachineUpdate(listboxState(domain,createCursorState(event.id),selectOne(state.selection,event.id,domain)),[{type:"focus",id:event.id},{type:"activate",id:event.id}])}switch(event){case"next":return moveListbox(domain,state,1,boundary,selectionFollowsFocus,policies);case"previous":return moveListbox(domain,state,-1,boundary,selectionFollowsFocus,policies);case"first":return moveListboxToEdge(domain,state,1,selectionFollowsFocus,policies);case"last":return moveListboxToEdge(domain,state,-1,selectionFollowsFocus,policies);case"toggle":{const current=state.cursor.current;if(current===null)return noCursor();return createMachineUpdate(listboxState(domain,state.cursor,selectForMode(state.selection,current,domain,selectionMode,deselectable)))}case"activate":{const current=state.cursor.current;if(current===null)return noCursor();return createMachineUpdate(listboxState(domain,state.cursor,selectOne(state.selection,current,domain)),[{type:"activate",id:current}])}case"clear":{const selection=clearSelection(state.selection);return createMachineUpdate(selection===state.selection?state:listboxState(domain,state.cursor,selection))}}}function findListboxTypeaheadMatch(domain,current,query,options){if(typeof query!=="string"||query.length===0)return ok(null);if(typeof options.textValue!=="function"){return fail("transition-rejection","invalid-typeahead-text-value","Listbox typeahead requires a textValue function.")}if(options.eligible!==void 0&&typeof options.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Listbox typeahead eligibility must be a function.")}if(options.normalize!==void 0&&typeof options.normalize!=="function"){return fail("transition-rejection","invalid-typeahead-normalizer","Listbox typeahead normalize must be a function.")}if(options.maxScan!==void 0&&(!Number.isSafeInteger(options.maxScan)||options.maxScan<0)){return fail("resource-rejection","invalid-scan-ceiling","Listbox typeahead maxScan must be a non-negative safe integer.")}if(current!==null&&!domain.contains(current)){return fail("transition-rejection","listbox-cursor-outside-domain","Listbox typeahead cursor must exist in the sequence domain.",{current})}const normalize=options.normalize??(text=>text.toLowerCase());const needle=normalize(query);if(needle.length===0||domain.size===0)return ok(null);const eligible=options.eligible??(()=>true);const maxScan=options.maxScan??Number.MAX_SAFE_INTEGER;const start=current===null?0:(domain.indexOf(current)+1)%domain.size;let scanned=0;for(let offset=0;offset<domain.size;offset+=1){if(scanned===maxScan){return fail("resource-rejection","scan-ceiling-reached","Listbox typeahead reached maxScan before its result was determined.",{maxScan})}const id=domain.at((start+offset)%domain.size);scanned+=1;if(id!==null&&eligible(id)&&normalize(options.textValue(id)).startsWith(needle)){return ok(id)}}return ok(null)}function moveListbox(domain,state,direction,boundary,selectionFollowsFocus,policies){const eligible=policies.eligible??(()=>true);const current=state.cursor.current;let target;if(current===null){const initial=findEligibleFromEdge(domain,direction,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!initial.ok)return initial;target=initial.value}else{const movement=domain.move(current,direction,boundary,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}if(target===null)return createMachineUpdate(state);const cursor=createCursorState(target);const selection=selectionFollowsFocus?selectOne(state.selection,target,domain):state.selection;return createMachineUpdate(listboxState(domain,cursor,selection),[{type:"focus",id:target}])}function moveListboxToEdge(domain,state,direction,selectionFollowsFocus,policies){const target=findEligibleFromEdge(domain,direction,{eligible:policies.eligible??(()=>true),...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!target.ok)return target;if(target.value===null||target.value===state.cursor.current){return createMachineUpdate(state)}return createMachineUpdate(listboxState(domain,createCursorState(target.value),selectionFollowsFocus?selectOne(state.selection,target.value,domain):state.selection),[{type:"focus",id:target.value}])}function selectForMode(state,id,domain,selectionMode,deselectable){return selectionMode==="single"?deselectable&&state.has(id)?clearSelection(state):selectOne(state,id,domain):toggleMultipleSelection(state,id,domain)}function validateListboxState(domain,state){if(state.cursor.current!==null&&!domain.contains(state.cursor.current)){return{class:"transition-rejection",code:"listbox-cursor-outside-domain",message:"Listbox cursor must exist in the sequence domain.",details:{current:state.cursor.current}}}const unique=new Set(state.selection.selected);if(unique.size!==state.selection.selected.length||state.selection.size!==unique.size){return{class:"transition-rejection",code:"invalid-listbox-selection",message:"Listbox selection must contain unique identities with a matching size."}}let previousIndex=-1;for(const id of unique){const index=domain.indexOf(id);if(index===null){return{class:"transition-rejection",code:"listbox-selection-outside-domain",message:"Listbox selection identities must exist in the sequence domain.",details:{id}}}if(index<=previousIndex||!state.selection.has(id)){return{class:"transition-rejection",code:"invalid-listbox-selection",message:"Listbox selection observations must match canonical sequence order."}}previousIndex=index}for(const id of domain.ids){if(state.selection.has(id)!==unique.has(id)){return{class:"transition-rejection",code:"invalid-listbox-selection",message:"Listbox selection membership observations must agree."}}}if(state.selection.anchor!==null&&!domain.contains(state.selection.anchor)){return{class:"transition-rejection",code:"listbox-anchor-outside-domain",message:"Listbox selection anchor must exist in the sequence domain.",details:{anchor:state.selection.anchor}}}return null}function listboxState(domain,cursor,selection){return bindCanonicalState(domain,Object.freeze({cursor,selection}))}function noCursor(){return fail("transition-rejection","no-cursor","Listbox toggle and activate require a current cursor.")}function isListboxEvent(value){return typeof value==="string"?value==="next"||value==="previous"||value==="first"||value==="last"||value==="toggle"||value==="activate"||value==="clear":typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&(value.type==="focus"||value.type==="toggle"||value.type==="activate")&&isStableID(value.id)}export{DEFAULT_LISTBOX_SELECTION_MODE,applyListboxEvent,createListboxState,findListboxTypeaheadMatch,tryCreateListboxState};
|
|
2
2
|
//# sourceMappingURL=listbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/composites/listbox.ts"],"mappings":"AAAA,OAAS,WAAc,kBAGvB,OAAS,sBAA2C,qBACpD,OAAS,mBAAoB,KAAM,kBAAmB,OAAU,
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/composites/listbox.ts"],"mappings":"AAAA,OAAS,WAAc,kBAGvB,OAAS,sBAA2C,qBACpD,OAAS,mBAAoB,K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,CACf,OAAO,KACL,uBACA,YACA,uDAAuD,CAE3D,CAEA,SAAS,eAAoC,MAAc,CACzD,OAAO,OAAO,QAAU,SACtB,QAAU,QACV,QAAU,YACV,QAAU,SACV,QAAU,QACV,QAAU,UACV,QAAU,YACV,QAAU,QACR,OAAO,QAAU,UAAY,QAAU,MACtC,SAAU,OAAS,OAAQ,QAC1B,MAAM,OAAS,SAAW,MAAM,OAAS,UAAY,MAAM,OAAS,aACrE,WAAW,MAAM,EAAE,CAC1B","names":[],"file":"listbox.js"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{unwrap}from"../../result.js";import{bindCanonicalState,fail,freezeArray,hasCanonicalState,memoizeWeakPair,ok}from"../kernel/foundation.js";import{findEligibleFromEdge,IndexedSequence}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";import{createExpansionState,setExpansionOpen}from"../state/expansion.js";import{createSelectionState,selectOne}from"../state/selection.js";const visibleCellViews=new WeakMap;const visibleRowSequences=new WeakMap;const visibleRowViews=new WeakMap;class IndexedTreeGridModel{tree;grid;rowIDs;#rowIndices;constructor(tree,grid,rowIDs,rowIndices){this.tree=tree;this.grid=grid;this.rowIDs=freezeArray(rowIDs);this.#rowIndices=rowIndices;Object.freeze(this)}rowIndexOf(id){return this.#rowIndices.get(id)??null}rowOfCell(id){const position=this.grid.positionOf(id);return position===null?null:this.rowIDs[position.row]??null}}function createTreeGridModel(tree,grid,rowIDs){return unwrap(tryCreateTreeGridModel(tree,grid,rowIDs))}function tryCreateTreeGridModel(tree,grid,rowIDs){if(rowIDs.length!==grid.rowCount||rowIDs.length!==tree.size){return fail("construction","tree-grid-row-count-mismatch","Tree-grid must map every tree row to exactly one grid row.",{mappedRows:rowIDs.length,gridRows:grid.rowCount,treeRows:tree.size})}const rowIndices=new Map;for(let index=0;index<rowIDs.length;index+=1){const id=rowIDs[index];if(id===void 0||!tree.has(id)){return fail("construction","tree-grid-row-outside-tree","Every mapped tree-grid row must exist in the tree.",{index,id})}if(rowIndices.has(id)){return fail("construction","duplicate-tree-grid-row","Each tree row must map to one grid row.",{index,id})}rowIndices.set(id,index)}return ok(new IndexedTreeGridModel(tree,grid,rowIDs,rowIndices))}function createTreeGridState(model,input={}){return unwrap(tryCreateTreeGridState(model,input))}function tryCreateTreeGridState(model,input={}){const expansion=createExpansionState(model.tree,input.expanded??[]);const visible=visibleCells(model,expansion);const current=input.current??null;if(current!==null&&!visible.contains(current)){return fail("construction","tree-grid-cursor-hidden","Tree-grid cursor must belong to a visible row.",{current})}const selection=createSelectionState(allCells(model),"single",input);if(!selection.ok)return selection;const editMode=input.editMode??"navigation";if(!isTreeGridEditMode(editMode)){return fail("construction","invalid-tree-grid-edit-mode","Tree-grid edit mode must be navigation or editing.",{editMode})}if(editMode==="editing"&¤t===null){return fail("construction","tree-grid-edit-without-cursor","Tree-grid editing requires a current cell.")}return ok(treeGridState(model,expansion,createCursorState(current),selection.value,editMode))}function applyTreeGridEvent(model,state,event,policies={}){const canonical=hasCanonicalState(model,state);const expansion=canonical?state.expansion:createExpansionState(model.tree,state.expansion.ids);const visible=visibleCells(model,expansion);const domain=allCells(model);const stateError=canonical?null:validateTreeGridState(visible,domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isTreeGridEvent(event)){return fail("transition-rejection","invalid-tree-grid-event","Tree-grid event is not part of the accepted event vocabulary.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap-axis"){return fail("transition-rejection","invalid-tree-grid-boundary","Tree-grid boundary must be stop or wrap-axis.",{boundary})}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Tree-grid eligibility policy must be a function.")}const normalized=sameExpansion(expansion,state.expansion)?state:treeGridState(model,expansion,state.cursor,state.selection,state.editMode);const current=state.cursor.current;if(typeof event==="object"){if(event.type==="set-expanded"){if(!model.tree.has(event.id)){return fail("transition-rejection","tree-grid-row-outside-tree","Direct tree-grid expansion requires a row in the tree.",{id:event.id})}const nextExpansion=setExpansionOpen(expansion,event.id,event.open,model.tree);const nextVisible=visibleCells(model,nextExpansion);const rowIndex=model.rowIndexOf(event.id);const target2=current===null||nextVisible.contains(current)?current:rowIndex===null?null:model.grid.row(rowIndex)?.at(0)??null;return createMachineUpdate(treeGridState(model,nextExpansion,createCursorState(target2),state.selection,"navigation"),target2===null||target2===current?[]:[{type:"focus",id:target2}])}if(!visible.contains(event.id)||policies.eligible?.(event.id)===false){return fail("transition-rejection","tree-grid-target-unavailable","Direct tree-grid cell events require an eligible visible cell.",{id:event.id})}const cursor=createCursorState(event.id);if(event.type==="focus"){return createMachineUpdate(treeGridState(model,expansion,cursor,state.selection,"navigation"),[{type:"focus",id:event.id}])}const selection=selectOne(state.selection,event.id,domain);if(event.type==="select"){return createMachineUpdate(treeGridState(model,expansion,cursor,selection,"navigation"),[{type:"focus",id:event.id}])}return createMachineUpdate(treeGridState(model,expansion,cursor,selection,"editing"),[{type:"focus",id:event.id},{type:"begin-edit",id:event.id}])}if(event==="commit-edit"||event==="cancel-edit"){if(state.editMode!=="editing"||current===null){return fail("transition-rejection","tree-grid-not-editing","Tree-grid can only finish an active edit.")}return createMachineUpdate(treeGridState(model,expansion,state.cursor,state.selection,"navigation"),[{type:event,id:current}])}if(state.editMode==="editing"){if(event==="start-edit")return createMachineUpdate(normalized);return fail("transition-rejection","tree-grid-edit-active","Tree-grid navigation is suspended while a cell edit is active.",{event})}if(event==="start-edit"){if(current===null){return fail("transition-rejection","no-cursor","Tree-grid editing requires a cursor.")}return createMachineUpdate(treeGridState(model,expansion,state.cursor,state.selection,"editing"),[{type:"begin-edit",id:current}])}if(event==="select"){if(current===null){return fail("transition-rejection","no-cursor","Tree-grid selection requires a cursor.")}const selection=selectOne(state.selection,current,domain);return createMachineUpdate(selection===state.selection?normalized:treeGridState(model,expansion,state.cursor,selection,"navigation"))}if(event==="expand"||event==="collapse"){if(current===null)return createMachineUpdate(normalized);const row=model.rowOfCell(current);if(row===null)return createMachineUpdate(normalized);const nextExpansion=setExpansionOpen(expansion,row,event==="expand",model.tree);return createMachineUpdate(nextExpansion===expansion?normalized:treeGridState(model,nextExpansion,state.cursor,state.selection,"navigation"))}const eligible=policies.eligible??(()=>true);let target;if(current===null){const initial=findEligibleFromEdge(visible,event==="right"||event==="down"?1:-1,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!initial.ok)return initial;target=initial.value}else{const visibleRows2=visibleRowsFor(model,expansion);const movement=model.grid.move(current,event,boundary,{eligible:id=>{const row=model.rowOfCell(id);return row!==null&&visibleRows2.has(row)&&eligible(id)},...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}if(target===null)return createMachineUpdate(normalized);return createMachineUpdate(treeGridState(model,expansion,createCursorState(target),state.selection,"navigation"),[{type:"focus",id:target}])}function allCells(model){return model.grid.domain()}function visibleCells(model,expansion){return memoizeWeakPair(visibleCellViews,model,expansion,createVisibleCells)}function createVisibleCells(owner,expansion){const model=owner;const rows=visibleRows(model,expansion);const ids=[];for(let index=0;index<rows.size;index+=1){const row=rows.at(index);if(row===null)continue;const rowIndex=model.rowIndexOf(row);if(rowIndex===null)continue;const cells=model.grid.row(rowIndex);if(cells===null)continue;for(let cellIndex=0;cellIndex<cells.size;cellIndex+=1){const cell=cells.at(cellIndex);if(cell!==null)ids.push(cell)}}return new IndexedSequence(Object.freeze(ids))}function visibleRows(model,expansion){return memoizeWeakPair(visibleRowSequences,model,expansion,createVisibleRowSequence)}function createVisibleRowSequence(owner,expansion){return owner.tree.visible(expansion)}function visibleRowsFor(model,expansion){return memoizeWeakPair(visibleRowViews,model,expansion,createVisibleRows)}function createVisibleRows(owner,expansion){return new Set(visibleRows(owner,expansion).ids)}function validateTreeGridState(visible,domain,state){if(!isTreeGridEditMode(state.editMode)){return{class:"transition-rejection",code:"invalid-tree-grid-edit-mode",message:"Tree-grid edit mode must be navigation or editing."}}if(state.cursor.current!==null&&!visible.contains(state.cursor.current)){return{class:"transition-rejection",code:"tree-grid-cursor-hidden",message:"Tree-grid cursor must remain on a visible row.",details:{current:state.cursor.current}}}if(state.editMode==="editing"&&state.cursor.current===null){return{class:"transition-rejection",code:"tree-grid-edit-without-cursor",message:"Tree-grid editing requires a current cell."}}if(state.selection.size>1||state.selection.selected.length!==state.selection.size){return{class:"transition-rejection",code:"invalid-tree-grid-selection",message:"Tree-grid selection must contain at most one identity."}}for(const id of state.selection.selected){if(!domain.contains(id)||!state.selection.has(id)){return{class:"transition-rejection",code:"tree-grid-selection-outside-grid",message:"Tree-grid selection must agree with the cell grid.",details:{id}}}}if(state.selection.anchor!==null&&!domain.contains(state.selection.anchor)){return{class:"transition-rejection",code:"tree-grid-anchor-outside-grid",message:"Tree-grid selection anchor must exist in the cell grid.",details:{anchor:state.selection.anchor}}}return null}function treeGridState(model,expansion,cursor,selection,editMode){return bindCanonicalState(model,Object.freeze({expansion,cursor,selection,editMode}))}function sameExpansion(left,right){return left.ids.length===right.ids.length&&left.ids.every((id,index)=>id===right.ids[index])}function isTreeGridEditMode(value){return value==="navigation"||value==="editing"}function isTreeGridEvent(value){if(typeof value==="string"){return value==="left"||value==="right"||value==="up"||value==="down"||value==="expand"||value==="collapse"||value==="select"||value==="start-edit"||value==="commit-edit"||value==="cancel-edit"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&typeof value.id==="string"&&(value.type==="focus"||value.type==="select"||value.type==="start-edit"||value.type==="set-expanded"&&"open"in value&&typeof value.open==="boolean")}export{applyTreeGridEvent,createTreeGridModel,createTreeGridState,tryCreateTreeGridModel,tryCreateTreeGridState};
|
|
1
|
+
import{unwrap}from"../../result.js";import{bindCanonicalState,fail,freezeArray,hasCanonicalState,isStableID,memoizeWeakPair,ok}from"../kernel/foundation.js";import{findEligibleFromEdge,IndexedSequence}from"../kernel/indexed-sequence.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";import{createExpansionState,setExpansionOpen}from"../state/expansion.js";import{createSelectionState,selectOne}from"../state/selection.js";const visibleCellViews=new WeakMap;const visibleRowSequences=new WeakMap;const visibleRowViews=new WeakMap;class IndexedTreeGridModel{tree;grid;rowIDs;#rowIndices;constructor(tree,grid,rowIDs,rowIndices){this.tree=tree;this.grid=grid;this.rowIDs=freezeArray(rowIDs);this.#rowIndices=rowIndices;Object.freeze(this)}rowIndexOf(id){return this.#rowIndices.get(id)??null}rowOfCell(id){const position=this.grid.positionOf(id);return position===null?null:this.rowIDs[position.row]??null}}function createTreeGridModel(tree,grid,rowIDs){return unwrap(tryCreateTreeGridModel(tree,grid,rowIDs))}function tryCreateTreeGridModel(tree,grid,rowIDs){if(rowIDs.length!==grid.rowCount||rowIDs.length!==tree.size){return fail("construction","tree-grid-row-count-mismatch","Tree-grid must map every tree row to exactly one grid row.",{mappedRows:rowIDs.length,gridRows:grid.rowCount,treeRows:tree.size})}const rowIndices=new Map;for(let index=0;index<rowIDs.length;index+=1){const id=rowIDs[index];if(id===void 0||!tree.has(id)){return fail("construction","tree-grid-row-outside-tree","Every mapped tree-grid row must exist in the tree.",{index,id})}if(rowIndices.has(id)){return fail("construction","duplicate-tree-grid-row","Each tree row must map to one grid row.",{index,id})}rowIndices.set(id,index)}return ok(new IndexedTreeGridModel(tree,grid,rowIDs,rowIndices))}function createTreeGridState(model,input={}){return unwrap(tryCreateTreeGridState(model,input))}function tryCreateTreeGridState(model,input={}){const expansion=createExpansionState(model.tree,input.expanded??[]);const visible=visibleCells(model,expansion);const current=input.current??null;if(current!==null&&!visible.contains(current)){return fail("construction","tree-grid-cursor-hidden","Tree-grid cursor must belong to a visible row.",{current})}const selection=createSelectionState(allCells(model),"single",input);if(!selection.ok)return selection;const editMode=input.editMode??"navigation";if(!isTreeGridEditMode(editMode)){return fail("construction","invalid-tree-grid-edit-mode","Tree-grid edit mode must be navigation or editing.",{editMode})}if(editMode==="editing"&¤t===null){return fail("construction","tree-grid-edit-without-cursor","Tree-grid editing requires a current cell.")}return ok(treeGridState(model,expansion,createCursorState(current),selection.value,editMode))}function applyTreeGridEvent(model,state,event,policies={}){const canonical=hasCanonicalState(model,state);const expansion=canonical?state.expansion:createExpansionState(model.tree,state.expansion.ids);const visible=visibleCells(model,expansion);const domain=allCells(model);const stateError=canonical?null:validateTreeGridState(visible,domain,state);if(stateError!==null)return{ok:false,error:stateError};if(!isTreeGridEvent(event)){return fail("transition-rejection","invalid-tree-grid-event","Tree-grid event is not part of the accepted event vocabulary.",{event})}const boundary=policies.boundary??"stop";if(boundary!=="stop"&&boundary!=="wrap-axis"){return fail("transition-rejection","invalid-tree-grid-boundary","Tree-grid boundary must be stop or wrap-axis.",{boundary})}if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Tree-grid eligibility policy must be a function.")}const normalized=sameExpansion(expansion,state.expansion)?state:treeGridState(model,expansion,state.cursor,state.selection,state.editMode);const current=state.cursor.current;if(typeof event==="object"){if(event.type==="set-expanded"){if(!model.tree.has(event.id)){return fail("transition-rejection","tree-grid-row-outside-tree","Direct tree-grid expansion requires a row in the tree.",{id:event.id})}const nextExpansion=setExpansionOpen(expansion,event.id,event.open,model.tree);const nextVisible=visibleCells(model,nextExpansion);const rowIndex=model.rowIndexOf(event.id);const target2=current===null||nextVisible.contains(current)?current:rowIndex===null?null:model.grid.row(rowIndex)?.at(0)??null;return createMachineUpdate(treeGridState(model,nextExpansion,createCursorState(target2),state.selection,"navigation"),target2===null||target2===current?[]:[{type:"focus",id:target2}])}if(!visible.contains(event.id)||policies.eligible?.(event.id)===false){return fail("transition-rejection","tree-grid-target-unavailable","Direct tree-grid cell events require an eligible visible cell.",{id:event.id})}const cursor=createCursorState(event.id);if(event.type==="focus"){return createMachineUpdate(treeGridState(model,expansion,cursor,state.selection,"navigation"),[{type:"focus",id:event.id}])}const selection=selectOne(state.selection,event.id,domain);if(event.type==="select"){return createMachineUpdate(treeGridState(model,expansion,cursor,selection,"navigation"),[{type:"focus",id:event.id}])}return createMachineUpdate(treeGridState(model,expansion,cursor,selection,"editing"),[{type:"focus",id:event.id},{type:"begin-edit",id:event.id}])}if(event==="commit-edit"||event==="cancel-edit"){if(state.editMode!=="editing"||current===null){return fail("transition-rejection","tree-grid-not-editing","Tree-grid can only finish an active edit.")}return createMachineUpdate(treeGridState(model,expansion,state.cursor,state.selection,"navigation"),[{type:event,id:current}])}if(state.editMode==="editing"){if(event==="start-edit")return createMachineUpdate(normalized);return fail("transition-rejection","tree-grid-edit-active","Tree-grid navigation is suspended while a cell edit is active.",{event})}if(event==="start-edit"){if(current===null){return fail("transition-rejection","no-cursor","Tree-grid editing requires a cursor.")}return createMachineUpdate(treeGridState(model,expansion,state.cursor,state.selection,"editing"),[{type:"begin-edit",id:current}])}if(event==="select"){if(current===null){return fail("transition-rejection","no-cursor","Tree-grid selection requires a cursor.")}const selection=selectOne(state.selection,current,domain);return createMachineUpdate(selection===state.selection?normalized:treeGridState(model,expansion,state.cursor,selection,"navigation"))}if(event==="expand"||event==="collapse"){if(current===null)return createMachineUpdate(normalized);const row=model.rowOfCell(current);if(row===null)return createMachineUpdate(normalized);const nextExpansion=setExpansionOpen(expansion,row,event==="expand",model.tree);return createMachineUpdate(nextExpansion===expansion?normalized:treeGridState(model,nextExpansion,state.cursor,state.selection,"navigation"))}const eligible=policies.eligible??(()=>true);let target;if(current===null){const initial=findEligibleFromEdge(visible,event==="right"||event==="down"?1:-1,{eligible,...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(!initial.ok)return initial;target=initial.value}else{const visibleRows2=visibleRowsFor(model,expansion);const movement=model.grid.move(current,event,boundary,{eligible:id=>{const row=model.rowOfCell(id);return row!==null&&visibleRows2.has(row)&&eligible(id)},...policies.maxScan===void 0?{}:{maxScan:policies.maxScan}});if(movement.kind==="resource-rejected")return{ok:false,error:movement.error};target=movement.kind==="found"?movement.id:null}if(target===null)return createMachineUpdate(normalized);return createMachineUpdate(treeGridState(model,expansion,createCursorState(target),state.selection,"navigation"),[{type:"focus",id:target}])}function allCells(model){return model.grid.domain()}function visibleCells(model,expansion){return memoizeWeakPair(visibleCellViews,model,expansion,createVisibleCells)}function createVisibleCells(owner,expansion){const model=owner;const rows=visibleRows(model,expansion);const ids=[];for(let index=0;index<rows.size;index+=1){const row=rows.at(index);if(row===null)continue;const rowIndex=model.rowIndexOf(row);if(rowIndex===null)continue;const cells=model.grid.row(rowIndex);if(cells===null)continue;for(let cellIndex=0;cellIndex<cells.size;cellIndex+=1){const cell=cells.at(cellIndex);if(cell!==null)ids.push(cell)}}return new IndexedSequence(Object.freeze(ids))}function visibleRows(model,expansion){return memoizeWeakPair(visibleRowSequences,model,expansion,createVisibleRowSequence)}function createVisibleRowSequence(owner,expansion){return owner.tree.visible(expansion)}function visibleRowsFor(model,expansion){return memoizeWeakPair(visibleRowViews,model,expansion,createVisibleRows)}function createVisibleRows(owner,expansion){return new Set(visibleRows(owner,expansion).ids)}function validateTreeGridState(visible,domain,state){if(!isTreeGridEditMode(state.editMode)){return{class:"transition-rejection",code:"invalid-tree-grid-edit-mode",message:"Tree-grid edit mode must be navigation or editing."}}if(state.cursor.current!==null&&!visible.contains(state.cursor.current)){return{class:"transition-rejection",code:"tree-grid-cursor-hidden",message:"Tree-grid cursor must remain on a visible row.",details:{current:state.cursor.current}}}if(state.editMode==="editing"&&state.cursor.current===null){return{class:"transition-rejection",code:"tree-grid-edit-without-cursor",message:"Tree-grid editing requires a current cell."}}if(state.selection.size>1||state.selection.selected.length!==state.selection.size){return{class:"transition-rejection",code:"invalid-tree-grid-selection",message:"Tree-grid selection must contain at most one identity."}}for(const id of state.selection.selected){if(!domain.contains(id)||!state.selection.has(id)){return{class:"transition-rejection",code:"tree-grid-selection-outside-grid",message:"Tree-grid selection must agree with the cell grid.",details:{id}}}}if(state.selection.anchor!==null&&!domain.contains(state.selection.anchor)){return{class:"transition-rejection",code:"tree-grid-anchor-outside-grid",message:"Tree-grid selection anchor must exist in the cell grid.",details:{anchor:state.selection.anchor}}}return null}function treeGridState(model,expansion,cursor,selection,editMode){return bindCanonicalState(model,Object.freeze({expansion,cursor,selection,editMode}))}function sameExpansion(left,right){return left.ids.length===right.ids.length&&left.ids.every((id,index)=>id===right.ids[index])}function isTreeGridEditMode(value){return value==="navigation"||value==="editing"}function isTreeGridEvent(value){if(typeof value==="string"){return value==="left"||value==="right"||value==="up"||value==="down"||value==="expand"||value==="collapse"||value==="select"||value==="start-edit"||value==="commit-edit"||value==="cancel-edit"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&isStableID(value.id)&&(value.type==="focus"||value.type==="select"||value.type==="start-edit"||value.type==="set-expanded"&&"open"in value&&typeof value.open==="boolean")}export{applyTreeGridEvent,createTreeGridModel,createTreeGridState,tryCreateTreeGridModel,tryCreateTreeGridState};
|
|
2
2
|
//# sourceMappingURL=tree-grid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/composites/tree-grid.ts"],"mappings":"AAAA,OAAS,WAAc,kBAWvB,OAAS,mBAAoB,KAAM,YAAa,kBAAmB,gBAAiB,OAAU,
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/composites/tree-grid.ts"],"mappings":"AAAA,OAAS,WAAc,kBAWvB,OAAS,mBAAoB,KAAM,YAAa,kBAAmB,WAAY,gBAAiB,OAAU,0BAC1G,OAAS,qBAAsB,oBAAuB,gCACtD,OAAS,wBAA2B,uBACpC,OAAS,sBAA2C,qBACpD,OACE,qBACA,qBAEK,wBACP,OACE,qBACA,cAGK,wBAsEP,MAAM,iBAAmB,IAAI,QAC7B,MAAM,oBAAsB,IAAI,QAChC,MAAM,gBAAkB,IAAI,QAE5B,MAAM,oBAAoB,CAER,KACA,KACA,OACP,YAET,YACE,KACA,KACA,OACA,WAAsC,CAEtC,KAAK,KAAO,KACZ,KAAK,KAAO,KACZ,KAAK,OAAS,YAAY,MAAM,EAChC,KAAK,YAAc,W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AAM,OAAS,gBAAkB,SAAU,OAAS,OAAO,MAAM,OAAS,UACpF","names":["target","visibleRows"],"file":"tree-grid.js"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{unwrap}from"../../result.js";import{bindCanonicalState,fail,hasCanonicalState,memoizeWeakPair,ok}from"../kernel/foundation.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";import{createExpansionState,setExpansionOpen}from"../state/expansion.js";import{createSelectionState,selectOne,toggleMultipleSelection}from"../state/selection.js";const treeVisibleViews=new WeakMap;function createTreeViewState(tree,input={},selectionMode="multiple"){return unwrap(tryCreateTreeViewState(tree,input,selectionMode))}function tryCreateTreeViewState(tree,input={},selectionMode="multiple"){const expansion=createExpansionState(tree,input.expanded??[]);const visible=treeVisible(tree,expansion);const current=input.current??null;if(current!==null&&!visible.contains(current)){return fail("construction","tree-view-cursor-hidden","Tree-view cursor must be visible under the requested expansion.",{current})}const selection=createSelectionState(tree.preorder(),selectionMode,input);if(!selection.ok)return selection;return ok(treeViewState(tree,expansion,createCursorState(current),selection.value))}function applyTreeViewEvent(tree,state,event,policies={}){if(!isTreeViewEvent(event)){return fail("transition-rejection","invalid-tree-view-event","Tree-view event must be next, previous, right, left, or toggle-select.",{event})}const canonical=hasCanonicalState(tree,state);const expansion=canonical?state.expansion:createExpansionState(tree,state.expansion.ids);if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Tree-view eligibility policy must be a function.")}const eligible=policies.eligible??(()=>true);const selectionMode=policies.selectionMode??"multiple";if(selectionMode!=="single"&&selectionMode!=="multiple"){return fail("transition-rejection","invalid-selection-mode","Tree-view selection mode must be single or multiple.",{selectionMode})}const visible=treeVisible(tree,expansion);const stateError=canonical?null:validateTreeViewState(tree,visible,state,selectionMode);if(stateError!==null)return{ok:false,error:stateError};const normalized=sameExpansion(expansion,state.expansion)?state:treeViewState(tree,expansion,state.cursor,state.selection);const current=state.cursor.current;if(typeof event==="object"){if(!tree.has(event.id)){return fail("transition-rejection","tree-view-target-outside-tree","Direct tree-view events require an identity in the tree.",{id:event.id})}if(event.type==="set-expanded"){if(!visible.contains(event.id))return fail("transition-rejection","tree-view-target-hidden","Expansion changes require a visible tree-view item.",{id:event.id});if(!eligible(event.id))return fail("transition-rejection","tree-view-target-ineligible","Disabled tree-view items cannot change expansion.",{id:event.id});const nextExpansion=setExpansionOpen(expansion,event.id,event.open,tree);const nextVisible=treeVisible(tree,nextExpansion);const target=current!==null&&nextVisible.contains(current)?current:event.id;return createMachineUpdate(treeViewState(tree,nextExpansion,createCursorState(target),state.selection),target===current?[]:[{type:"focus",id:target}])}if(!visible.contains(event.id)){return fail("transition-rejection","tree-view-target-hidden","Direct tree-view focus and selection require a visible identity.",{id:event.id})}if(!eligible(event.id))return fail("transition-rejection","tree-view-target-ineligible","Direct tree-view focus and selection require an eligible identity.",{id:event.id});if(event.type==="focus"){return createMachineUpdate(treeViewState(tree,expansion,createCursorState(event.id),state.selection),[{type:"focus",id:event.id}])}return createMachineUpdate(treeViewState(tree,expansion,createCursorState(event.id),selectForMode(state.selection,event.id,tree.preorder(),selectionMode)),[{type:"focus",id:event.id}])}if(event==="next"||event==="previous"){const target=current===null?eligibleFromEdge(visible,event==="next"?1:-1,eligible):movementTarget(visible,current,event==="next"?1:-1,eligible);if(target===null)return createMachineUpdate(normalized);return createMachineUpdate(treeViewState(tree,expansion,createCursorState(target),state.selection),[{type:"focus",id:target}])}if(event==="right"){if(current===null)return createMachineUpdate(normalized);const children=tree.childrenOf(current);if(children===null||children.size===0)return createMachineUpdate(normalized);if(!expansion.has(current)){return createMachineUpdate(treeViewState(tree,setExpansionOpen(expansion,current,true,tree),state.cursor,state.selection))}const target=eligibleFromEdge(children,1,eligible);if(target===null)return createMachineUpdate(normalized);return createMachineUpdate(treeViewState(tree,expansion,createCursorState(target),state.selection),[{type:"focus",id:target}])}if(event==="left"){if(current===null)return createMachineUpdate(normalized);if(expansion.has(current)){return createMachineUpdate(treeViewState(tree,setExpansionOpen(expansion,current,false,tree),state.cursor,state.selection))}const parent=eligibleAncestor(tree,current,eligible);if(parent===null)return createMachineUpdate(normalized);return createMachineUpdate(treeViewState(tree,expansion,createCursorState(parent),state.selection),[{type:"focus",id:parent}])}if(current===null){return fail("transition-rejection","no-cursor","Tree-view selection requires a cursor.")}if(!eligible(current))return fail("transition-rejection","tree-view-target-ineligible","Tree-view selection requires an eligible cursor.",{id:current});return createMachineUpdate(treeViewState(tree,expansion,state.cursor,selectForMode(state.selection,current,tree.preorder(),selectionMode)))}function movementTarget(visible,current,direction,eligible){const index=visible.indexOf(current);if(index===null)return null;for(let candidate=index+direction;candidate>=0&&candidate<visible.size;candidate+=direction){const id=visible.at(candidate);if(id!==null&&eligible(id))return id}return null}function eligibleFromEdge(domain,direction,eligible){for(let index=direction===1?0:domain.size-1;index>=0&&index<domain.size;index+=direction){const id=domain.at(index);if(id!==null&&eligible(id))return id}return null}function eligibleAncestor(tree,id,eligible){let parent=tree.parentOf(id);while(parent!==null&&!eligible(parent))parent=tree.parentOf(parent);return parent}function validateTreeViewState(tree,visible,state,selectionMode){if(state.cursor.current!==null&&!visible.contains(state.cursor.current)){return{class:"transition-rejection",code:"tree-view-cursor-hidden",message:"Tree-view cursor must remain visible.",details:{current:state.cursor.current}}}const preorder=tree.preorder();const unique=new Set(state.selection.selected);if(selectionMode==="single"&&unique.size>1){return{class:"transition-rejection",code:"invalid-selection-cardinality",message:"Single-selection tree-view state must contain at most one identity.",details:{selectedCount:unique.size}}}if(unique.size!==state.selection.selected.length||unique.size!==state.selection.size){return{class:"transition-rejection",code:"invalid-tree-view-selection",message:"Tree-view selection must contain unique identities with matching observations."}}for(const id of unique){if(!preorder.contains(id)||!state.selection.has(id)){return{class:"transition-rejection",code:"tree-view-selection-outside-tree",message:"Tree-view selection must belong to the tree.",details:{id}}}}if(state.selection.anchor!==null&&!preorder.contains(state.selection.anchor)){return{class:"transition-rejection",code:"tree-view-anchor-outside-tree",message:"Tree-view anchor must belong to the tree.",details:{anchor:state.selection.anchor}}}return null}function selectForMode(state,id,domain,selectionMode){return selectionMode==="single"?selectOne(state,id,domain):toggleMultipleSelection(state,id,domain)}function sameExpansion(left,right){return left.ids.length===right.ids.length&&left.ids.every((id,index)=>id===right.ids[index])}function treeViewState(tree,expansion,cursor,selection){return bindCanonicalState(tree,Object.freeze({expansion,cursor,selection}))}function treeVisible(tree,expansion){return memoizeWeakPair(treeVisibleViews,tree,expansion,createTreeVisible)}function createTreeVisible(owner,expansion){return owner.visible(expansion)}function isTreeViewEvent(value){if(typeof value==="string"){return value==="next"||value==="previous"||value==="right"||value==="left"||value==="toggle-select"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&
|
|
1
|
+
import{unwrap}from"../../result.js";import{bindCanonicalState,fail,hasCanonicalState,isStableID,memoizeWeakPair,ok}from"../kernel/foundation.js";import{createMachineUpdate}from"../kernel/machine.js";import{createCursorState}from"../state/cursor.js";import{createExpansionState,setExpansionOpen}from"../state/expansion.js";import{createSelectionState,selectOne,toggleMultipleSelection}from"../state/selection.js";const treeVisibleViews=new WeakMap;function createTreeViewState(tree,input={},selectionMode="multiple"){return unwrap(tryCreateTreeViewState(tree,input,selectionMode))}function tryCreateTreeViewState(tree,input={},selectionMode="multiple"){const expansion=createExpansionState(tree,input.expanded??[]);const visible=treeVisible(tree,expansion);const current=input.current??null;if(current!==null&&!visible.contains(current)){return fail("construction","tree-view-cursor-hidden","Tree-view cursor must be visible under the requested expansion.",{current})}const selection=createSelectionState(tree.preorder(),selectionMode,input);if(!selection.ok)return selection;return ok(treeViewState(tree,expansion,createCursorState(current),selection.value))}function applyTreeViewEvent(tree,state,event,policies={}){if(!isTreeViewEvent(event)){return fail("transition-rejection","invalid-tree-view-event","Tree-view event must be next, previous, right, left, or toggle-select.",{event})}const canonical=hasCanonicalState(tree,state);const expansion=canonical?state.expansion:createExpansionState(tree,state.expansion.ids);if(policies.eligible!==void 0&&typeof policies.eligible!=="function"){return fail("transition-rejection","invalid-eligibility-policy","Tree-view eligibility policy must be a function.")}const eligible=policies.eligible??(()=>true);const selectionMode=policies.selectionMode??"multiple";if(selectionMode!=="single"&&selectionMode!=="multiple"){return fail("transition-rejection","invalid-selection-mode","Tree-view selection mode must be single or multiple.",{selectionMode})}const visible=treeVisible(tree,expansion);const stateError=canonical?null:validateTreeViewState(tree,visible,state,selectionMode);if(stateError!==null)return{ok:false,error:stateError};const normalized=sameExpansion(expansion,state.expansion)?state:treeViewState(tree,expansion,state.cursor,state.selection);const current=state.cursor.current;if(typeof event==="object"){if(!tree.has(event.id)){return fail("transition-rejection","tree-view-target-outside-tree","Direct tree-view events require an identity in the tree.",{id:event.id})}if(event.type==="set-expanded"){if(!visible.contains(event.id))return fail("transition-rejection","tree-view-target-hidden","Expansion changes require a visible tree-view item.",{id:event.id});if(!eligible(event.id))return fail("transition-rejection","tree-view-target-ineligible","Disabled tree-view items cannot change expansion.",{id:event.id});const nextExpansion=setExpansionOpen(expansion,event.id,event.open,tree);const nextVisible=treeVisible(tree,nextExpansion);const target=current!==null&&nextVisible.contains(current)?current:event.id;return createMachineUpdate(treeViewState(tree,nextExpansion,createCursorState(target),state.selection),target===current?[]:[{type:"focus",id:target}])}if(!visible.contains(event.id)){return fail("transition-rejection","tree-view-target-hidden","Direct tree-view focus and selection require a visible identity.",{id:event.id})}if(!eligible(event.id))return fail("transition-rejection","tree-view-target-ineligible","Direct tree-view focus and selection require an eligible identity.",{id:event.id});if(event.type==="focus"){return createMachineUpdate(treeViewState(tree,expansion,createCursorState(event.id),state.selection),[{type:"focus",id:event.id}])}return createMachineUpdate(treeViewState(tree,expansion,createCursorState(event.id),selectForMode(state.selection,event.id,tree.preorder(),selectionMode)),[{type:"focus",id:event.id}])}if(event==="next"||event==="previous"){const target=current===null?eligibleFromEdge(visible,event==="next"?1:-1,eligible):movementTarget(visible,current,event==="next"?1:-1,eligible);if(target===null)return createMachineUpdate(normalized);return createMachineUpdate(treeViewState(tree,expansion,createCursorState(target),state.selection),[{type:"focus",id:target}])}if(event==="right"){if(current===null)return createMachineUpdate(normalized);const children=tree.childrenOf(current);if(children===null||children.size===0)return createMachineUpdate(normalized);if(!expansion.has(current)){return createMachineUpdate(treeViewState(tree,setExpansionOpen(expansion,current,true,tree),state.cursor,state.selection))}const target=eligibleFromEdge(children,1,eligible);if(target===null)return createMachineUpdate(normalized);return createMachineUpdate(treeViewState(tree,expansion,createCursorState(target),state.selection),[{type:"focus",id:target}])}if(event==="left"){if(current===null)return createMachineUpdate(normalized);if(expansion.has(current)){return createMachineUpdate(treeViewState(tree,setExpansionOpen(expansion,current,false,tree),state.cursor,state.selection))}const parent=eligibleAncestor(tree,current,eligible);if(parent===null)return createMachineUpdate(normalized);return createMachineUpdate(treeViewState(tree,expansion,createCursorState(parent),state.selection),[{type:"focus",id:parent}])}if(current===null){return fail("transition-rejection","no-cursor","Tree-view selection requires a cursor.")}if(!eligible(current))return fail("transition-rejection","tree-view-target-ineligible","Tree-view selection requires an eligible cursor.",{id:current});return createMachineUpdate(treeViewState(tree,expansion,state.cursor,selectForMode(state.selection,current,tree.preorder(),selectionMode)))}function movementTarget(visible,current,direction,eligible){const index=visible.indexOf(current);if(index===null)return null;for(let candidate=index+direction;candidate>=0&&candidate<visible.size;candidate+=direction){const id=visible.at(candidate);if(id!==null&&eligible(id))return id}return null}function eligibleFromEdge(domain,direction,eligible){for(let index=direction===1?0:domain.size-1;index>=0&&index<domain.size;index+=direction){const id=domain.at(index);if(id!==null&&eligible(id))return id}return null}function eligibleAncestor(tree,id,eligible){let parent=tree.parentOf(id);while(parent!==null&&!eligible(parent))parent=tree.parentOf(parent);return parent}function validateTreeViewState(tree,visible,state,selectionMode){if(state.cursor.current!==null&&!visible.contains(state.cursor.current)){return{class:"transition-rejection",code:"tree-view-cursor-hidden",message:"Tree-view cursor must remain visible.",details:{current:state.cursor.current}}}const preorder=tree.preorder();const unique=new Set(state.selection.selected);if(selectionMode==="single"&&unique.size>1){return{class:"transition-rejection",code:"invalid-selection-cardinality",message:"Single-selection tree-view state must contain at most one identity.",details:{selectedCount:unique.size}}}if(unique.size!==state.selection.selected.length||unique.size!==state.selection.size){return{class:"transition-rejection",code:"invalid-tree-view-selection",message:"Tree-view selection must contain unique identities with matching observations."}}for(const id of unique){if(!preorder.contains(id)||!state.selection.has(id)){return{class:"transition-rejection",code:"tree-view-selection-outside-tree",message:"Tree-view selection must belong to the tree.",details:{id}}}}if(state.selection.anchor!==null&&!preorder.contains(state.selection.anchor)){return{class:"transition-rejection",code:"tree-view-anchor-outside-tree",message:"Tree-view anchor must belong to the tree.",details:{anchor:state.selection.anchor}}}return null}function selectForMode(state,id,domain,selectionMode){return selectionMode==="single"?selectOne(state,id,domain):toggleMultipleSelection(state,id,domain)}function sameExpansion(left,right){return left.ids.length===right.ids.length&&left.ids.every((id,index)=>id===right.ids[index])}function treeViewState(tree,expansion,cursor,selection){return bindCanonicalState(tree,Object.freeze({expansion,cursor,selection}))}function treeVisible(tree,expansion){return memoizeWeakPair(treeVisibleViews,tree,expansion,createTreeVisible)}function createTreeVisible(owner,expansion){return owner.visible(expansion)}function isTreeViewEvent(value){if(typeof value==="string"){return value==="next"||value==="previous"||value==="right"||value==="left"||value==="toggle-select"}return typeof value==="object"&&value!==null&&"type"in value&&"id"in value&&isStableID(value.id)&&(value.type==="focus"||value.type==="toggle-select"||value.type==="set-expanded"&&"open"in value&&typeof value.open==="boolean")}export{applyTreeViewEvent,createTreeViewState,tryCreateTreeViewState};
|
|
2
2
|
//# sourceMappingURL=tree-view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/composites/tree-view.ts"],"mappings":"AAAA,OAAS,WAAc,kBAGvB,OAAS,mBAAoB,KAAM,kBAAmB,gBAAiB,OAAU,
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/composites/tree-view.ts"],"mappings":"AAAA,OAAS,WAAc,kBAGvB,OAAS,mBAAoB,KAAM,kBAAmB,WAAY,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cACP,MACA,GACA,OACA,cAAoC,CAEpC,OAAO,gBAAkB,SACrB,UAAU,MAAO,GAAI,MAAM,EAC3B,wBAAwB,MAAO,GAAI,MAAM,CAC/C,CAEA,SAAS,cACP,KACA,MAAyB,CAEzB,OAAO,KAAK,IAAI,SAAW,MAAM,IAAI,QAAU,KAAK,IAAI,MAAM,CAAC,GAAI,QAAU,KAAO,MAAM,IAAI,KAAK,CAAC,CACtG,CAEA,SAAS,cACP,KACA,UACA,OACA,UAA6B,CAE7B,OAAO,mBAAmB,KAAM,OAAO,OAAO,CAAE,UAAW,OAAQ,SAAS,CAAE,CAAC,CACjF,CAEA,SAAS,YAAiC,KAAgB,UAA6B,CACrF,OAAO,gBAAgB,iBAAkB,KAAM,UAAW,iBAAiB,CAC7E,CAEA,SAAS,kBAAkB,MAAe,UAAiB,CAA2C,OAAQ,MAAyB,QAAQ,SAAqC,CAAG,CAEvL,SAAS,gBAAqC,MAAc,CAC1D,GAAI,OAAO,QAAU,SAAU,CAC7B,OAAO,QAAU,QACZ,QAAU,YACV,QAAU,SACV,QAAU,QACV,QAAU,eACjB,CACA,OAAO,OAAO,QAAU,UAAY,QAAU,MAAQ,SAAU,OAAS,OAAQ,OAC5E,WAAW,MAAM,EAAE,IAClB,MAAM,OAAS,SAAW,MAAM,OAAS,iBACvC,MAAM,OAAS,gBAAkB,SAAU,OAAS,OAAO,MAAM,OAAS,UACpF","names":[],"file":"tree-view.js"}
|
|
@@ -9,7 +9,8 @@ export declare function memoizeWeak<Key extends object, Value>(cache: WeakMap<Ke
|
|
|
9
9
|
export declare function memoizeWeakPair<Owner extends object, Key extends object, Value>(cache: WeakMap<Owner, WeakMap<Key, Value>>, owner: Owner, key: Key, create: (owner: Owner, key: Key) => Value): Value;
|
|
10
10
|
export declare function resourceError<Code extends string = CoreErrorCode>(code: Code, message: string, details?: Readonly<Record<string, unknown>>): SectileError<Code>;
|
|
11
11
|
export declare function isWellFormedUTF16(value: string): boolean;
|
|
12
|
-
export declare function validateStableID(id:
|
|
12
|
+
export declare function validateStableID(id: unknown, maxIDCodeUnits?: number): SectileError | null;
|
|
13
|
+
export declare function isStableID(value: unknown): value is StableID;
|
|
13
14
|
export declare function validateSafeCeiling(value: number, name: SafeCeilingName, minimum?: number): SectileError | null;
|
|
14
15
|
export declare function normalizeMaxScan(maxScan: number | undefined): number | SectileError;
|
|
15
16
|
export declare function freezeArray<T>(values: readonly T[]): readonly T[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DEFAULT_MAX_ID_CODE_UNITS}from"../../shared.js";import{failResult as fail,okResult as ok}from"../../result.js";const safeCeilingErrorCodes=Object.freeze({columnCount:"invalid-column-count",count:"invalid-count",itemsPerPage:"invalid-items-per-page",maxCells:"invalid-max-cells",maxCodeUnits:"invalid-max-code-units",maxColumns:"invalid-max-columns",maxCount:"invalid-max-count",maxDecimalCodeUnits:"invalid-max-decimal-code-units",maxDepth:"invalid-max-depth",maxExponent:"invalid-max-exponent",maxIDCodeUnits:"invalid-max-id-code-units",maxItems:"invalid-max-items",maxOperations:"invalid-max-operations",maxRows:"invalid-max-rows",maxScale:"invalid-max-scale",maxTokens:"invalid-max-tokens",precision:"invalid-precision",siblingCount:"invalid-sibling-count",total:"invalid-total"});const canonicalOwners=new WeakMap;function bindCanonicalState(owner,state){canonicalOwners.set(state,owner);return state}function hasCanonicalState(owner,state){return canonicalOwners.get(state)===owner}function memoizeWeak(cache,key,create){const cached=cache.get(key);if(cached!==void 0)return cached;const value=create(key);cache.set(key,value);return value}function memoizeWeakPair(cache,owner,key,create){let owned=cache.get(owner);if(owned===void 0){owned=new WeakMap;cache.set(owner,owned)}const cached=owned.get(key);if(cached!==void 0)return cached;const value=create(owner,key);owned.set(key,value);return value}function resourceError(code,message,details){return{class:"resource-rejection",code,message,...details===void 0?{}:{details}}}function isWellFormedUTF16(value){for(let index=0;index<value.length;index+=1){const code=value.charCodeAt(index);if(code>=55296&&code<=56319){const next=value.charCodeAt(index+1);if(!(next>=56320&&next<=57343))return false;index+=1}else if(code>=56320&&code<=57343){return false}}return true}function validateStableID(id,maxIDCodeUnits=DEFAULT_MAX_ID_CODE_UNITS){if(typeof id!=="string"){return{class:"construction",code:"invalid-id-type",message:"Stable IDs must be strings.",details:{receivedType:typeof id}}}if(!Number.isSafeInteger(maxIDCodeUnits)||maxIDCodeUnits<1){return{class:"construction",code:"invalid-max-id-code-units",message:"maxIDCodeUnits must be a positive safe integer.",details:{maxIDCodeUnits}}}if(id.length===0){return{class:"construction",code:"empty-id",message:"Stable IDs must not be empty."}}if(!isWellFormedUTF16(id)){return{class:"construction",code:"ill-formed-id",message:"Stable IDs must be well-formed UTF-16 strings.",details:{id}}}if(id.length>maxIDCodeUnits){return{class:"resource-rejection",code:"id-code-unit-ceiling-exceeded",message:"Stable ID exceeds maxIDCodeUnits.",details:{idCodeUnits:id.length,maxIDCodeUnits}}}return null}function validateSafeCeiling(value,name,minimum=0){if(!Number.isSafeInteger(value)||value<minimum){return{class:"construction",code:safeCeilingErrorCodes[name],message:`${name} must be a safe integer greater than or equal to ${minimum}.`,details:{[name]:value}}}return null}function normalizeMaxScan(maxScan){if(maxScan===void 0)return Number.MAX_SAFE_INTEGER;if(!Number.isSafeInteger(maxScan)||maxScan<0){return resourceError("invalid-scan-ceiling","maxScan must be a non-negative safe integer.",{maxScan})}return maxScan}function freezeArray(values){return Object.freeze([...values])}function assertNever(value){throw new Error(`Internal invariant breach: unexpected value ${String(value)}`)}function validateUniqueIDs(ids,maxIDCodeUnits,indexByID){const snapshot=[];const seen=indexByID??new Map;for(let index=0;index<ids.length;index+=1){const id=ids[index];if(id===void 0){return fail("construction","invalid-id-type","Stable IDs must be strings.",{index})}const idError=validateStableID(id,maxIDCodeUnits);if(idError!==null)return{ok:false,error:idError};if(seen.has(id)){return fail("construction","duplicate-id","Stable identities must be unique.",{id,index})}seen.set(id,index);snapshot.push(id)}return ok(Object.freeze(snapshot))}export{assertNever,bindCanonicalState,fail,freezeArray,hasCanonicalState,isWellFormedUTF16,memoizeWeak,memoizeWeakPair,normalizeMaxScan,ok,resourceError,validateSafeCeiling,validateStableID,validateUniqueIDs};
|
|
1
|
+
import{DEFAULT_MAX_ID_CODE_UNITS}from"../../shared.js";import{failResult as fail,okResult as ok}from"../../result.js";const safeCeilingErrorCodes=Object.freeze({columnCount:"invalid-column-count",count:"invalid-count",itemsPerPage:"invalid-items-per-page",maxCells:"invalid-max-cells",maxCodeUnits:"invalid-max-code-units",maxColumns:"invalid-max-columns",maxCount:"invalid-max-count",maxDecimalCodeUnits:"invalid-max-decimal-code-units",maxDepth:"invalid-max-depth",maxExponent:"invalid-max-exponent",maxIDCodeUnits:"invalid-max-id-code-units",maxItems:"invalid-max-items",maxOperations:"invalid-max-operations",maxRows:"invalid-max-rows",maxScale:"invalid-max-scale",maxTokens:"invalid-max-tokens",precision:"invalid-precision",siblingCount:"invalid-sibling-count",total:"invalid-total"});const canonicalOwners=new WeakMap;function bindCanonicalState(owner,state){canonicalOwners.set(state,owner);return state}function hasCanonicalState(owner,state){return canonicalOwners.get(state)===owner}function memoizeWeak(cache,key,create){const cached=cache.get(key);if(cached!==void 0)return cached;const value=create(key);cache.set(key,value);return value}function memoizeWeakPair(cache,owner,key,create){let owned=cache.get(owner);if(owned===void 0){owned=new WeakMap;cache.set(owner,owned)}const cached=owned.get(key);if(cached!==void 0)return cached;const value=create(owner,key);owned.set(key,value);return value}function resourceError(code,message,details){return{class:"resource-rejection",code,message,...details===void 0?{}:{details}}}function isWellFormedUTF16(value){for(let index=0;index<value.length;index+=1){const code=value.charCodeAt(index);if(code>=55296&&code<=56319){const next=value.charCodeAt(index+1);if(!(next>=56320&&next<=57343))return false;index+=1}else if(code>=56320&&code<=57343){return false}}return true}function validateStableID(id,maxIDCodeUnits=DEFAULT_MAX_ID_CODE_UNITS){if(typeof id==="number"){if(Number.isSafeInteger(id)&&!Object.is(id,-0))return null;return{class:"construction",code:"invalid-id-type",message:"Numeric stable IDs must be safe integers other than negative zero.",details:{id}}}if(typeof id!=="string"){return{class:"construction",code:"invalid-id-type",message:"Stable IDs must be strings or safe integers.",details:{receivedType:typeof id}}}if(!Number.isSafeInteger(maxIDCodeUnits)||maxIDCodeUnits<1){return{class:"construction",code:"invalid-max-id-code-units",message:"maxIDCodeUnits must be a positive safe integer.",details:{maxIDCodeUnits}}}if(id.length===0){return{class:"construction",code:"empty-id",message:"Stable IDs must not be empty."}}if(!isWellFormedUTF16(id)){return{class:"construction",code:"ill-formed-id",message:"Stable IDs must be well-formed UTF-16 strings.",details:{id}}}if(id.length>maxIDCodeUnits){return{class:"resource-rejection",code:"id-code-unit-ceiling-exceeded",message:"Stable ID exceeds maxIDCodeUnits.",details:{idCodeUnits:id.length,maxIDCodeUnits}}}return null}function isStableID(value){return typeof value==="string"||typeof value==="number"&&Number.isSafeInteger(value)&&!Object.is(value,-0)}function validateSafeCeiling(value,name,minimum=0){if(!Number.isSafeInteger(value)||value<minimum){return{class:"construction",code:safeCeilingErrorCodes[name],message:`${name} must be a safe integer greater than or equal to ${minimum}.`,details:{[name]:value}}}return null}function normalizeMaxScan(maxScan){if(maxScan===void 0)return Number.MAX_SAFE_INTEGER;if(!Number.isSafeInteger(maxScan)||maxScan<0){return resourceError("invalid-scan-ceiling","maxScan must be a non-negative safe integer.",{maxScan})}return maxScan}function freezeArray(values){return Object.freeze([...values])}function assertNever(value){throw new Error(`Internal invariant breach: unexpected value ${String(value)}`)}function validateUniqueIDs(ids,maxIDCodeUnits,indexByID){const snapshot=[];const seen=indexByID??new Map;for(let index=0;index<ids.length;index+=1){const id=ids[index];if(id===void 0){return fail("construction","invalid-id-type","Stable IDs must be strings.",{index})}const idError=validateStableID(id,maxIDCodeUnits);if(idError!==null)return{ok:false,error:idError};if(seen.has(id)){return fail("construction","duplicate-id","Stable identities must be unique.",{id,index})}seen.set(id,index);snapshot.push(id)}return ok(Object.freeze(snapshot))}export{assertNever,bindCanonicalState,fail,freezeArray,hasCanonicalState,isStableID,isWellFormedUTF16,memoizeWeak,memoizeWeakPair,normalizeMaxScan,ok,resourceError,validateSafeCeiling,validateStableID,validateUniqueIDs};
|
|
2
2
|
//# sourceMappingURL=foundation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/kernel/foundation.ts"],"mappings":"AAAA,OACE,8BAIK,kBAEP,OAAS,cAAc,KAAM,YAAY,OAAU,kBAyBnD,MAAM,sBAA0E,OAAO,OAAO,CAC5F,YAAa,uBACb,MAAO,gBACP,aAAc,yBACd,SAAU,oBACV,aAAc,yBACd,WAAY,sBACZ,SAAU,oBACV,oBAAqB,iCACrB,SAAU,oBACV,YAAa,uBACb,eAAgB,4BAChB,SAAU,oBACV,cAAe,yBACf,QAAS,mBACT,SAAU,oBACV,UAAW,qBACX,UAAW,oBACX,aAAc,wBACd,MAAO,gBACR,EAED,MAAM,gBAAkB,IAAI,QAEtB,SAAU,mBAAyC,MAAe,MAAY,CAClF,gBAAgB,IAAI,MAAO,KAAK,EAChC,OAAO,KACT,CAEM,SAAU,kBAAkB,MAAe,MAAa,CAC5D,OAAO,gBAAgB,IAAI,KAAK,IAAM,KACxC,CAEM,SAAU,YACd,MACA,IACA,OAA2B,CAE3B,MAAM,OAAS,MAAM,IAAI,GAAG,EAC5B,GAAI,SAAW,OAAW,OAAO,OACjC,MAAM,MAAQ,OAAO,GAAG,EACxB,MAAM,IAAI,IAAK,KAAK,EACpB,OAAO,KACT,CAEM,SAAU,gBACd,MACA,MACA,IACA,OAAyC,CAEzC,IAAI,MAAQ,MAAM,IAAI,KAAK,EAC3B,GAAI,QAAU,OAAW,CACvB,MAAQ,IAAI,QACZ,MAAM,IAAI,MAAO,KAAK,CACxB,CACA,MAAM,OAAS,MAAM,IAAI,GAAG,EAC5B,GAAI,SAAW,OAAW,OAAO,OACjC,MAAM,MAAQ,OAAO,MAAO,GAAG,EAC/B,MAAM,IAAI,IAAK,KAAK,EACpB,OAAO,KACT,CAEM,SAAU,cACd,KACA,QACA,QAA2C,CAE3C,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,MAAM,KAAO,WAAa,IAAI,IAC9B,QAAS,MAAQ,EAAG,MAAQ,IAAI,OAAQ,OAAS,EAAG,CAClD,MAAM,GAAK,IAAI,KAAK,EACpB,GAAI,KAAO,OAAW,CACpB,OAAO,KAAK,eAAgB,kBAAmB,8BAA+B,CAAE,KAAK,CAAE,CACzF,CACA,MAAM,QAAU,iBAAiB,GAAI,cAAc,EACnD,GAAI,UAAY,KAAM,MAAO,CAAE,GAAI,MAAO,MAAO,OAAO,EACxD,GAAI,KAAK,IAAI,EAAE,EAAG,CAChB,OAAO,KAAK,eAAgB,eAAgB,oCAAqC,CAC/E,GACA,MACD,CACH,CACA,KAAK,IAAI,GAAI,KAAK,EAClB,SAAS,KAAK,EAAE,CAClB,CACA,OAAO,GAAG,OAAO,OAAO,QAAQ,CAAC,CACnC","names":[],"file":"foundation.js"}
|
|
@@ -53,5 +53,7 @@ export declare class PatchedSequence<ID extends StableID> implements SequenceVie
|
|
|
53
53
|
project(predicate: (id: ID, index: number) => boolean): IndexedSequence<ID>;
|
|
54
54
|
move(current: ID, direction: Direction, boundary?: BoundaryPolicy, options?: ScanOptions<ID>): MoveResult<ID>;
|
|
55
55
|
}
|
|
56
|
+
export declare function spliceSequenceArray<ID extends StableID>(ids: ID[], index: number, deleteCount: number, inserted: readonly ID[]): ID[];
|
|
57
|
+
export declare function moveSequenceArray<ID extends StableID>(ids: ID[], from: number, to: number, count: number): void;
|
|
56
58
|
export declare function moveInSequence<ID extends StableID>(sequence: Pick<SequenceView<ID>, 'size' | 'at' | 'indexOf'>, current: ID, direction: Direction, boundary: BoundaryPolicy, options: ScanOptions<ID>): MoveResult<ID>;
|
|
57
59
|
export declare function findEligibleFromEdge<ID extends StableID>(sequence: SequenceView<ID>, direction: Direction, options?: ScanOptions<ID>): Result<ID | null>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{}from"../../shared.js";import{freezeArray,normalizeMaxScan,ok,resourceError}from"./foundation.js";const MAX_PATCH_DEPTH=32;class IndexedSequence{ids;maxItems;maxIDCodeUnits;#index;constructor(ids,maxItems=1e5,maxIDCodeUnits=1024,index){this.ids=Object.isFrozen(ids)?ids:freezeArray(ids);this.maxItems=maxItems;this.maxIDCodeUnits=maxIDCodeUnits;if(index===void 0){const built=new Map;for(let position=0;position<this.ids.length;position+=1){const id=this.ids[position];if(id!==void 0)built.set(id,position)}this.#index=built}else{this.#index=index}Object.freeze(this)}get size(){return this.ids.length}at(index){return Number.isSafeInteger(index)&&index>=0&&index<this.ids.length?this.ids[index]??null:null}indexOf(id){return this.#index.get(id)??null}contains(id){return this.#index.has(id)}compare(left,right){const leftIndex=this.#index.get(left);const rightIndex=this.#index.get(right);if(leftIndex===void 0||rightIndex===void 0)return null;return leftIndex===rightIndex?0:leftIndex<rightIndex?-1:1}project(predicate){return new IndexedSequence(this.ids.filter(predicate),this.maxItems,this.maxIDCodeUnits)}move(current,direction,boundary="stop",options={}){return moveInSequence(this,current,direction,boundary,options)}}class PatchedSequence{size;maxItems;maxIDCodeUnits;depth;changedCardinality;#parent;#patch;#insertedIndex;#materialized=null;constructor(parent,patch,maxItems,maxIDCodeUnits,insertedIndex){this.#parent=parent instanceof PatchedSequence&&parent.depth>=MAX_PATCH_DEPTH?new IndexedSequence(parent.ids,parent.maxItems,parent.maxIDCodeUnits):parent;this.#patch=patch;this.size=patch.type==="splice"?this.#parent.size-patch.deleteCount+patch.inserted.length:this.#parent.size;this.maxItems=maxItems;this.maxIDCodeUnits=maxIDCodeUnits;this.depth=this.#parent instanceof PatchedSequence?this.#parent.depth+1:1;const localChanged=patch.type==="splice"?patch.deleteCount+patch.inserted.length:patch.count;this.changedCardinality=(this.#parent instanceof PatchedSequence?this.#parent.changedCardinality:0)+localChanged;if(patch.type==="splice"){if(insertedIndex!==void 0)this.#insertedIndex=insertedIndex;else{const built=new Map;for(let index=0;index<patch.inserted.length;index+=1){const id=patch.inserted[index];if(id!==void 0)built.set(id,index)}this.#insertedIndex=built}}else this.#insertedIndex=null;Object.freeze(this)}get ids(){if(this.#materialized!==null)return this.#materialized;this.#materialized=Object.freeze(this.copyIDs());return this.#materialized}copyIDs(){const patches=[];let base=this;while(base instanceof PatchedSequence){patches.push(base.#patch);base=base.#parent}
|
|
1
|
+
import{}from"../../shared.js";import{freezeArray,normalizeMaxScan,ok,resourceError}from"./foundation.js";const MAX_PATCH_DEPTH=32;const MAX_NATIVE_SPLICE_ITEMS=4096;class IndexedSequence{ids;maxItems;maxIDCodeUnits;#index;constructor(ids,maxItems=1e5,maxIDCodeUnits=1024,index){this.ids=Object.isFrozen(ids)?ids:freezeArray(ids);this.maxItems=maxItems;this.maxIDCodeUnits=maxIDCodeUnits;if(index===void 0){const built=new Map;for(let position=0;position<this.ids.length;position+=1){const id=this.ids[position];if(id!==void 0)built.set(id,position)}this.#index=built}else{this.#index=index}Object.freeze(this)}get size(){return this.ids.length}at(index){return Number.isSafeInteger(index)&&index>=0&&index<this.ids.length?this.ids[index]??null:null}indexOf(id){return this.#index.get(id)??null}contains(id){return this.#index.has(id)}compare(left,right){const leftIndex=this.#index.get(left);const rightIndex=this.#index.get(right);if(leftIndex===void 0||rightIndex===void 0)return null;return leftIndex===rightIndex?0:leftIndex<rightIndex?-1:1}project(predicate){return new IndexedSequence(this.ids.filter(predicate),this.maxItems,this.maxIDCodeUnits)}move(current,direction,boundary="stop",options={}){return moveInSequence(this,current,direction,boundary,options)}}class PatchedSequence{size;maxItems;maxIDCodeUnits;depth;changedCardinality;#parent;#patch;#insertedIndex;#materialized=null;constructor(parent,patch,maxItems,maxIDCodeUnits,insertedIndex){this.#parent=parent instanceof PatchedSequence&&parent.depth>=MAX_PATCH_DEPTH?new IndexedSequence(parent.ids,parent.maxItems,parent.maxIDCodeUnits):parent;this.#patch=patch;this.size=patch.type==="splice"?this.#parent.size-patch.deleteCount+patch.inserted.length:this.#parent.size;this.maxItems=maxItems;this.maxIDCodeUnits=maxIDCodeUnits;this.depth=this.#parent instanceof PatchedSequence?this.#parent.depth+1:1;const localChanged=patch.type==="splice"?patch.deleteCount+patch.inserted.length:patch.count;this.changedCardinality=(this.#parent instanceof PatchedSequence?this.#parent.changedCardinality:0)+localChanged;if(patch.type==="splice"){if(insertedIndex!==void 0)this.#insertedIndex=insertedIndex;else{const built=new Map;for(let index=0;index<patch.inserted.length;index+=1){const id=patch.inserted[index];if(id!==void 0)built.set(id,index)}this.#insertedIndex=built}}else this.#insertedIndex=null;Object.freeze(this)}get ids(){if(this.#materialized!==null)return this.#materialized;this.#materialized=Object.freeze(this.copyIDs());return this.#materialized}copyIDs(){const patches=[];let base=this;while(base instanceof PatchedSequence){patches.push(base.#patch);base=base.#parent}let ids=[...base.ids];for(let index=patches.length-1;index>=0;index-=1){const patch=patches[index];if(patch?.type==="splice"){ids=spliceSequenceArray(ids,patch.index,patch.deleteCount,patch.inserted)}else if(patch!==void 0&&patch.count>0&&patch.from!==patch.to){moveSequenceArray(ids,patch.from,patch.to,patch.count)}}return ids}at(index){if(!Number.isSafeInteger(index)||index<0||index>=this.size)return null;if(this.#patch.type==="splice"){const insertedEnd=this.#patch.index+this.#patch.inserted.length;if(index<this.#patch.index)return this.#parent.at(index);if(index<insertedEnd)return this.#patch.inserted[index-this.#patch.index]??null;return this.#parent.at(index-this.#patch.inserted.length+this.#patch.deleteCount)}return this.#parent.at(parentIndexForMove(index,this.#patch))}indexOf(id){if(this.#patch.type==="splice"){const inserted=this.#insertedIndex?.get(id);if(inserted!==void 0)return this.#patch.index+inserted;const previous2=this.#parent.indexOf(id);if(previous2===null)return null;const deletedEnd=this.#patch.index+this.#patch.deleteCount;if(previous2>=this.#patch.index&&previous2<deletedEnd)return null;return previous2<this.#patch.index?previous2:previous2-this.#patch.deleteCount+this.#patch.inserted.length}const previous=this.#parent.indexOf(id);return previous===null?null:movedIndex(previous,this.#patch)}contains(id){return this.indexOf(id)!==null}compare(left,right){const leftIndex=this.indexOf(left);const rightIndex=this.indexOf(right);if(leftIndex===null||rightIndex===null)return null;return leftIndex===rightIndex?0:leftIndex<rightIndex?-1:1}project(predicate){return new IndexedSequence(this.ids.filter(predicate),this.maxItems,this.maxIDCodeUnits)}move(current,direction,boundary="stop",options={}){return moveInSequence(this,current,direction,boundary,options)}}function spliceSequenceArray(ids,index,deleteCount,inserted){if(inserted.length<=MAX_NATIVE_SPLICE_ITEMS){ids.splice(index,deleteCount,...inserted);return ids}const next=new Array(ids.length-deleteCount+inserted.length);let write=0;for(;write<index;write+=1)next[write]=ids[write];for(let source=0;source<inserted.length;source+=1,write+=1){next[write]=inserted[source]}for(let source=index+deleteCount;source<ids.length;source+=1,write+=1){next[write]=ids[source]}return next}function moveSequenceArray(ids,from,to,count){if(count<=MAX_NATIVE_SPLICE_ITEMS){const moved2=ids.splice(from,count);ids.splice(to,0,...moved2);return}const moved=ids.slice(from,from+count);if(to<from)ids.copyWithin(to+count,to,from);else ids.copyWithin(from,from+count,to+count);for(let index=0;index<moved.length;index+=1)ids[to+index]=moved[index]}function parentIndexForMove(index,patch){if(patch.count===0||patch.from===patch.to)return index;const movedEnd=patch.to+patch.count;if(index>=patch.to&&index<movedEnd)return patch.from+index-patch.to;if(patch.to<patch.from){if(index>=movedEnd&&index<patch.from+patch.count)return index-patch.count;return index}if(index>=patch.from&&index<patch.to)return index+patch.count;return index}function movedIndex(index,patch){if(patch.count===0||patch.from===patch.to)return index;if(index>=patch.from&&index<patch.from+patch.count)return patch.to+index-patch.from;if(patch.to<patch.from){if(index>=patch.to&&index<patch.from)return index+patch.count;return index}const shiftedEnd=patch.to+patch.count;if(index>=patch.from+patch.count&&index<shiftedEnd)return index-patch.count;return index}function moveInSequence(sequence,current,direction,boundary,options){const currentIndex=sequence.indexOf(current);if(currentIndex===null)return{kind:"none",scanned:0};if(direction!==-1&&direction!==1)return invalidMovement("invalid-direction");if(boundary!=="stop"&&boundary!=="wrap")return invalidMovement("invalid-boundary");const normalized=normalizeMaxScan(options.maxScan);if(typeof normalized!=="number"){return{kind:"resource-rejected",scanned:0,error:normalized}}const eligible=options.eligible??(()=>true);const size=sequence.size;let scanned=0;let candidateIndex=currentIndex+direction;while(candidateIndex>=0&&candidateIndex<size){if(scanned===normalized)return scanRejected(scanned,normalized);const candidate=sequence.at(candidateIndex);scanned+=1;if(candidate!==null&&eligible(candidate)){return{kind:"found",id:candidate,scanned}}candidateIndex+=direction}if(boundary==="wrap"){candidateIndex=direction>0?0:size-1;while(candidateIndex!==currentIndex){if(scanned===normalized)return scanRejected(scanned,normalized);const candidate=sequence.at(candidateIndex);scanned+=1;if(candidate!==null&&eligible(candidate)){return{kind:"found",id:candidate,scanned}}candidateIndex+=direction}}return{kind:"none",scanned}}function findEligibleFromEdge(sequence,direction,options={}){const maxScan=normalizeMaxScan(options.maxScan);if(typeof maxScan!=="number")return{ok:false,error:maxScan};const eligible=options.eligible??(()=>true);let scanned=0;let index=direction>0?0:sequence.size-1;while(index>=0&&index<sequence.size){if(scanned===maxScan){return{ok:false,error:resourceError("scan-ceiling-reached","Movement reached maxScan before its semantic result was determined.",{maxScan})}}const id=sequence.at(index);scanned+=1;if(id!==null&&eligible(id))return ok(id);index+=direction}return ok(null)}function scanRejected(scanned,maxScan){return{kind:"resource-rejected",scanned,error:resourceError("scan-ceiling-reached","Movement reached maxScan before its semantic result was determined.",{maxScan})}}function invalidMovement(code){const error={class:"internal-invariant",code,message:"Movement received an impossible runtime value."};return{kind:"resource-rejected",scanned:0,error}}export{IndexedSequence,PatchedSequence,findEligibleFromEdge,moveInSequence,moveSequenceArray,spliceSequenceArray};
|
|
2
2
|
//# sourceMappingURL=indexed-sequence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/kernel/indexed-sequence.ts"],"mappings":"AAAA,YAQO,kBACP,OAAS,YAAa,iBAAkB,GAAI,kBAAqB,kBAkCjE,MAAM,gBAAkB,
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/kernel/indexed-sequence.ts"],"mappings":"AAAA,YAQO,kBACP,OAAS,YAAa,iBAAkB,GAAI,kBAA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ACnE,MAAM,SAAW,QAAQ,WAAa,IAAM,MAC5C,IAAI,QAAU,EACd,IAAI,MAAQ,UAAY,EAAI,EAAI,SAAS,KAAO,EAEhD,MAAO,OAAS,GAAK,MAAQ,SAAS,KAAM,CAC1C,GAAI,UAAY,QAAS,CACvB,MAAO,CACL,GAAI,MACJ,MAAO,cACL,uBACA,sEACA,CAAE,OAAO,CAAE,EAGjB,CACA,MAAM,GAAK,SAAS,GAAG,KAAK,EAC5B,SAAW,EACX,GAAI,KAAO,MAAQ,SAAS,EAAE,EAAG,OAAO,GAAG,EAAE,EAC7C,OAAS,SACX,CACA,OAAO,GAAG,IAAI,CAChB,CAEA,SAAS,aAAkC,QAAiB,QAAe,CACzE,MAAO,CACL,KAAM,oBACN,QACA,MAAO,cACL,uBACA,sEACA,CAAE,OAAO,CAAE,EAGjB,CAEA,SAAS,gBACP,KAA8C,CAE9C,MAAM,MAAsB,CAC1B,MAAO,qBACP,KACA,QAAS,kDAEX,MAAO,CAAE,KAAM,oBAAqB,QAAS,EAAG,KAAK,CACvD","names":["previous","moved"],"file":"indexed-sequence.js"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Shared public contracts for the canonical Sectile structures. */
|
|
2
2
|
import type { CoreErrorCode } from './error-code.js';
|
|
3
|
-
export type StableID = string;
|
|
3
|
+
export type StableID = string | number;
|
|
4
4
|
export type ErrorClass = 'construction' | 'transition-rejection' | 'resource-rejection' | 'internal-invariant';
|
|
5
5
|
export interface SectileError<Code extends string = CoreErrorCode> {
|
|
6
6
|
readonly class: ErrorClass;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{unwrap}from"../result.js";import{DEFAULT_MAX_ID_CODE_UNITS}from"../shared.js";import{fail,ok,validateSafeCeiling,validateUniqueIDs}from"../internal/kernel/foundation.js";import{IndexedSequence,PatchedSequence}from"../internal/kernel/indexed-sequence.js";function createSequence(ids,options={}){return unwrap(tryCreateSequence(ids,options))}function tryCreateSequence(ids,options={}){const maxItems=options.maxItems??1e5;const ceilingError=validateSafeCeiling(maxItems,"maxItems");if(ceilingError!==null)return{ok:false,error:ceilingError};const maxIDCodeUnits=options.maxIDCodeUnits??DEFAULT_MAX_ID_CODE_UNITS;const idCeilingError=validateSafeCeiling(maxIDCodeUnits,"maxIDCodeUnits",1);if(idCeilingError!==null)return{ok:false,error:idCeilingError};if(ids.length>maxItems){return fail("resource-rejection","item-ceiling-exceeded","Sequence exceeds maxItems.",{size:ids.length,maxItems})}const index=new Map;const validated=validateUniqueIDs(ids,maxIDCodeUnits,index);if(!validated.ok)return validated;return ok(new IndexedSequence(validated.value,maxItems,maxIDCodeUnits,index))}function applySequencePatch(sequence,patch,options={}){return unwrap(tryApplySequencePatch(sequence,patch,options))}function tryApplySequencePatch(sequence,patch,options={}){const maxItems=options.maxItems??sequence.maxItems;const ceilingError=validateSafeCeiling(maxItems,"maxItems");if(ceilingError!==null)return{ok:false,error:ceilingError};const maxIDCodeUnits=options.maxIDCodeUnits??sequence.maxIDCodeUnits;const idCeilingError=validateSafeCeiling(maxIDCodeUnits,"maxIDCodeUnits",1);if(idCeilingError!==null)return{ok:false,error:idCeilingError};const size=sequence.size;if(maxIDCodeUnits<sequence.maxIDCodeUnits){return applyMaterializedSequencePatch(sequence,patch,maxItems,maxIDCodeUnits)}if(patch.type==="splice"){if(!Number.isSafeInteger(patch.index)||!Number.isSafeInteger(patch.deleteCount)||patch.index<0||patch.deleteCount<0||patch.index>size||patch.deleteCount>size-patch.index)return invalidPatch(patch,size);const nextSize=size-patch.deleteCount+patch.inserted.length;if(nextSize>maxItems){return fail("resource-rejection","item-ceiling-exceeded","Sequence exceeds maxItems.",{size:nextSize,maxItems})}if(patch.deleteCount===0&&patch.inserted.length===0)return ok(sequence);const insertedIndex=new Map;const inserted=validateUniqueIDs(patch.inserted,maxIDCodeUnits,insertedIndex);if(!inserted.ok){return fail("transition-rejection",inserted.error.code,inserted.error.message,inserted.error.details)}const deletedEnd=patch.index+patch.deleteCount;for(let index=0;index<inserted.value.length;index+=1){const id=inserted.value[index];const previousIndex=sequence.indexOf(id);if(previousIndex!==null&&(previousIndex<patch.index||previousIndex>=deletedEnd)){return fail("transition-rejection","duplicate-id","Stable identities must be unique.",{id,index:patch.index+index})}}if(shouldMaterializeSequencePatch(sequence,patch.deleteCount+inserted.value.length,nextSize)){return applyMaterializedSequencePatch(sequence,Object.freeze({...patch,inserted:inserted.value}),maxItems,maxIDCodeUnits)}return ok(new PatchedSequence(sequence,Object.freeze({...patch,inserted:inserted.value}),maxItems,maxIDCodeUnits,insertedIndex))}else{if(!Number.isSafeInteger(patch.from)||!Number.isSafeInteger(patch.to)||!Number.isSafeInteger(patch.count)||patch.from<0||patch.count<0||patch.from>size||patch.count>size-patch.from||patch.to<0||patch.to>size-patch.count)return invalidPatch(patch,size);if(patch.count===0||patch.from===patch.to)return ok(sequence);if(shouldMaterializeSequencePatch(sequence,patch.count,size)){return applyMaterializedSequencePatch(sequence,patch,maxItems,maxIDCodeUnits)}return ok(new PatchedSequence(sequence,Object.freeze({...patch}),maxItems,maxIDCodeUnits))}}function shouldMaterializeSequencePatch(sequence,changedCardinality,nextSize){const previousChanged=sequence instanceof PatchedSequence?sequence.changedCardinality:0;return previousChanged+changedCardinality>nextSize/8}function applyMaterializedSequencePatch(sequence,patch,maxItems,maxIDCodeUnits){
|
|
1
|
+
import{unwrap}from"../result.js";import{DEFAULT_MAX_ID_CODE_UNITS}from"../shared.js";import{fail,ok,validateSafeCeiling,validateUniqueIDs}from"../internal/kernel/foundation.js";import{IndexedSequence,moveSequenceArray,PatchedSequence,spliceSequenceArray}from"../internal/kernel/indexed-sequence.js";function createSequence(ids,options={}){return unwrap(tryCreateSequence(ids,options))}function tryCreateSequence(ids,options={}){const maxItems=options.maxItems??1e5;const ceilingError=validateSafeCeiling(maxItems,"maxItems");if(ceilingError!==null)return{ok:false,error:ceilingError};const maxIDCodeUnits=options.maxIDCodeUnits??DEFAULT_MAX_ID_CODE_UNITS;const idCeilingError=validateSafeCeiling(maxIDCodeUnits,"maxIDCodeUnits",1);if(idCeilingError!==null)return{ok:false,error:idCeilingError};if(ids.length>maxItems){return fail("resource-rejection","item-ceiling-exceeded","Sequence exceeds maxItems.",{size:ids.length,maxItems})}const index=new Map;const validated=validateUniqueIDs(ids,maxIDCodeUnits,index);if(!validated.ok)return validated;return ok(new IndexedSequence(validated.value,maxItems,maxIDCodeUnits,index))}function applySequencePatch(sequence,patch,options={}){return unwrap(tryApplySequencePatch(sequence,patch,options))}function tryApplySequencePatch(sequence,patch,options={}){const maxItems=options.maxItems??sequence.maxItems;const ceilingError=validateSafeCeiling(maxItems,"maxItems");if(ceilingError!==null)return{ok:false,error:ceilingError};const maxIDCodeUnits=options.maxIDCodeUnits??sequence.maxIDCodeUnits;const idCeilingError=validateSafeCeiling(maxIDCodeUnits,"maxIDCodeUnits",1);if(idCeilingError!==null)return{ok:false,error:idCeilingError};const size=sequence.size;if(maxIDCodeUnits<sequence.maxIDCodeUnits){return applyMaterializedSequencePatch(sequence,patch,maxItems,maxIDCodeUnits)}if(patch.type==="splice"){if(!Number.isSafeInteger(patch.index)||!Number.isSafeInteger(patch.deleteCount)||patch.index<0||patch.deleteCount<0||patch.index>size||patch.deleteCount>size-patch.index)return invalidPatch(patch,size);const nextSize=size-patch.deleteCount+patch.inserted.length;if(nextSize>maxItems){return fail("resource-rejection","item-ceiling-exceeded","Sequence exceeds maxItems.",{size:nextSize,maxItems})}if(patch.deleteCount===0&&patch.inserted.length===0)return ok(sequence);const insertedIndex=new Map;const inserted=validateUniqueIDs(patch.inserted,maxIDCodeUnits,insertedIndex);if(!inserted.ok){return fail("transition-rejection",inserted.error.code,inserted.error.message,inserted.error.details)}const deletedEnd=patch.index+patch.deleteCount;for(let index=0;index<inserted.value.length;index+=1){const id=inserted.value[index];const previousIndex=sequence.indexOf(id);if(previousIndex!==null&&(previousIndex<patch.index||previousIndex>=deletedEnd)){return fail("transition-rejection","duplicate-id","Stable identities must be unique.",{id,index:patch.index+index})}}if(shouldMaterializeSequencePatch(sequence,patch.deleteCount+inserted.value.length,nextSize)){return applyMaterializedSequencePatch(sequence,Object.freeze({...patch,inserted:inserted.value}),maxItems,maxIDCodeUnits)}return ok(new PatchedSequence(sequence,Object.freeze({...patch,inserted:inserted.value}),maxItems,maxIDCodeUnits,insertedIndex))}else{if(!Number.isSafeInteger(patch.from)||!Number.isSafeInteger(patch.to)||!Number.isSafeInteger(patch.count)||patch.from<0||patch.count<0||patch.from>size||patch.count>size-patch.from||patch.to<0||patch.to>size-patch.count)return invalidPatch(patch,size);if(patch.count===0||patch.from===patch.to)return ok(sequence);if(shouldMaterializeSequencePatch(sequence,patch.count,size)){return applyMaterializedSequencePatch(sequence,patch,maxItems,maxIDCodeUnits)}return ok(new PatchedSequence(sequence,Object.freeze({...patch}),maxItems,maxIDCodeUnits))}}function shouldMaterializeSequencePatch(sequence,changedCardinality,nextSize){const previousChanged=sequence instanceof PatchedSequence?sequence.changedCardinality:0;return previousChanged+changedCardinality>nextSize/8}function applyMaterializedSequencePatch(sequence,patch,maxItems,maxIDCodeUnits){let ids=sequence instanceof PatchedSequence?sequence.copyIDs():[...sequence.ids];if(patch.type==="splice"){if(!Number.isSafeInteger(patch.index)||!Number.isSafeInteger(patch.deleteCount)||patch.index<0||patch.deleteCount<0||patch.index>ids.length||patch.deleteCount>ids.length-patch.index)return invalidPatch(patch,ids.length);ids=spliceSequenceArray(ids,patch.index,patch.deleteCount,patch.inserted)}else{if(!Number.isSafeInteger(patch.from)||!Number.isSafeInteger(patch.to)||!Number.isSafeInteger(patch.count)||patch.from<0||patch.count<0||patch.from>ids.length||patch.count>ids.length-patch.from||patch.to<0||patch.to>ids.length-patch.count)return invalidPatch(patch,ids.length);if(patch.count===0||patch.from===patch.to)return ok(sequence);moveSequenceArray(ids,patch.from,patch.to,patch.count)}const result=tryCreateSequence(ids,{maxItems,maxIDCodeUnits});if(result.ok)return result;return fail("transition-rejection",result.error.code,result.error.message,result.error.details)}function invalidPatch(patch,size){return fail("transition-rejection","sequence-patch-invalid","Sequence patch must identify a valid post-removal destination and source range.",{patch,size})}export{applySequencePatch,createSequence,tryApplySequencePatch,tryCreateSequence};
|
|
2
2
|
//# sourceMappingURL=sequence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/structures/sequence.ts"],"mappings":"AAAA,OAAS,WAAc,eACvB,OACE,8BAQK,eACP,OAAS,KAAM,GAAI,oBAAqB,sBAAyB,mCACjE,OACE,gBACA,
|
|
1
|
+
{"version":3,"sources":["../../src/structures/sequence.ts"],"mappings":"AAAA,OAAS,WAAc,eACvB,OACE,8BAQK,eACP,OAAS,KAAM,GAAI,oBAAqB,sBAAyB,mCACjE,OACE,gBACA,kBACA,gBACA,wBAEK,yCAwCD,SAAU,eACd,IACA,QAA2B,CAAA,EAAE,CAE7B,OAAO,OAAO,kBAAkB,IAAK,OAAO,CAAC,CAC/C,CAEM,SAAU,kBACd,IACA,QAA2B,CAAA,EAAE,CAE7B,MAAM,SAAW,QAAQ,UAAY,IACrC,MAAM,aAAe,oBAAoB,SAAU,UAAU,EAC7D,GAAI,eAAiB,KAAM,MAAO,CAAE,GAAI,MAAO,MAAO,YAAY,EAClE,MAAM,eAAiB,QAAQ,gBAAkB,0BACjD,MAAM,eAAiB,oBAAoB,eAAgB,iBAAkB,CAAC,EAC9E,GAAI,iBAAmB,KAAM,MAAO,CAAE,GAAI,MAAO,MAAO,cAAc,EACtE,GAAI,IAAI,OAAS,SAAU,CACzB,OAAO,KAAK,qBAAsB,wBAAyB,6BAA8B,CACvF,KAAM,IAAI,OACV,SACD,CACH,CACA,MAAM,MAAQ,IAAI,IAClB,MAAM,UAAY,kBAAkB,IAAK,eAAgB,KAAK,EAC9D,GAAI,CAAC,UAAU,GAAI,OAAO,UAC1B,OAAO,GACL,IAAI,gBACF,UAAU,MACV,SACA,eACA,KAAK,CACc,CAEzB,CAEM,SAAU,mBACd,SACA,MACA,QAA2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+
import type { Result } from './shared.js';
|
|
2
2
|
import { type DecimalRounding } from './internal/kernel/decimal.js';
|
|
3
|
-
export type UnitID =
|
|
3
|
+
export type UnitID = string;
|
|
4
4
|
export type Dimension = Readonly<Record<string, number>>;
|
|
5
5
|
export interface UnitRatio {
|
|
6
6
|
readonly numerator: string;
|
|
@@ -55,11 +55,11 @@ export interface UnitSystemPreferenceDefinition {
|
|
|
55
55
|
readonly units: readonly UnitID[];
|
|
56
56
|
}
|
|
57
57
|
export interface UnitSystemDefinition {
|
|
58
|
-
readonly id:
|
|
58
|
+
readonly id: string;
|
|
59
59
|
readonly preferences: readonly UnitSystemPreferenceDefinition[];
|
|
60
60
|
}
|
|
61
61
|
export interface UnitSystemProfile {
|
|
62
|
-
readonly id:
|
|
62
|
+
readonly id: string;
|
|
63
63
|
getDefaultUnit(canonicalUnit: UnitID): UnitID | null;
|
|
64
64
|
getUnits(canonicalUnit: UnitID): readonly UnitID[];
|
|
65
65
|
}
|