@portabletext/plugin-typeahead-picker 5.0.26 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +590 -597
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
package/dist/index.js
CHANGED
|
@@ -113,9 +113,7 @@ function createTriggerActions({
|
|
|
113
113
|
text: `${newSpan.text}${payload.nextSpan?.node.text ?? payload.focusSpanTextAfter}`,
|
|
114
114
|
marks: payload.markState.marks
|
|
115
115
|
},
|
|
116
|
-
path: [{
|
|
117
|
-
_key: payload.focusSpan.path[0]._key
|
|
118
|
-
}, "children", {
|
|
116
|
+
path: [...payload.focusSpan.path.slice(0, -2), "children", {
|
|
119
117
|
_key: newSpan._key
|
|
120
118
|
}],
|
|
121
119
|
textBefore: "",
|
|
@@ -626,620 +624,617 @@ const triggerListenerCallback = () => ({
|
|
|
626
624
|
}), ...selectActions];
|
|
627
625
|
}]
|
|
628
626
|
})
|
|
629
|
-
})
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
const focusSpan = event.focusSpan, patternText = extractPatternTextFromFocusSpan(focusSpan), keyword = event.extractedKeyword;
|
|
671
|
-
if (context.definition.mode === "async" || context.definition.debounceMs)
|
|
672
|
-
return {
|
|
673
|
-
focusSpan,
|
|
674
|
-
patternText,
|
|
675
|
-
keyword,
|
|
676
|
-
isLoading: !0,
|
|
677
|
-
selectedIndex: 0
|
|
678
|
-
};
|
|
679
|
-
const matches = context.definition.getMatches({
|
|
680
|
-
keyword
|
|
681
|
-
});
|
|
627
|
+
}), typeaheadPickerMachine = setup({
|
|
628
|
+
types: {
|
|
629
|
+
context: {},
|
|
630
|
+
input: {},
|
|
631
|
+
events: {}
|
|
632
|
+
},
|
|
633
|
+
delays: {
|
|
634
|
+
DEBOUNCE: ({
|
|
635
|
+
context
|
|
636
|
+
}) => context.definition.debounceMs ?? 0
|
|
637
|
+
},
|
|
638
|
+
actors: {
|
|
639
|
+
"trigger listener": fromCallback(triggerListenerCallback()),
|
|
640
|
+
"escape listener": fromCallback(escapeListenerCallback()),
|
|
641
|
+
"arrow listener": fromCallback(arrowListenerCallback()),
|
|
642
|
+
"selection listener": fromCallback(selectionListenerCallback()),
|
|
643
|
+
"submit listener": fromCallback(submitListenerCallback()),
|
|
644
|
+
"text insertion listener": fromCallback(textInsertionListenerCallback()),
|
|
645
|
+
"select match listener": fromCallback(selectMatchListenerCallback()),
|
|
646
|
+
"dismiss listener": fromCallback(dismissListenerCallback()),
|
|
647
|
+
"get matches": fromPromise(async ({
|
|
648
|
+
input
|
|
649
|
+
}) => {
|
|
650
|
+
const result = input.getMatches({
|
|
651
|
+
keyword: input.keyword
|
|
652
|
+
}), matches = await Promise.resolve(result);
|
|
653
|
+
return {
|
|
654
|
+
keyword: input.keyword,
|
|
655
|
+
matches
|
|
656
|
+
};
|
|
657
|
+
})
|
|
658
|
+
},
|
|
659
|
+
actions: {
|
|
660
|
+
"handle trigger found": assign(({
|
|
661
|
+
context,
|
|
662
|
+
event
|
|
663
|
+
}) => {
|
|
664
|
+
if (event.type !== "custom.typeahead trigger found" && event.type !== "custom.typeahead keyword found")
|
|
665
|
+
return {};
|
|
666
|
+
const focusSpan = event.focusSpan, patternText = extractPatternTextFromFocusSpan(focusSpan), keyword = event.extractedKeyword;
|
|
667
|
+
if (context.definition.mode === "async" || context.definition.debounceMs)
|
|
682
668
|
return {
|
|
683
669
|
focusSpan,
|
|
684
670
|
patternText,
|
|
685
671
|
keyword,
|
|
686
|
-
|
|
687
|
-
requestedKeyword: keyword,
|
|
688
|
-
isLoading: !1,
|
|
672
|
+
isLoading: !0,
|
|
689
673
|
selectedIndex: 0
|
|
690
674
|
};
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
675
|
+
const matches = context.definition.getMatches({
|
|
676
|
+
keyword
|
|
677
|
+
});
|
|
678
|
+
return {
|
|
679
|
+
focusSpan,
|
|
680
|
+
patternText,
|
|
681
|
+
keyword,
|
|
682
|
+
matches,
|
|
683
|
+
requestedKeyword: keyword,
|
|
684
|
+
isLoading: !1,
|
|
685
|
+
selectedIndex: 0
|
|
686
|
+
};
|
|
687
|
+
}),
|
|
688
|
+
"handle selection changed": assign(({
|
|
689
|
+
context
|
|
690
|
+
}) => {
|
|
691
|
+
if (!context.focusSpan)
|
|
692
|
+
return {
|
|
693
|
+
focusSpan: void 0
|
|
694
|
+
};
|
|
695
|
+
const snapshot = context.editor.getSnapshot(), currentFocusSpan = getFocusSpan(snapshot);
|
|
696
|
+
if (!snapshot.context.selection || !currentFocusSpan)
|
|
697
|
+
return {
|
|
698
|
+
focusSpan: void 0
|
|
699
|
+
};
|
|
700
|
+
const nextSpan = getNextSpan({
|
|
701
|
+
...snapshot,
|
|
702
|
+
context: {
|
|
703
|
+
...snapshot.context,
|
|
704
|
+
selection: {
|
|
705
|
+
anchor: {
|
|
706
|
+
path: context.focusSpan.path,
|
|
707
|
+
offset: 0
|
|
708
|
+
},
|
|
709
|
+
focus: {
|
|
710
|
+
path: context.focusSpan.path,
|
|
711
|
+
offset: 0
|
|
717
712
|
}
|
|
718
713
|
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
focusSpan,
|
|
752
|
-
patternText,
|
|
753
|
-
keyword,
|
|
754
|
-
selectedIndex: patternText !== context.patternText ? 0 : context.selectedIndex,
|
|
755
|
-
isLoading: context.isLoading || context.requestedKeyword !== keyword
|
|
756
|
-
};
|
|
757
|
-
const matches = context.definition.getMatches({
|
|
758
|
-
keyword
|
|
759
|
-
});
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
if (!isEqualPaths(currentFocusSpan.path, context.focusSpan.path))
|
|
717
|
+
return nextSpan && context.focusSpan.textAfter.length === 0 && snapshot.context.selection.focus.offset === 0 && isSelectionCollapsed(snapshot) ? {} : {
|
|
718
|
+
focusSpan: void 0
|
|
719
|
+
};
|
|
720
|
+
if (!currentFocusSpan.node.text.startsWith(context.focusSpan.textBefore))
|
|
721
|
+
return {
|
|
722
|
+
focusSpan: void 0
|
|
723
|
+
};
|
|
724
|
+
if (!currentFocusSpan.node.text.endsWith(context.focusSpan.textAfter))
|
|
725
|
+
return {
|
|
726
|
+
focusSpan: void 0
|
|
727
|
+
};
|
|
728
|
+
const keywordAnchor = {
|
|
729
|
+
path: currentFocusSpan.path,
|
|
730
|
+
offset: context.focusSpan.textBefore.length
|
|
731
|
+
}, keywordFocus = {
|
|
732
|
+
path: currentFocusSpan.path,
|
|
733
|
+
offset: currentFocusSpan.node.text.length - context.focusSpan.textAfter.length
|
|
734
|
+
}, selectionIsBeforeKeyword = isPointAfterSelection(keywordAnchor)(snapshot), selectionIsAfterKeyword = isPointBeforeSelection(keywordFocus)(snapshot);
|
|
735
|
+
if (selectionIsBeforeKeyword || selectionIsAfterKeyword)
|
|
736
|
+
return {
|
|
737
|
+
focusSpan: void 0
|
|
738
|
+
};
|
|
739
|
+
const focusSpan = {
|
|
740
|
+
node: currentFocusSpan.node,
|
|
741
|
+
path: currentFocusSpan.path,
|
|
742
|
+
textBefore: context.focusSpan.textBefore,
|
|
743
|
+
textAfter: context.focusSpan.textAfter
|
|
744
|
+
}, patternText = extractPatternTextFromFocusSpan(focusSpan), keyword = extractKeyword(patternText, context.triggerPattern, context.definition.delimiter, context.completePattern);
|
|
745
|
+
if (context.definition.mode === "async" || context.definition.debounceMs)
|
|
760
746
|
return {
|
|
761
747
|
focusSpan,
|
|
762
748
|
patternText,
|
|
763
749
|
keyword,
|
|
764
|
-
matches,
|
|
765
|
-
requestedKeyword: keyword,
|
|
766
750
|
selectedIndex: patternText !== context.patternText ? 0 : context.selectedIndex,
|
|
767
|
-
isLoading:
|
|
768
|
-
};
|
|
769
|
-
}),
|
|
770
|
-
"handle async load complete": assign(({
|
|
771
|
-
context,
|
|
772
|
-
event
|
|
773
|
-
}) => {
|
|
774
|
-
const output = event.output;
|
|
775
|
-
return output.keyword !== context.keyword ? {
|
|
776
|
-
isLoading: context.keyword !== context.requestedKeyword
|
|
777
|
-
} : {
|
|
778
|
-
matches: output.matches,
|
|
779
|
-
isLoading: context.keyword !== context.requestedKeyword
|
|
751
|
+
isLoading: context.isLoading || context.requestedKeyword !== keyword
|
|
780
752
|
};
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
753
|
+
const matches = context.definition.getMatches({
|
|
754
|
+
keyword
|
|
755
|
+
});
|
|
756
|
+
return {
|
|
757
|
+
focusSpan,
|
|
758
|
+
patternText,
|
|
759
|
+
keyword,
|
|
760
|
+
matches,
|
|
761
|
+
requestedKeyword: keyword,
|
|
762
|
+
selectedIndex: patternText !== context.patternText ? 0 : context.selectedIndex,
|
|
763
|
+
isLoading: !1
|
|
764
|
+
};
|
|
765
|
+
}),
|
|
766
|
+
"handle async load complete": assign(({
|
|
767
|
+
context,
|
|
768
|
+
event
|
|
769
|
+
}) => {
|
|
770
|
+
const output = event.output;
|
|
771
|
+
return output.keyword !== context.keyword ? {
|
|
772
|
+
isLoading: context.keyword !== context.requestedKeyword
|
|
801
773
|
} : {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
if (!context.focusSpan)
|
|
808
|
-
return;
|
|
809
|
-
const match = params.exact ? getFirstExactMatch(context.matches) : context.matches[context.selectedIndex];
|
|
810
|
-
match && context.editor.send({
|
|
811
|
-
type: "custom.typeahead select match",
|
|
812
|
-
match,
|
|
813
|
-
focusSpan: context.focusSpan,
|
|
814
|
-
keyword: context.keyword,
|
|
815
|
-
pickerId: context.definition._id
|
|
816
|
-
});
|
|
817
|
-
},
|
|
818
|
-
"update submit listener context": sendTo("submit listener", ({
|
|
819
|
-
context
|
|
820
|
-
}) => ({
|
|
821
|
-
type: "context changed",
|
|
822
|
-
context
|
|
823
|
-
})),
|
|
824
|
-
"update text insertion listener context": sendTo("text insertion listener", ({
|
|
825
|
-
context
|
|
826
|
-
}) => ({
|
|
827
|
-
type: "context changed",
|
|
828
|
-
context
|
|
829
|
-
})),
|
|
830
|
-
"update escape listener context": sendTo("escape listener", ({
|
|
831
|
-
context
|
|
832
|
-
}) => ({
|
|
833
|
-
type: "context changed",
|
|
834
|
-
context
|
|
835
|
-
})),
|
|
836
|
-
"update request dismiss listener context": sendTo("dismiss listener", ({
|
|
837
|
-
context
|
|
838
|
-
}) => ({
|
|
839
|
-
type: "context changed",
|
|
840
|
-
context
|
|
841
|
-
})),
|
|
842
|
-
"handle error": assign({
|
|
843
|
-
isLoading: !1,
|
|
844
|
-
error: ({
|
|
845
|
-
event
|
|
846
|
-
}) => event.error
|
|
847
|
-
})
|
|
848
|
-
},
|
|
849
|
-
guards: {
|
|
850
|
-
"no focus span": ({
|
|
851
|
-
context
|
|
852
|
-
}) => !context.focusSpan,
|
|
853
|
-
"invalid pattern": ({
|
|
854
|
-
context
|
|
855
|
-
}) => {
|
|
856
|
-
if (!context.patternText)
|
|
857
|
-
return !0;
|
|
858
|
-
const triggerMatch = context.patternText.match(context.triggerPattern);
|
|
859
|
-
if (triggerMatch && triggerMatch.index === 0 && triggerMatch[0] === context.patternText)
|
|
860
|
-
return !1;
|
|
861
|
-
const partialMatch = context.patternText.match(context.partialPattern);
|
|
862
|
-
if (partialMatch && partialMatch.index === 0 && partialMatch[0] === context.patternText)
|
|
863
|
-
return !1;
|
|
864
|
-
if (context.completePattern) {
|
|
865
|
-
const completeMatch = context.patternText.match(context.completePattern);
|
|
866
|
-
if (completeMatch && completeMatch.index === 0 && completeMatch[0] === context.patternText)
|
|
867
|
-
return !1;
|
|
868
|
-
}
|
|
869
|
-
return !0;
|
|
870
|
-
},
|
|
871
|
-
"no debounce": ({
|
|
872
|
-
context
|
|
873
|
-
}) => !context.definition.debounceMs || context.definition.debounceMs === 0,
|
|
874
|
-
"is complete keyword": ({
|
|
875
|
-
context
|
|
876
|
-
}) => {
|
|
877
|
-
if (!context.completePattern || !context.focusSpan)
|
|
878
|
-
return !1;
|
|
879
|
-
const fullKeywordText = context.focusSpan.node.text.slice(context.focusSpan.textBefore.length, context.focusSpan.textAfter.length > 0 ? -context.focusSpan.textAfter.length : void 0), completeMatch = fullKeywordText.match(context.completePattern);
|
|
880
|
-
return !completeMatch || completeMatch.index !== 0 || completeMatch[0] !== fullKeywordText ? !1 : hasAtLeastOneExactMatch(context.matches);
|
|
881
|
-
},
|
|
882
|
-
"has matches": ({
|
|
883
|
-
context
|
|
884
|
-
}) => context.matches.length > 0,
|
|
885
|
-
"no matches": ({
|
|
886
|
-
context
|
|
887
|
-
}) => context.matches.length === 0,
|
|
888
|
-
"is loading": ({
|
|
889
|
-
context
|
|
890
|
-
}) => context.isLoading
|
|
891
|
-
}
|
|
892
|
-
}).createMachine({
|
|
893
|
-
id: "typeahead picker",
|
|
894
|
-
context: ({
|
|
895
|
-
input
|
|
896
|
-
}) => ({
|
|
897
|
-
editor: input.editor,
|
|
898
|
-
definition: input.definition,
|
|
899
|
-
triggerPattern: buildTriggerPattern(input.definition),
|
|
900
|
-
partialPattern: buildPartialPattern(input.definition),
|
|
901
|
-
completePattern: buildCompletePattern(input.definition),
|
|
902
|
-
matches: [],
|
|
903
|
-
selectedIndex: 0,
|
|
904
|
-
focusSpan: void 0,
|
|
774
|
+
matches: output.matches,
|
|
775
|
+
isLoading: context.keyword !== context.requestedKeyword
|
|
776
|
+
};
|
|
777
|
+
}),
|
|
778
|
+
reset: assign({
|
|
905
779
|
patternText: "",
|
|
906
780
|
keyword: "",
|
|
781
|
+
matches: [],
|
|
782
|
+
selectedIndex: 0,
|
|
783
|
+
isLoading: !1,
|
|
907
784
|
requestedKeyword: "",
|
|
908
|
-
|
|
909
|
-
|
|
785
|
+
focusSpan: void 0,
|
|
786
|
+
error: void 0
|
|
910
787
|
}),
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
788
|
+
navigate: assign(({
|
|
789
|
+
context,
|
|
790
|
+
event
|
|
791
|
+
}) => context.matches.length === 0 ? {
|
|
792
|
+
selectedIndex: 0
|
|
793
|
+
} : event.type === "navigate to" ? {
|
|
794
|
+
selectedIndex: event.index
|
|
795
|
+
} : event.type === "navigate up" ? {
|
|
796
|
+
selectedIndex: (context.selectedIndex - 1 + context.matches.length) % context.matches.length
|
|
797
|
+
} : {
|
|
798
|
+
selectedIndex: (context.selectedIndex + 1) % context.matches.length
|
|
799
|
+
}),
|
|
800
|
+
"select match": ({
|
|
801
|
+
context
|
|
802
|
+
}, params) => {
|
|
803
|
+
if (!context.focusSpan)
|
|
804
|
+
return;
|
|
805
|
+
const match = params.exact ? getFirstExactMatch(context.matches) : context.matches[context.selectedIndex];
|
|
806
|
+
match && context.editor.send({
|
|
807
|
+
type: "custom.typeahead select match",
|
|
808
|
+
match,
|
|
809
|
+
focusSpan: context.focusSpan,
|
|
810
|
+
keyword: context.keyword,
|
|
811
|
+
pickerId: context.definition._id
|
|
812
|
+
});
|
|
813
|
+
},
|
|
814
|
+
"update submit listener context": sendTo("submit listener", ({
|
|
815
|
+
context
|
|
816
|
+
}) => ({
|
|
817
|
+
type: "context changed",
|
|
818
|
+
context
|
|
819
|
+
})),
|
|
820
|
+
"update text insertion listener context": sendTo("text insertion listener", ({
|
|
821
|
+
context
|
|
822
|
+
}) => ({
|
|
823
|
+
type: "context changed",
|
|
824
|
+
context
|
|
825
|
+
})),
|
|
826
|
+
"update escape listener context": sendTo("escape listener", ({
|
|
827
|
+
context
|
|
828
|
+
}) => ({
|
|
829
|
+
type: "context changed",
|
|
830
|
+
context
|
|
831
|
+
})),
|
|
832
|
+
"update request dismiss listener context": sendTo("dismiss listener", ({
|
|
833
|
+
context
|
|
834
|
+
}) => ({
|
|
835
|
+
type: "context changed",
|
|
836
|
+
context
|
|
837
|
+
})),
|
|
838
|
+
"handle error": assign({
|
|
839
|
+
isLoading: !1,
|
|
840
|
+
error: ({
|
|
841
|
+
event
|
|
842
|
+
}) => event.error
|
|
843
|
+
})
|
|
844
|
+
},
|
|
845
|
+
guards: {
|
|
846
|
+
"no focus span": ({
|
|
847
|
+
context
|
|
848
|
+
}) => !context.focusSpan,
|
|
849
|
+
"invalid pattern": ({
|
|
850
|
+
context
|
|
851
|
+
}) => {
|
|
852
|
+
if (!context.patternText)
|
|
853
|
+
return !0;
|
|
854
|
+
const triggerMatch = context.patternText.match(context.triggerPattern);
|
|
855
|
+
if (triggerMatch && triggerMatch.index === 0 && triggerMatch[0] === context.patternText)
|
|
856
|
+
return !1;
|
|
857
|
+
const partialMatch = context.patternText.match(context.partialPattern);
|
|
858
|
+
if (partialMatch && partialMatch.index === 0 && partialMatch[0] === context.patternText)
|
|
859
|
+
return !1;
|
|
860
|
+
if (context.completePattern) {
|
|
861
|
+
const completeMatch = context.patternText.match(context.completePattern);
|
|
862
|
+
if (completeMatch && completeMatch.index === 0 && completeMatch[0] === context.patternText)
|
|
863
|
+
return !1;
|
|
864
|
+
}
|
|
865
|
+
return !0;
|
|
866
|
+
},
|
|
867
|
+
"no debounce": ({
|
|
868
|
+
context
|
|
869
|
+
}) => !context.definition.debounceMs || context.definition.debounceMs === 0,
|
|
870
|
+
"is complete keyword": ({
|
|
871
|
+
context
|
|
872
|
+
}) => {
|
|
873
|
+
if (!context.completePattern || !context.focusSpan)
|
|
874
|
+
return !1;
|
|
875
|
+
const fullKeywordText = context.focusSpan.node.text.slice(context.focusSpan.textBefore.length, context.focusSpan.textAfter.length > 0 ? -context.focusSpan.textAfter.length : void 0), completeMatch = fullKeywordText.match(context.completePattern);
|
|
876
|
+
return !completeMatch || completeMatch.index !== 0 || completeMatch[0] !== fullKeywordText ? !1 : hasAtLeastOneExactMatch(context.matches);
|
|
877
|
+
},
|
|
878
|
+
"has matches": ({
|
|
879
|
+
context
|
|
880
|
+
}) => context.matches.length > 0,
|
|
881
|
+
"no matches": ({
|
|
882
|
+
context
|
|
883
|
+
}) => context.matches.length === 0,
|
|
884
|
+
"is loading": ({
|
|
885
|
+
context
|
|
886
|
+
}) => context.isLoading
|
|
887
|
+
}
|
|
888
|
+
}).createMachine({
|
|
889
|
+
id: "typeahead picker",
|
|
890
|
+
context: ({
|
|
891
|
+
input
|
|
892
|
+
}) => ({
|
|
893
|
+
editor: input.editor,
|
|
894
|
+
definition: input.definition,
|
|
895
|
+
triggerPattern: buildTriggerPattern(input.definition),
|
|
896
|
+
partialPattern: buildPartialPattern(input.definition),
|
|
897
|
+
completePattern: buildCompletePattern(input.definition),
|
|
898
|
+
matches: [],
|
|
899
|
+
selectedIndex: 0,
|
|
900
|
+
focusSpan: void 0,
|
|
901
|
+
patternText: "",
|
|
902
|
+
keyword: "",
|
|
903
|
+
requestedKeyword: "",
|
|
904
|
+
error: void 0,
|
|
905
|
+
isLoading: !1
|
|
906
|
+
}),
|
|
907
|
+
initial: "idle",
|
|
908
|
+
states: {
|
|
909
|
+
idle: {
|
|
910
|
+
entry: ["reset"],
|
|
911
|
+
invoke: {
|
|
912
|
+
src: "trigger listener",
|
|
913
|
+
input: ({
|
|
914
|
+
context
|
|
915
|
+
}) => ({
|
|
916
|
+
editor: context.editor,
|
|
917
|
+
definition: context.definition
|
|
918
|
+
})
|
|
919
|
+
},
|
|
920
|
+
on: {
|
|
921
|
+
"custom.typeahead trigger found": {
|
|
922
|
+
target: "active",
|
|
923
|
+
actions: ["handle trigger found"]
|
|
923
924
|
},
|
|
924
|
-
|
|
925
|
-
"
|
|
926
|
-
|
|
927
|
-
actions: ["handle trigger found"]
|
|
928
|
-
},
|
|
929
|
-
"custom.typeahead keyword found": {
|
|
930
|
-
target: "checking complete",
|
|
931
|
-
actions: ["handle trigger found"]
|
|
932
|
-
}
|
|
925
|
+
"custom.typeahead keyword found": {
|
|
926
|
+
target: "checking complete",
|
|
927
|
+
actions: ["handle trigger found"]
|
|
933
928
|
}
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
"checking complete": {
|
|
932
|
+
invoke: [{
|
|
933
|
+
src: "select match listener",
|
|
934
|
+
input: ({
|
|
935
|
+
context
|
|
936
|
+
}) => ({
|
|
937
|
+
context
|
|
938
|
+
})
|
|
939
|
+
}, {
|
|
940
|
+
src: "get matches",
|
|
941
|
+
input: ({
|
|
942
|
+
context
|
|
943
|
+
}) => ({
|
|
944
|
+
keyword: context.keyword,
|
|
945
|
+
getMatches: context.definition.getMatches
|
|
946
|
+
}),
|
|
947
|
+
onDone: [{
|
|
948
|
+
guard: ({
|
|
949
|
+
event
|
|
950
|
+
}) => hasAtLeastOneExactMatch(event.output.matches),
|
|
951
|
+
target: "idle",
|
|
952
|
+
actions: [assign({
|
|
953
|
+
matches: ({
|
|
953
954
|
event
|
|
954
|
-
}) =>
|
|
955
|
-
|
|
956
|
-
actions: [assign({
|
|
957
|
-
matches: ({
|
|
958
|
-
event
|
|
959
|
-
}) => event.output.matches
|
|
960
|
-
}), {
|
|
961
|
-
type: "select match",
|
|
962
|
-
params: {
|
|
963
|
-
exact: !0
|
|
964
|
-
}
|
|
965
|
-
}]
|
|
966
|
-
}, {
|
|
967
|
-
target: "active",
|
|
968
|
-
actions: [assign({
|
|
969
|
-
matches: ({
|
|
970
|
-
event
|
|
971
|
-
}) => event.output.matches
|
|
972
|
-
})]
|
|
973
|
-
}],
|
|
974
|
-
onError: {
|
|
975
|
-
target: "active.no matches",
|
|
976
|
-
actions: ["handle error"]
|
|
977
|
-
}
|
|
978
|
-
}]
|
|
979
|
-
},
|
|
980
|
-
active: {
|
|
981
|
-
invoke: [{
|
|
982
|
-
src: "select match listener",
|
|
983
|
-
input: ({
|
|
984
|
-
context
|
|
985
|
-
}) => ({
|
|
986
|
-
context
|
|
987
|
-
})
|
|
988
|
-
}, {
|
|
989
|
-
src: "escape listener",
|
|
990
|
-
id: "escape listener",
|
|
991
|
-
input: ({
|
|
992
|
-
context
|
|
993
|
-
}) => ({
|
|
994
|
-
context
|
|
995
|
-
})
|
|
996
|
-
}, {
|
|
997
|
-
src: "selection listener",
|
|
998
|
-
input: ({
|
|
999
|
-
context
|
|
1000
|
-
}) => ({
|
|
1001
|
-
editor: context.editor
|
|
1002
|
-
})
|
|
1003
|
-
}, {
|
|
1004
|
-
src: "submit listener",
|
|
1005
|
-
id: "submit listener",
|
|
1006
|
-
input: ({
|
|
1007
|
-
context
|
|
1008
|
-
}) => ({
|
|
1009
|
-
context
|
|
1010
|
-
})
|
|
1011
|
-
}, {
|
|
1012
|
-
src: "text insertion listener",
|
|
1013
|
-
id: "text insertion listener",
|
|
1014
|
-
input: ({
|
|
1015
|
-
context
|
|
1016
|
-
}) => ({
|
|
1017
|
-
context
|
|
1018
|
-
})
|
|
1019
|
-
}, {
|
|
1020
|
-
src: "dismiss listener",
|
|
1021
|
-
id: "dismiss listener",
|
|
1022
|
-
input: ({
|
|
1023
|
-
context
|
|
1024
|
-
}) => ({
|
|
1025
|
-
context
|
|
1026
|
-
})
|
|
1027
|
-
}],
|
|
1028
|
-
on: {
|
|
1029
|
-
close: {
|
|
1030
|
-
target: "idle"
|
|
1031
|
-
},
|
|
1032
|
-
"selection changed": {
|
|
1033
|
-
actions: ["handle selection changed", "update submit listener context", "update text insertion listener context", "update escape listener context", "update request dismiss listener context"]
|
|
1034
|
-
}
|
|
1035
|
-
},
|
|
1036
|
-
always: [{
|
|
1037
|
-
guard: "no focus span",
|
|
1038
|
-
target: "idle"
|
|
1039
|
-
}, {
|
|
1040
|
-
guard: "invalid pattern",
|
|
1041
|
-
target: "idle"
|
|
1042
|
-
}, {
|
|
1043
|
-
guard: "is complete keyword",
|
|
1044
|
-
actions: [{
|
|
955
|
+
}) => event.output.matches
|
|
956
|
+
}), {
|
|
1045
957
|
type: "select match",
|
|
1046
958
|
params: {
|
|
1047
|
-
exact: !
|
|
959
|
+
exact: !0
|
|
1048
960
|
}
|
|
1049
|
-
}]
|
|
961
|
+
}]
|
|
962
|
+
}, {
|
|
963
|
+
target: "active",
|
|
964
|
+
actions: [assign({
|
|
965
|
+
matches: ({
|
|
966
|
+
event
|
|
967
|
+
}) => event.output.matches
|
|
968
|
+
})]
|
|
969
|
+
}],
|
|
970
|
+
onError: {
|
|
971
|
+
target: "active.no matches",
|
|
972
|
+
actions: ["handle error"]
|
|
973
|
+
}
|
|
974
|
+
}]
|
|
975
|
+
},
|
|
976
|
+
active: {
|
|
977
|
+
invoke: [{
|
|
978
|
+
src: "select match listener",
|
|
979
|
+
input: ({
|
|
980
|
+
context
|
|
981
|
+
}) => ({
|
|
982
|
+
context
|
|
983
|
+
})
|
|
984
|
+
}, {
|
|
985
|
+
src: "escape listener",
|
|
986
|
+
id: "escape listener",
|
|
987
|
+
input: ({
|
|
988
|
+
context
|
|
989
|
+
}) => ({
|
|
990
|
+
context
|
|
991
|
+
})
|
|
992
|
+
}, {
|
|
993
|
+
src: "selection listener",
|
|
994
|
+
input: ({
|
|
995
|
+
context
|
|
996
|
+
}) => ({
|
|
997
|
+
editor: context.editor
|
|
998
|
+
})
|
|
999
|
+
}, {
|
|
1000
|
+
src: "submit listener",
|
|
1001
|
+
id: "submit listener",
|
|
1002
|
+
input: ({
|
|
1003
|
+
context
|
|
1004
|
+
}) => ({
|
|
1005
|
+
context
|
|
1006
|
+
})
|
|
1007
|
+
}, {
|
|
1008
|
+
src: "text insertion listener",
|
|
1009
|
+
id: "text insertion listener",
|
|
1010
|
+
input: ({
|
|
1011
|
+
context
|
|
1012
|
+
}) => ({
|
|
1013
|
+
context
|
|
1014
|
+
})
|
|
1015
|
+
}, {
|
|
1016
|
+
src: "dismiss listener",
|
|
1017
|
+
id: "dismiss listener",
|
|
1018
|
+
input: ({
|
|
1019
|
+
context
|
|
1020
|
+
}) => ({
|
|
1021
|
+
context
|
|
1022
|
+
})
|
|
1023
|
+
}],
|
|
1024
|
+
on: {
|
|
1025
|
+
close: {
|
|
1050
1026
|
target: "idle"
|
|
1027
|
+
},
|
|
1028
|
+
"selection changed": {
|
|
1029
|
+
actions: ["handle selection changed", "update submit listener context", "update text insertion listener context", "update escape listener context", "update request dismiss listener context"]
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1032
|
+
always: [{
|
|
1033
|
+
guard: "no focus span",
|
|
1034
|
+
target: "idle"
|
|
1035
|
+
}, {
|
|
1036
|
+
guard: "invalid pattern",
|
|
1037
|
+
target: "idle"
|
|
1038
|
+
}, {
|
|
1039
|
+
guard: "is complete keyword",
|
|
1040
|
+
actions: [{
|
|
1041
|
+
type: "select match",
|
|
1042
|
+
params: {
|
|
1043
|
+
exact: !1
|
|
1044
|
+
}
|
|
1051
1045
|
}],
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1046
|
+
target: "idle"
|
|
1047
|
+
}],
|
|
1048
|
+
initial: "evaluating",
|
|
1049
|
+
states: {
|
|
1050
|
+
evaluating: {
|
|
1051
|
+
always: [{
|
|
1052
|
+
guard: "is loading",
|
|
1053
|
+
target: "loading"
|
|
1054
|
+
}, {
|
|
1055
|
+
guard: "has matches",
|
|
1056
|
+
target: "showing matches"
|
|
1057
|
+
}, {
|
|
1058
|
+
target: "no matches"
|
|
1059
|
+
}]
|
|
1060
|
+
},
|
|
1061
|
+
loading: {
|
|
1062
|
+
entry: [assign({
|
|
1063
|
+
requestedKeyword: ({
|
|
1064
|
+
context
|
|
1065
|
+
}) => context.keyword
|
|
1066
|
+
})],
|
|
1067
|
+
initial: "debouncing",
|
|
1068
|
+
states: {
|
|
1069
|
+
debouncing: {
|
|
1070
|
+
always: [{
|
|
1071
|
+
guard: "no debounce",
|
|
1072
|
+
target: "fetching"
|
|
1073
|
+
}],
|
|
1074
|
+
after: {
|
|
1075
|
+
DEBOUNCE: "fetching"
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
fetching: {
|
|
1079
|
+
invoke: {
|
|
1080
|
+
src: "get matches",
|
|
1081
|
+
input: ({
|
|
1082
|
+
context
|
|
1083
|
+
}) => ({
|
|
1084
|
+
keyword: context.keyword,
|
|
1085
|
+
getMatches: context.definition.getMatches
|
|
1086
|
+
}),
|
|
1087
|
+
onDone: {
|
|
1088
|
+
target: "#typeahead picker.active.evaluating",
|
|
1089
|
+
actions: [assign(({
|
|
1090
|
+
context,
|
|
1091
|
+
event
|
|
1092
|
+
}) => event.output.keyword !== context.keyword ? {
|
|
1093
|
+
isLoading: context.patternText !== context.requestedKeyword
|
|
1094
|
+
} : {
|
|
1095
|
+
matches: event.output.matches,
|
|
1096
|
+
isLoading: context.keyword !== context.requestedKeyword
|
|
1097
|
+
})]
|
|
1098
|
+
},
|
|
1099
|
+
onError: {
|
|
1100
|
+
target: "#typeahead picker.active.no matches",
|
|
1101
|
+
actions: ["handle error"]
|
|
1107
1102
|
}
|
|
1108
1103
|
}
|
|
1109
1104
|
}
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
})
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1107
|
+
"no matches": {
|
|
1108
|
+
entry: [assign({
|
|
1109
|
+
selectedIndex: 0
|
|
1110
|
+
})],
|
|
1111
|
+
always: [{
|
|
1112
|
+
guard: "has matches",
|
|
1113
|
+
target: "showing matches"
|
|
1114
|
+
}],
|
|
1115
|
+
initial: "idle",
|
|
1116
|
+
states: {
|
|
1117
|
+
idle: {
|
|
1118
|
+
always: [{
|
|
1119
|
+
guard: "is loading",
|
|
1120
|
+
target: "loading"
|
|
1121
|
+
}]
|
|
1122
|
+
},
|
|
1123
|
+
loading: {
|
|
1124
|
+
entry: [assign({
|
|
1125
|
+
requestedKeyword: ({
|
|
1126
|
+
context
|
|
1127
|
+
}) => context.keyword
|
|
1128
|
+
})],
|
|
1129
|
+
initial: "debouncing",
|
|
1130
|
+
states: {
|
|
1131
|
+
debouncing: {
|
|
1132
|
+
always: [{
|
|
1133
|
+
guard: "no debounce",
|
|
1134
|
+
target: "fetching"
|
|
1135
|
+
}],
|
|
1136
|
+
after: {
|
|
1137
|
+
DEBOUNCE: "fetching"
|
|
1138
|
+
}
|
|
1139
|
+
},
|
|
1140
|
+
fetching: {
|
|
1141
|
+
invoke: {
|
|
1142
|
+
src: "get matches",
|
|
1143
|
+
input: ({
|
|
1144
|
+
context
|
|
1145
|
+
}) => ({
|
|
1146
|
+
keyword: context.keyword,
|
|
1147
|
+
getMatches: context.definition.getMatches
|
|
1148
|
+
}),
|
|
1149
|
+
onDone: {
|
|
1150
|
+
target: "#typeahead picker.active.no matches.idle",
|
|
1151
|
+
actions: ["handle async load complete"]
|
|
1152
|
+
},
|
|
1153
|
+
onError: {
|
|
1154
|
+
target: "#typeahead picker.active.no matches.idle",
|
|
1155
|
+
actions: ["handle error"]
|
|
1161
1156
|
}
|
|
1162
1157
|
}
|
|
1163
1158
|
}
|
|
1164
1159
|
}
|
|
1165
1160
|
}
|
|
1161
|
+
}
|
|
1162
|
+
},
|
|
1163
|
+
"showing matches": {
|
|
1164
|
+
entry: ["update submit listener context", "update text insertion listener context"],
|
|
1165
|
+
invoke: {
|
|
1166
|
+
src: "arrow listener",
|
|
1167
|
+
input: ({
|
|
1168
|
+
context
|
|
1169
|
+
}) => ({
|
|
1170
|
+
editor: context.editor
|
|
1171
|
+
})
|
|
1166
1172
|
},
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
editor: context.editor
|
|
1175
|
-
})
|
|
1173
|
+
always: [{
|
|
1174
|
+
guard: "no matches",
|
|
1175
|
+
target: "no matches"
|
|
1176
|
+
}],
|
|
1177
|
+
on: {
|
|
1178
|
+
"navigate down": {
|
|
1179
|
+
actions: ["navigate", "update submit listener context", "update text insertion listener context"]
|
|
1176
1180
|
},
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
target: "no matches"
|
|
1180
|
-
}],
|
|
1181
|
-
on: {
|
|
1182
|
-
"navigate down": {
|
|
1183
|
-
actions: ["navigate", "update submit listener context", "update text insertion listener context"]
|
|
1184
|
-
},
|
|
1185
|
-
"navigate up": {
|
|
1186
|
-
actions: ["navigate", "update submit listener context", "update text insertion listener context"]
|
|
1187
|
-
},
|
|
1188
|
-
"navigate to": {
|
|
1189
|
-
actions: ["navigate", "update submit listener context", "update text insertion listener context"]
|
|
1190
|
-
},
|
|
1191
|
-
select: {
|
|
1192
|
-
target: "#typeahead picker.idle",
|
|
1193
|
-
actions: [{
|
|
1194
|
-
type: "select match",
|
|
1195
|
-
params: {
|
|
1196
|
-
exact: !1
|
|
1197
|
-
}
|
|
1198
|
-
}]
|
|
1199
|
-
}
|
|
1181
|
+
"navigate up": {
|
|
1182
|
+
actions: ["navigate", "update submit listener context", "update text insertion listener context"]
|
|
1200
1183
|
},
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1184
|
+
"navigate to": {
|
|
1185
|
+
actions: ["navigate", "update submit listener context", "update text insertion listener context"]
|
|
1186
|
+
},
|
|
1187
|
+
select: {
|
|
1188
|
+
target: "#typeahead picker.idle",
|
|
1189
|
+
actions: [{
|
|
1190
|
+
type: "select match",
|
|
1191
|
+
params: {
|
|
1192
|
+
exact: !1
|
|
1193
|
+
}
|
|
1194
|
+
}]
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
initial: "idle",
|
|
1198
|
+
states: {
|
|
1199
|
+
idle: {
|
|
1200
|
+
always: [{
|
|
1201
|
+
guard: "is loading",
|
|
1202
|
+
target: "loading"
|
|
1203
|
+
}]
|
|
1204
|
+
},
|
|
1205
|
+
loading: {
|
|
1206
|
+
entry: [assign({
|
|
1207
|
+
requestedKeyword: ({
|
|
1208
|
+
context
|
|
1209
|
+
}) => context.keyword
|
|
1210
|
+
})],
|
|
1211
|
+
initial: "debouncing",
|
|
1212
|
+
states: {
|
|
1213
|
+
debouncing: {
|
|
1214
|
+
always: [{
|
|
1215
|
+
guard: "no debounce",
|
|
1216
|
+
target: "fetching"
|
|
1217
|
+
}],
|
|
1218
|
+
after: {
|
|
1219
|
+
DEBOUNCE: "fetching"
|
|
1220
|
+
}
|
|
1221
|
+
},
|
|
1222
|
+
fetching: {
|
|
1223
|
+
invoke: {
|
|
1224
|
+
src: "get matches",
|
|
1225
|
+
input: ({
|
|
1226
|
+
context
|
|
1227
|
+
}) => ({
|
|
1228
|
+
keyword: context.keyword,
|
|
1229
|
+
getMatches: context.definition.getMatches
|
|
1230
|
+
}),
|
|
1231
|
+
onDone: {
|
|
1232
|
+
target: "#typeahead picker.active.showing matches.idle",
|
|
1233
|
+
actions: ["handle async load complete"]
|
|
1234
|
+
},
|
|
1235
|
+
onError: {
|
|
1236
|
+
target: "#typeahead picker.active.showing matches.idle",
|
|
1237
|
+
actions: ["handle error"]
|
|
1243
1238
|
}
|
|
1244
1239
|
}
|
|
1245
1240
|
}
|
|
@@ -1249,8 +1244,8 @@ function createTypeaheadPickerMachine() {
|
|
|
1249
1244
|
}
|
|
1250
1245
|
}
|
|
1251
1246
|
}
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1254
1249
|
function hasAtLeastOneExactMatch(matches) {
|
|
1255
1250
|
return matches.some((match) => match?.type === "exact");
|
|
1256
1251
|
}
|
|
@@ -1258,44 +1253,42 @@ function getFirstExactMatch(matches) {
|
|
|
1258
1253
|
return matches.find((match) => match?.type === "exact");
|
|
1259
1254
|
}
|
|
1260
1255
|
function useTypeaheadPicker(definition) {
|
|
1261
|
-
const $ = c(
|
|
1262
|
-
let t0;
|
|
1263
|
-
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = createTypeaheadPickerMachine(), $[0] = t0) : t0 = $[0];
|
|
1256
|
+
const $ = c(20), editor = useEditor(), t0 = definition;
|
|
1264
1257
|
let t1;
|
|
1265
|
-
$[
|
|
1258
|
+
$[0] !== editor || $[1] !== t0 ? (t1 = {
|
|
1266
1259
|
input: {
|
|
1267
1260
|
editor,
|
|
1268
|
-
definition
|
|
1261
|
+
definition: t0
|
|
1269
1262
|
}
|
|
1270
|
-
}, $[
|
|
1271
|
-
const [actorSnapshot, send] = useActor(
|
|
1263
|
+
}, $[0] = editor, $[1] = t0, $[2] = t1) : t1 = $[2];
|
|
1264
|
+
const [actorSnapshot, send] = useActor(typeaheadPickerMachine, t1);
|
|
1272
1265
|
let t2;
|
|
1273
|
-
$[
|
|
1266
|
+
$[3] !== actorSnapshot ? (t2 = (state) => actorSnapshot.matches(state), $[3] = actorSnapshot, $[4] = t2) : t2 = $[4];
|
|
1274
1267
|
const t3 = actorSnapshot.context.matches;
|
|
1275
1268
|
let t4;
|
|
1276
|
-
$[
|
|
1269
|
+
$[5] !== actorSnapshot.context.error || $[6] !== actorSnapshot.context.keyword || $[7] !== actorSnapshot.context.selectedIndex || $[8] !== t3 ? (t4 = {
|
|
1277
1270
|
keyword: actorSnapshot.context.keyword,
|
|
1278
1271
|
matches: t3,
|
|
1279
1272
|
selectedIndex: actorSnapshot.context.selectedIndex,
|
|
1280
1273
|
error: actorSnapshot.context.error
|
|
1281
|
-
}, $[
|
|
1274
|
+
}, $[5] = actorSnapshot.context.error, $[6] = actorSnapshot.context.keyword, $[7] = actorSnapshot.context.selectedIndex, $[8] = t3, $[9] = t4) : t4 = $[9];
|
|
1282
1275
|
let t5;
|
|
1283
|
-
$[
|
|
1276
|
+
$[10] !== t2 || $[11] !== t4 ? (t5 = {
|
|
1284
1277
|
matches: t2,
|
|
1285
1278
|
context: t4
|
|
1286
|
-
}, $[
|
|
1279
|
+
}, $[10] = t2, $[11] = t4, $[12] = t5) : t5 = $[12];
|
|
1287
1280
|
let t6;
|
|
1288
|
-
$[
|
|
1281
|
+
$[13] !== definition || $[14] !== editor || $[15] !== send ? (t6 = (event) => {
|
|
1289
1282
|
event.type === "dismiss" ? editor.send({
|
|
1290
1283
|
type: "custom.typeahead dismiss",
|
|
1291
1284
|
pickerId: definition._id
|
|
1292
1285
|
}) : send(event);
|
|
1293
|
-
}, $[
|
|
1286
|
+
}, $[13] = definition, $[14] = editor, $[15] = send, $[16] = t6) : t6 = $[16];
|
|
1294
1287
|
let t7;
|
|
1295
|
-
return $[
|
|
1288
|
+
return $[17] !== t5 || $[18] !== t6 ? (t7 = {
|
|
1296
1289
|
snapshot: t5,
|
|
1297
1290
|
send: t6
|
|
1298
|
-
}, $[
|
|
1291
|
+
}, $[17] = t5, $[18] = t6, $[19] = t7) : t7 = $[19], t7;
|
|
1299
1292
|
}
|
|
1300
1293
|
export {
|
|
1301
1294
|
defineTypeaheadPicker,
|