@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 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
- function createTypeaheadPickerMachine() {
631
- return setup({
632
- types: {
633
- context: {},
634
- input: {},
635
- events: {}
636
- },
637
- delays: {
638
- DEBOUNCE: ({
639
- context
640
- }) => context.definition.debounceMs ?? 0
641
- },
642
- actors: {
643
- "trigger listener": fromCallback(triggerListenerCallback()),
644
- "escape listener": fromCallback(escapeListenerCallback()),
645
- "arrow listener": fromCallback(arrowListenerCallback()),
646
- "selection listener": fromCallback(selectionListenerCallback()),
647
- "submit listener": fromCallback(submitListenerCallback()),
648
- "text insertion listener": fromCallback(textInsertionListenerCallback()),
649
- "select match listener": fromCallback(selectMatchListenerCallback()),
650
- "dismiss listener": fromCallback(dismissListenerCallback()),
651
- "get matches": fromPromise(async ({
652
- input
653
- }) => {
654
- const result = input.getMatches({
655
- keyword: input.keyword
656
- }), matches = await Promise.resolve(result);
657
- return {
658
- keyword: input.keyword,
659
- matches
660
- };
661
- })
662
- },
663
- actions: {
664
- "handle trigger found": assign(({
665
- context,
666
- event
667
- }) => {
668
- if (event.type !== "custom.typeahead trigger found" && event.type !== "custom.typeahead keyword found")
669
- return {};
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
- matches,
687
- requestedKeyword: keyword,
688
- isLoading: !1,
672
+ isLoading: !0,
689
673
  selectedIndex: 0
690
674
  };
691
- }),
692
- "handle selection changed": assign(({
693
- context
694
- }) => {
695
- if (!context.focusSpan)
696
- return {
697
- focusSpan: void 0
698
- };
699
- const snapshot = context.editor.getSnapshot(), currentFocusSpan = getFocusSpan(snapshot);
700
- if (!snapshot.context.selection || !currentFocusSpan)
701
- return {
702
- focusSpan: void 0
703
- };
704
- const nextSpan = getNextSpan({
705
- ...snapshot,
706
- context: {
707
- ...snapshot.context,
708
- selection: {
709
- anchor: {
710
- path: context.focusSpan.path,
711
- offset: 0
712
- },
713
- focus: {
714
- path: context.focusSpan.path,
715
- offset: 0
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
- if (!isEqualPaths(currentFocusSpan.path, context.focusSpan.path))
721
- return nextSpan && context.focusSpan.textAfter.length === 0 && snapshot.context.selection.focus.offset === 0 && isSelectionCollapsed(snapshot) ? {} : {
722
- focusSpan: void 0
723
- };
724
- if (!currentFocusSpan.node.text.startsWith(context.focusSpan.textBefore))
725
- return {
726
- focusSpan: void 0
727
- };
728
- if (!currentFocusSpan.node.text.endsWith(context.focusSpan.textAfter))
729
- return {
730
- focusSpan: void 0
731
- };
732
- const keywordAnchor = {
733
- path: currentFocusSpan.path,
734
- offset: context.focusSpan.textBefore.length
735
- }, keywordFocus = {
736
- path: currentFocusSpan.path,
737
- offset: currentFocusSpan.node.text.length - context.focusSpan.textAfter.length
738
- }, selectionIsBeforeKeyword = isPointAfterSelection(keywordAnchor)(snapshot), selectionIsAfterKeyword = isPointBeforeSelection(keywordFocus)(snapshot);
739
- if (selectionIsBeforeKeyword || selectionIsAfterKeyword)
740
- return {
741
- focusSpan: void 0
742
- };
743
- const focusSpan = {
744
- node: currentFocusSpan.node,
745
- path: currentFocusSpan.path,
746
- textBefore: context.focusSpan.textBefore,
747
- textAfter: context.focusSpan.textAfter
748
- }, patternText = extractPatternTextFromFocusSpan(focusSpan), keyword = extractKeyword(patternText, context.triggerPattern, context.definition.delimiter, context.completePattern);
749
- if (context.definition.mode === "async" || context.definition.debounceMs)
750
- return {
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: !1
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
- reset: assign({
783
- patternText: "",
784
- keyword: "",
785
- matches: [],
786
- selectedIndex: 0,
787
- isLoading: !1,
788
- requestedKeyword: "",
789
- focusSpan: void 0,
790
- error: void 0
791
- }),
792
- navigate: assign(({
793
- context,
794
- event
795
- }) => context.matches.length === 0 ? {
796
- selectedIndex: 0
797
- } : event.type === "navigate to" ? {
798
- selectedIndex: event.index
799
- } : event.type === "navigate up" ? {
800
- selectedIndex: (context.selectedIndex - 1 + context.matches.length) % context.matches.length
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
- selectedIndex: (context.selectedIndex + 1) % context.matches.length
803
- }),
804
- "select match": ({
805
- context
806
- }, params) => {
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
- error: void 0,
909
- isLoading: !1
785
+ focusSpan: void 0,
786
+ error: void 0
910
787
  }),
911
- initial: "idle",
912
- states: {
913
- idle: {
914
- entry: ["reset"],
915
- invoke: {
916
- src: "trigger listener",
917
- input: ({
918
- context
919
- }) => ({
920
- editor: context.editor,
921
- definition: context.definition
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
- on: {
925
- "custom.typeahead trigger found": {
926
- target: "active",
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
- "checking complete": {
936
- invoke: [{
937
- src: "select match listener",
938
- input: ({
939
- context
940
- }) => ({
941
- context
942
- })
943
- }, {
944
- src: "get matches",
945
- input: ({
946
- context
947
- }) => ({
948
- keyword: context.keyword,
949
- getMatches: context.definition.getMatches
950
- }),
951
- onDone: [{
952
- guard: ({
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
- }) => hasAtLeastOneExactMatch(event.output.matches),
955
- target: "idle",
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: !1
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
- initial: "evaluating",
1053
- states: {
1054
- evaluating: {
1055
- always: [{
1056
- guard: "is loading",
1057
- target: "loading"
1058
- }, {
1059
- guard: "has matches",
1060
- target: "showing matches"
1061
- }, {
1062
- target: "no matches"
1063
- }]
1064
- },
1065
- loading: {
1066
- entry: [assign({
1067
- requestedKeyword: ({
1068
- context
1069
- }) => context.keyword
1070
- })],
1071
- initial: "debouncing",
1072
- states: {
1073
- debouncing: {
1074
- always: [{
1075
- guard: "no debounce",
1076
- target: "fetching"
1077
- }],
1078
- after: {
1079
- DEBOUNCE: "fetching"
1080
- }
1081
- },
1082
- fetching: {
1083
- invoke: {
1084
- src: "get matches",
1085
- input: ({
1086
- context
1087
- }) => ({
1088
- keyword: context.keyword,
1089
- getMatches: context.definition.getMatches
1090
- }),
1091
- onDone: {
1092
- target: "#typeahead picker.active.evaluating",
1093
- actions: [assign(({
1094
- context,
1095
- event
1096
- }) => event.output.keyword !== context.keyword ? {
1097
- isLoading: context.patternText !== context.requestedKeyword
1098
- } : {
1099
- matches: event.output.matches,
1100
- isLoading: context.keyword !== context.requestedKeyword
1101
- })]
1102
- },
1103
- onError: {
1104
- target: "#typeahead picker.active.no matches",
1105
- actions: ["handle error"]
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
- "no matches": {
1112
- entry: [assign({
1113
- selectedIndex: 0
1114
- })],
1115
- always: [{
1116
- guard: "has matches",
1117
- target: "showing matches"
1118
- }],
1119
- initial: "idle",
1120
- states: {
1121
- idle: {
1122
- always: [{
1123
- guard: "is loading",
1124
- target: "loading"
1125
- }]
1126
- },
1127
- loading: {
1128
- entry: [assign({
1129
- requestedKeyword: ({
1130
- context
1131
- }) => context.keyword
1132
- })],
1133
- initial: "debouncing",
1134
- states: {
1135
- debouncing: {
1136
- always: [{
1137
- guard: "no debounce",
1138
- target: "fetching"
1139
- }],
1140
- after: {
1141
- DEBOUNCE: "fetching"
1142
- }
1143
- },
1144
- fetching: {
1145
- invoke: {
1146
- src: "get matches",
1147
- input: ({
1148
- context
1149
- }) => ({
1150
- keyword: context.keyword,
1151
- getMatches: context.definition.getMatches
1152
- }),
1153
- onDone: {
1154
- target: "#typeahead picker.active.no matches.idle",
1155
- actions: ["handle async load complete"]
1156
- },
1157
- onError: {
1158
- target: "#typeahead picker.active.no matches.idle",
1159
- actions: ["handle error"]
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
- "showing matches": {
1168
- entry: ["update submit listener context", "update text insertion listener context"],
1169
- invoke: {
1170
- src: "arrow listener",
1171
- input: ({
1172
- context
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
- always: [{
1178
- guard: "no matches",
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
- initial: "idle",
1202
- states: {
1203
- idle: {
1204
- always: [{
1205
- guard: "is loading",
1206
- target: "loading"
1207
- }]
1208
- },
1209
- loading: {
1210
- entry: [assign({
1211
- requestedKeyword: ({
1212
- context
1213
- }) => context.keyword
1214
- })],
1215
- initial: "debouncing",
1216
- states: {
1217
- debouncing: {
1218
- always: [{
1219
- guard: "no debounce",
1220
- target: "fetching"
1221
- }],
1222
- after: {
1223
- DEBOUNCE: "fetching"
1224
- }
1225
- },
1226
- fetching: {
1227
- invoke: {
1228
- src: "get matches",
1229
- input: ({
1230
- context
1231
- }) => ({
1232
- keyword: context.keyword,
1233
- getMatches: context.definition.getMatches
1234
- }),
1235
- onDone: {
1236
- target: "#typeahead picker.active.showing matches.idle",
1237
- actions: ["handle async load complete"]
1238
- },
1239
- onError: {
1240
- target: "#typeahead picker.active.showing matches.idle",
1241
- actions: ["handle error"]
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(21), editor = useEditor();
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
- $[1] !== definition || $[2] !== editor ? (t1 = {
1258
+ $[0] !== editor || $[1] !== t0 ? (t1 = {
1266
1259
  input: {
1267
1260
  editor,
1268
- definition
1261
+ definition: t0
1269
1262
  }
1270
- }, $[1] = definition, $[2] = editor, $[3] = t1) : t1 = $[3];
1271
- const [actorSnapshot, send] = useActor(t0, t1);
1263
+ }, $[0] = editor, $[1] = t0, $[2] = t1) : t1 = $[2];
1264
+ const [actorSnapshot, send] = useActor(typeaheadPickerMachine, t1);
1272
1265
  let t2;
1273
- $[4] !== actorSnapshot ? (t2 = (state) => actorSnapshot.matches(state), $[4] = actorSnapshot, $[5] = t2) : t2 = $[5];
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
- $[6] !== actorSnapshot.context.error || $[7] !== actorSnapshot.context.keyword || $[8] !== actorSnapshot.context.selectedIndex || $[9] !== t3 ? (t4 = {
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
- }, $[6] = actorSnapshot.context.error, $[7] = actorSnapshot.context.keyword, $[8] = actorSnapshot.context.selectedIndex, $[9] = t3, $[10] = t4) : t4 = $[10];
1274
+ }, $[5] = actorSnapshot.context.error, $[6] = actorSnapshot.context.keyword, $[7] = actorSnapshot.context.selectedIndex, $[8] = t3, $[9] = t4) : t4 = $[9];
1282
1275
  let t5;
1283
- $[11] !== t2 || $[12] !== t4 ? (t5 = {
1276
+ $[10] !== t2 || $[11] !== t4 ? (t5 = {
1284
1277
  matches: t2,
1285
1278
  context: t4
1286
- }, $[11] = t2, $[12] = t4, $[13] = t5) : t5 = $[13];
1279
+ }, $[10] = t2, $[11] = t4, $[12] = t5) : t5 = $[12];
1287
1280
  let t6;
1288
- $[14] !== definition || $[15] !== editor || $[16] !== send ? (t6 = (event) => {
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
- }, $[14] = definition, $[15] = editor, $[16] = send, $[17] = t6) : t6 = $[17];
1286
+ }, $[13] = definition, $[14] = editor, $[15] = send, $[16] = t6) : t6 = $[16];
1294
1287
  let t7;
1295
- return $[18] !== t5 || $[19] !== t6 ? (t7 = {
1288
+ return $[17] !== t5 || $[18] !== t6 ? (t7 = {
1296
1289
  snapshot: t5,
1297
1290
  send: t6
1298
- }, $[18] = t5, $[19] = t6, $[20] = t7) : t7 = $[20], t7;
1291
+ }, $[17] = t5, $[18] = t6, $[19] = t7) : t7 = $[19], t7;
1299
1292
  }
1300
1293
  export {
1301
1294
  defineTypeaheadPicker,