pxt-core 8.0.2 → 8.0.5

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.
@@ -15502,6 +15502,8 @@ var pxtblockly;
15502
15502
  getScaledBBox: () => bbox
15503
15503
  };
15504
15504
  Blockly.WidgetDiv.show(widgetOwner, this.sourceBlock_.RTL, () => {
15505
+ if (document.activeElement && document.activeElement.tagName === "INPUT")
15506
+ document.activeElement.blur();
15505
15507
  fv.hide();
15506
15508
  widgetDiv.classList.remove("sound-effect-editor-widget");
15507
15509
  widgetDiv.style.transform = "";
@@ -11940,6 +11940,8 @@ var pxtblockly;
11940
11940
  getScaledBBox: () => bbox
11941
11941
  };
11942
11942
  Blockly.WidgetDiv.show(widgetOwner, this.sourceBlock_.RTL, () => {
11943
+ if (document.activeElement && document.activeElement.tagName === "INPUT")
11944
+ document.activeElement.blur();
11943
11945
  fv.hide();
11944
11946
  widgetDiv.classList.remove("sound-effect-editor-widget");
11945
11947
  widgetDiv.style.transform = "";
@@ -1045,6 +1045,7 @@ declare namespace pxt.editor {
1045
1045
  isRegex: boolean;
1046
1046
  matchWholeWord: boolean;
1047
1047
  matchCase: boolean;
1048
+ validateRange?: (range: monaco.Range, model: monaco.editor.ITextModel) => monaco.Range;
1048
1049
  }
1049
1050
  function registerMonacoFieldEditor(name: string, definition: MonacoFieldEditorDefinition): void;
1050
1051
  function getMonacoFieldEditor(name: string): MonacoFieldEditorDefinition;
@@ -1068,6 +1069,16 @@ declare namespace pxt.editor {
1068
1069
  protected getOptions(): any;
1069
1070
  }
1070
1071
  }
1072
+ declare namespace pxt.editor {
1073
+ class MonacoSoundEffectEditor extends MonacoReactFieldEditor<pxt.assets.Sound> {
1074
+ protected value: pxt.assets.Sound;
1075
+ protected textToValue(text: string): pxt.assets.Sound;
1076
+ protected resultToText(result: pxt.assets.Sound): string;
1077
+ protected getFieldEditorId(): string;
1078
+ protected getOptions(): any;
1079
+ }
1080
+ const soundEditorDefinition: MonacoFieldEditorDefinition;
1081
+ }
1071
1082
  declare namespace pxt.editor {
1072
1083
  class MonacoSpriteEditor extends MonacoReactFieldEditor<pxt.ProjectImage> {
1073
1084
  protected isPython: boolean;
@@ -930,6 +930,203 @@ var pxt;
930
930
  /// <reference path="./monacoFieldEditor.ts" />
931
931
  /// <reference path="./field_react.ts" />
932
932
  var pxt;
933
+ (function (pxt) {
934
+ var editor;
935
+ (function (editor) {
936
+ const fieldEditorId = "soundeffect-editor";
937
+ // music.createSoundEffect(WaveShape.Sine, 5000, 0, 255, 0, 500, SoundExpressionEffect.None, InterpolationCurve.Linear
938
+ class MonacoSoundEffectEditor extends editor.MonacoReactFieldEditor {
939
+ textToValue(text) {
940
+ const out = defaultSound();
941
+ this.value = out;
942
+ const argMatch = /\(([^)]*)\)/.exec(text);
943
+ const args = argMatch[1].split(",").map(a => a.replace(/\s/g, ""));
944
+ if (args.length !== 8)
945
+ return out;
946
+ switch (args[0]) {
947
+ case "WaveShape.Sawtooth":
948
+ out.wave = "sawtooth";
949
+ break;
950
+ case "WaveShape.Square":
951
+ out.wave = "square";
952
+ break;
953
+ case "WaveShape.Noise":
954
+ out.wave = "noise";
955
+ break;
956
+ case "WaveShape.Triangle":
957
+ out.wave = "triangle";
958
+ break;
959
+ case "WaveShape.Sine":
960
+ default:
961
+ out.wave = "sine";
962
+ break;
963
+ }
964
+ const withDefault = (val, def) => {
965
+ return isNaN(val) ? def : val;
966
+ };
967
+ out.startFrequency = withDefault(parseInt(args[1]), out.startFrequency);
968
+ out.endFrequency = withDefault(parseInt(args[2]), out.endFrequency);
969
+ out.startVolume = withDefault(parseInt(args[3]), out.startVolume);
970
+ out.endVolume = withDefault(parseInt(args[4]), out.endVolume);
971
+ out.duration = withDefault(parseInt(args[5]), out.duration);
972
+ switch (args[6]) {
973
+ case "SoundExpressionEffect.Vibrato":
974
+ out.effect = "vibrato";
975
+ break;
976
+ case "SoundExpressionEffect.Tremolo":
977
+ out.effect = "tremolo";
978
+ break;
979
+ case "SoundExpressionEffect.Warble":
980
+ out.effect = "warble";
981
+ break;
982
+ case "SoundExpressionEffect.None":
983
+ default:
984
+ out.effect = "none";
985
+ break;
986
+ }
987
+ switch (args[7]) {
988
+ case "InterpolationCurve.Logarithmic":
989
+ out.interpolation = "logarithmic";
990
+ break;
991
+ case "InterpolationCurve.Curve":
992
+ out.interpolation = "curve";
993
+ break;
994
+ case "InterpolationCurve.Linear":
995
+ default:
996
+ out.interpolation = "linear";
997
+ break;
998
+ }
999
+ return out;
1000
+ }
1001
+ resultToText(result) {
1002
+ result = this.value;
1003
+ let waveShape;
1004
+ switch (result.wave) {
1005
+ case "sine":
1006
+ waveShape = "WaveShape.Sine";
1007
+ break;
1008
+ case "square":
1009
+ waveShape = "WaveShape.Square";
1010
+ break;
1011
+ case "triangle":
1012
+ waveShape = "WaveShape.Triangle";
1013
+ break;
1014
+ case "noise":
1015
+ waveShape = "WaveShape.Noise";
1016
+ break;
1017
+ case "sawtooth":
1018
+ waveShape = "WaveShape.Sawtooth";
1019
+ break;
1020
+ }
1021
+ let effect;
1022
+ switch (result.effect) {
1023
+ case "vibrato":
1024
+ effect = "SoundExpressionEffect.Vibrato";
1025
+ break;
1026
+ case "tremolo":
1027
+ effect = "SoundExpressionEffect.Tremolo";
1028
+ break;
1029
+ case "warble":
1030
+ effect = "SoundExpressionEffect.Warble";
1031
+ break;
1032
+ case "none":
1033
+ effect = "SoundExpressionEffect.None";
1034
+ break;
1035
+ }
1036
+ let interpolation;
1037
+ switch (result.interpolation) {
1038
+ case "curve":
1039
+ interpolation = "InterpolationCurve.Curve";
1040
+ break;
1041
+ case "linear":
1042
+ interpolation = "InterpolationCurve.Linear";
1043
+ break;
1044
+ case "logarithmic":
1045
+ interpolation = "InterpolationCurve.Logarithmic";
1046
+ break;
1047
+ }
1048
+ return `music.createSoundEffect(${waveShape}, ${Math.round(result.startFrequency)}, ${Math.round(result.endFrequency)}, ${Math.round(result.startVolume)}, ${Math.round(result.endVolume)}, ${Math.round(result.duration)}, ${effect}, ${interpolation})`;
1049
+ }
1050
+ getFieldEditorId() {
1051
+ return fieldEditorId;
1052
+ }
1053
+ getOptions() {
1054
+ return {
1055
+ onClose: () => this.fv.hide(),
1056
+ onSoundChange: (newValue) => this.value = newValue,
1057
+ initialSound: this.value,
1058
+ useFlex: true
1059
+ };
1060
+ }
1061
+ }
1062
+ editor.MonacoSoundEffectEditor = MonacoSoundEffectEditor;
1063
+ function validateRange(range, model) {
1064
+ let currentLine = range.startLineNumber;
1065
+ let currentColumn = 0;
1066
+ let foundStart = false;
1067
+ let parenCount = 0;
1068
+ const methodName = "createSoundEffect";
1069
+ const totalLines = model.getLineCount();
1070
+ while (currentLine < totalLines) {
1071
+ const lineContent = model.getLineContent(currentLine);
1072
+ const startIndex = lineContent.indexOf(methodName);
1073
+ if (startIndex !== -1) {
1074
+ foundStart = true;
1075
+ currentColumn = startIndex + methodName.length;
1076
+ }
1077
+ if (foundStart) {
1078
+ while (currentColumn < lineContent.length) {
1079
+ const currentChar = lineContent.charAt(currentColumn);
1080
+ if (currentChar === "(") {
1081
+ parenCount++;
1082
+ }
1083
+ else if (currentChar === ")") {
1084
+ parenCount--;
1085
+ if (parenCount === 0) {
1086
+ return new monaco.Range(range.startLineNumber, range.startColumn, currentLine, currentColumn + model.getLineMinColumn(currentLine) + 1);
1087
+ }
1088
+ }
1089
+ currentColumn++;
1090
+ }
1091
+ }
1092
+ currentColumn = 0;
1093
+ currentLine++;
1094
+ }
1095
+ return undefined;
1096
+ }
1097
+ function defaultSound() {
1098
+ return {
1099
+ wave: "sine",
1100
+ startFrequency: 5000,
1101
+ endFrequency: 0,
1102
+ startVolume: 255,
1103
+ endVolume: 0,
1104
+ duration: 500,
1105
+ effect: "none",
1106
+ interpolation: "linear"
1107
+ };
1108
+ }
1109
+ editor.soundEditorDefinition = {
1110
+ id: fieldEditorId,
1111
+ foldMatches: true,
1112
+ glyphCssClass: "fas fa-music sprite-focus-hover",
1113
+ heightInPixels: 510,
1114
+ matcher: {
1115
+ // match both JS and python
1116
+ searchString: "music\\s*\\.\\s*createSoundEffect\\s*\\(",
1117
+ isRegex: true,
1118
+ matchCase: true,
1119
+ matchWholeWord: false,
1120
+ validateRange
1121
+ },
1122
+ proto: MonacoSoundEffectEditor
1123
+ };
1124
+ editor.registerMonacoFieldEditor(fieldEditorId, editor.soundEditorDefinition);
1125
+ })(editor = pxt.editor || (pxt.editor = {}));
1126
+ })(pxt || (pxt = {}));
1127
+ /// <reference path="./monacoFieldEditor.ts" />
1128
+ /// <reference path="./field_react.ts" />
1129
+ var pxt;
933
1130
  (function (pxt) {
934
1131
  var editor;
935
1132
  (function (editor) {