keystonemc 4.1.0 → 4.2.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.
@@ -1,10 +1,13 @@
1
- import { ModalFormData, ActionFormData } from "@minecraft/server-ui";
1
+ import { ModalFormData, ActionFormData, MessageFormData } from "@minecraft/server-ui";
2
2
  class ModalForm {
3
3
  constructor(config) {
4
4
  this.config = config;
5
5
  }
6
6
  async send(player) {
7
7
  const form = new ModalFormData().title(this.config.title);
8
+ if (this.config.submitButtonText) {
9
+ form.submitButton(this.config.submitButtonText);
10
+ }
8
11
  for (const component of this.config.components) {
9
12
  component.render(form);
10
13
  }
@@ -53,8 +56,31 @@ class ActionForm {
53
56
  function createActionForm(config) {
54
57
  return new ActionForm(config);
55
58
  }
59
+ class MessageForm {
60
+ constructor(config) {
61
+ this.config = config;
62
+ }
63
+ async send(player) {
64
+ const form = new MessageFormData().title(this.config.title).body(this.config.body).button1(this.config.yes.text).button2(this.config.no.text);
65
+ const res = await form.show(player);
66
+ if (res.canceled) {
67
+ this.config.previousForm?.send(player);
68
+ return;
69
+ }
70
+ if (res.selection === 0) {
71
+ this.config.yes.handler(player);
72
+ } else if (res.selection === 1) {
73
+ this.config.no.handler(player);
74
+ }
75
+ }
76
+ }
77
+ function createMessageForm(config) {
78
+ return new MessageForm(config);
79
+ }
56
80
  function toggle(opts) {
57
81
  return {
82
+ type: "toggle",
83
+ opts,
58
84
  render(form) {
59
85
  form.toggle(opts.label, { defaultValue: opts.default });
60
86
  },
@@ -65,11 +91,16 @@ function toggle(opts) {
65
91
  }
66
92
  function textField(opts) {
67
93
  return {
94
+ type: "text_field",
95
+ opts,
68
96
  render(form) {
69
97
  form.textField(
70
98
  opts.label,
71
99
  opts.placeholder ?? "",
72
- { defaultValue: opts.default ?? "" }
100
+ {
101
+ defaultValue: opts.default ?? "",
102
+ tooltip: opts.tooltip
103
+ }
73
104
  );
74
105
  },
75
106
  handle(player, value) {
@@ -79,6 +110,8 @@ function textField(opts) {
79
110
  }
80
111
  function slider(opts) {
81
112
  return {
113
+ type: "slider",
114
+ opts,
82
115
  render(form) {
83
116
  form.slider(
84
117
  opts.label,
@@ -94,6 +127,8 @@ function slider(opts) {
94
127
  }
95
128
  function dropdown(opts) {
96
129
  return {
130
+ type: "dropdown",
131
+ opts,
97
132
  render(form) {
98
133
  form.dropdown(
99
134
  opts.label,
@@ -106,6 +141,32 @@ function dropdown(opts) {
106
141
  }
107
142
  };
108
143
  }
144
+ function header(opts) {
145
+ return {
146
+ type: "header",
147
+ opts,
148
+ render(form) {
149
+ form.header(opts.text);
150
+ }
151
+ };
152
+ }
153
+ function label(opts) {
154
+ return {
155
+ type: "label",
156
+ opts,
157
+ render(form) {
158
+ form.label(opts.text);
159
+ }
160
+ };
161
+ }
162
+ function divider() {
163
+ return {
164
+ type: "divider",
165
+ render(form) {
166
+ form.divider();
167
+ }
168
+ };
169
+ }
109
170
  function button(opts) {
110
171
  return {
111
172
  render(form) {
@@ -124,10 +185,15 @@ export {
124
185
  ActionForm as A,
125
186
  ModalForm as M,
126
187
  createActionForm as a,
127
- textField as b,
188
+ MessageForm as b,
128
189
  createModalForm as c,
129
- dropdown as d,
130
- button as e,
190
+ createMessageForm as d,
191
+ textField as e,
192
+ dropdown as f,
193
+ divider as g,
194
+ header as h,
195
+ button as i,
196
+ label as l,
131
197
  slider as s,
132
198
  toggle as t
133
199
  };
@@ -1,5 +1,5 @@
1
1
  import { Player } from '@minecraft/server';
2
- import { ActionButton, FormComponent } from './types';
2
+ import { ActionButton, FormComponent, StatelessFormComponent } from './types';
3
3
  /**
4
4
  * トグル
5
5
  * @param opts
@@ -19,6 +19,7 @@ export declare function textField(opts: {
19
19
  label: string;
20
20
  placeholder?: string;
21
21
  default?: string;
22
+ tooltip?: string;
22
23
  handler?(player: Player, value: string): void;
23
24
  }): FormComponent<string>;
24
25
  /**
@@ -45,6 +46,22 @@ export declare function dropdown(opts: {
45
46
  defaultIndex?: number;
46
47
  handler?(player: Player, value: number): void;
47
48
  }): FormComponent<number>;
49
+ /**
50
+ * ヘッダー
51
+ */
52
+ export declare function header(opts: {
53
+ text: string;
54
+ }): StatelessFormComponent;
55
+ /**
56
+ * ラベル
57
+ */
58
+ export declare function label(opts: {
59
+ text: string;
60
+ }): StatelessFormComponent;
61
+ /**
62
+ * Divider
63
+ */
64
+ export declare function divider(): StatelessFormComponent;
48
65
  /**
49
66
  * ボタン (ActionForm)
50
67
  * @param opts
@@ -0,0 +1,2 @@
1
+ declare const Divider: () => import('../../types').StatelessFormComponent;
2
+ export default Divider;
@@ -3,5 +3,8 @@ interface DropdownProps {
3
3
  options: string[];
4
4
  defaultValueIndex?: number;
5
5
  }
6
+ /**
7
+ * ModalFormでドロップダウン選択を行えるコンポーネント
8
+ */
6
9
  export default function Dropdown({ label, options, defaultValueIndex, }: DropdownProps): import('../../types').FormComponent<number>;
7
10
  export {};
@@ -0,0 +1,8 @@
1
+ interface HeaderProps {
2
+ text: string;
3
+ }
4
+ /**
5
+ * ModalFormでヘッダーを表示するコンポーネント
6
+ */
7
+ declare const Header: ({ text }: HeaderProps) => import('../../types').StatelessFormComponent;
8
+ export default Header;
@@ -0,0 +1,5 @@
1
+ interface LabelProps {
2
+ text: string;
3
+ }
4
+ declare const Label: ({ text }: LabelProps) => import('../../types').StatelessFormComponent;
5
+ export default Label;
@@ -0,0 +1,15 @@
1
+ import { ActionForm as ActionFormType } from '../../actionForm';
2
+ import { MessageForm as MessageFormType } from '../../messageForm';
3
+ import { ModalForm as ModalFormType } from '../../modalForm';
4
+ import { Player } from '@minecraft/server';
5
+ interface MessageFormProps {
6
+ title: string;
7
+ children?: string[];
8
+ previousForm?: ActionFormType | MessageFormType | ModalFormType;
9
+ yesLabel: string;
10
+ noLabel: string;
11
+ onClickYes?: (player: Player) => void;
12
+ onClickNo?: (player: Player) => void;
13
+ }
14
+ declare const MessageForm: ({ title, children, previousForm, yesLabel, noLabel, onClickYes, onClickNo, }: MessageFormProps) => MessageFormType;
15
+ export default MessageForm;
@@ -5,9 +5,25 @@ import { FormComponent } from '../../types';
5
5
  import { Player } from '@minecraft/server';
6
6
  interface ModalFormProps<T = any> {
7
7
  title: string;
8
+ submitButtonText?: string;
8
9
  previousForm?: ModalFormType | ActionForm | MessageForm;
9
10
  children?: FormComponent[];
10
11
  onSubmit?: (player: Player, values?: T[] | undefined) => any;
11
12
  }
12
- export default function ModalForm({ title, previousForm, children, onSubmit, }: ModalFormProps): ModalFormType;
13
+ /**
14
+ * ユーザーからのテキストやその他の入力を受け取れるフォーム
15
+ *
16
+ * **使用例**
17
+ * ```tsx
18
+ * <ModalForm
19
+ * title="タイトル"
20
+ * onSubmit={handleSubmit}
21
+ * >
22
+ * <Textfield
23
+ * label="テキスト入力"
24
+ * />
25
+ * </ModalForm>
26
+ * ```
27
+ */
28
+ export default function ModalForm({ title, submitButtonText, previousForm, children, onSubmit, }: ModalFormProps): ModalFormType;
13
29
  export {};
@@ -5,5 +5,8 @@ interface SliderProps {
5
5
  step?: number;
6
6
  defaultValue?: number;
7
7
  }
8
+ /**
9
+ * ModalFormでスライダー表示するコンポーネント
10
+ */
8
11
  export default function Slider({ label, min, max, step, defaultValue, }: SliderProps): import('../../types').FormComponent<number>;
9
12
  export {};
@@ -2,6 +2,10 @@ interface TextfieldProps {
2
2
  label: string;
3
3
  placeholder?: string;
4
4
  defaultValue?: string;
5
+ tooltip?: string;
5
6
  }
6
- export default function Textfield({ label, placeholder, defaultValue, }: TextfieldProps): import('../../types').FormComponent<string>;
7
+ /**
8
+ * ModalFormでテキスト入力を行えるコンポーネント
9
+ */
10
+ export default function Textfield({ label, placeholder, defaultValue, tooltip, }: TextfieldProps): import('../../types').FormComponent<string>;
7
11
  export {};
@@ -2,5 +2,8 @@ interface ToggleProps {
2
2
  label: string;
3
3
  defaultValue?: boolean;
4
4
  }
5
+ /**
6
+ * ModalFormでトグル切り替えを行えるコンポーネント
7
+ */
5
8
  export default function Toggle({ label, defaultValue, }: ToggleProps): import('../../types').FormComponent<boolean>;
6
9
  export {};
@@ -1,8 +1,12 @@
1
1
  import { default as ActionForm } from './ActionForm';
2
+ import { default as MessageForm } from './MessageForm';
2
3
  import { default as Button } from './Button';
3
4
  import { default as ModalForm } from './ModalForm';
4
5
  import { default as Slider } from './Slider';
5
6
  import { default as Dropdown } from './Dropdown';
6
7
  import { default as Textfield } from './Textfield';
7
8
  import { default as Toggle } from './Toggle';
8
- export { ActionForm, Button, ModalForm, Slider, Dropdown, Textfield, Toggle, };
9
+ import { default as Header } from './Header';
10
+ import { default as Divider } from './Divider';
11
+ import { default as Label } from './Label';
12
+ export { ActionForm, Button, MessageForm, ModalForm, Slider, Dropdown, Textfield, Toggle, Header, Divider, Label, };
@@ -4,11 +4,19 @@ import { ActionForm } from './actionForm';
4
4
  import { ModalForm } from './modalForm';
5
5
  import { MessageForm } from './messageForm';
6
6
  export interface FormComponent<T = any> {
7
+ type: string;
8
+ opts: object;
7
9
  render(form: ModalFormData): void;
8
10
  handle?(player: Player, value: T): void;
9
11
  }
12
+ export interface StatelessFormComponent {
13
+ type: string;
14
+ opts?: object;
15
+ render(form: ModalFormData): void;
16
+ }
10
17
  export interface ModalFormConfig<T = any> {
11
18
  title: string;
19
+ submitButtonText?: string;
12
20
  previousForm?: ModalForm | ActionForm | MessageForm;
13
21
  components: FormComponent[];
14
22
  handle?(player: Player, values?: T[] | undefined): void;
@@ -1,4 +1,4 @@
1
- import { a as createActionForm, e as button, c as createModalForm, s as slider, d as dropdown, b as textField, t as toggle } from "../../components-BZCbUNW6.js";
1
+ import { a as createActionForm, d as createMessageForm, i as button, c as createModalForm, s as slider, f as dropdown, e as textField, t as toggle, h as header, g as divider, l as label } from "../../components-avk6bHuS.js";
2
2
  function ActionForm({
3
3
  title,
4
4
  body,
@@ -12,6 +12,31 @@ function ActionForm({
12
12
  buttons: children
13
13
  });
14
14
  }
15
+ const MessageForm = ({
16
+ title,
17
+ children = [],
18
+ previousForm,
19
+ yesLabel,
20
+ noLabel,
21
+ onClickYes = () => {
22
+ },
23
+ onClickNo = () => {
24
+ }
25
+ }) => {
26
+ return createMessageForm({
27
+ title,
28
+ body: typeof children === "object" ? children.join("\n") : children,
29
+ previousForm,
30
+ yes: {
31
+ text: yesLabel,
32
+ handler: onClickYes
33
+ },
34
+ no: {
35
+ text: noLabel,
36
+ handler: onClickNo
37
+ }
38
+ });
39
+ };
15
40
  function Button({
16
41
  iconPath = "",
17
42
  children = [],
@@ -26,6 +51,7 @@ function Button({
26
51
  }
27
52
  function ModalForm({
28
53
  title,
54
+ submitButtonText,
29
55
  previousForm,
30
56
  children = [],
31
57
  onSubmit = () => {
@@ -33,20 +59,21 @@ function ModalForm({
33
59
  }) {
34
60
  return createModalForm({
35
61
  title,
62
+ submitButtonText,
36
63
  previousForm,
37
64
  components: children,
38
65
  handle: onSubmit
39
66
  });
40
67
  }
41
68
  function Slider({
42
- label,
69
+ label: label2,
43
70
  min,
44
71
  max,
45
72
  step,
46
73
  defaultValue = min
47
74
  }) {
48
75
  return slider({
49
- label,
76
+ label: label2,
50
77
  min,
51
78
  max,
52
79
  step,
@@ -54,40 +81,53 @@ function Slider({
54
81
  });
55
82
  }
56
83
  function Dropdown({
57
- label,
84
+ label: label2,
58
85
  options,
59
86
  defaultValueIndex
60
87
  }) {
61
88
  return dropdown({
62
- label,
89
+ label: label2,
63
90
  options,
64
91
  defaultIndex: defaultValueIndex
65
92
  });
66
93
  }
67
94
  function Textfield({
68
- label,
69
- placeholder = "",
70
- defaultValue = ""
95
+ label: label2,
96
+ placeholder,
97
+ defaultValue,
98
+ tooltip
71
99
  }) {
72
100
  return textField({
73
- label,
101
+ label: label2,
74
102
  placeholder,
75
- default: defaultValue
103
+ default: defaultValue,
104
+ tooltip
76
105
  });
77
106
  }
78
107
  function Toggle({
79
- label,
108
+ label: label2,
80
109
  defaultValue = false
81
110
  }) {
82
111
  return toggle({
83
- label,
112
+ label: label2,
84
113
  default: defaultValue
85
114
  });
86
115
  }
116
+ const Header = ({ text }) => {
117
+ return header({ text });
118
+ };
119
+ const Divider = () => divider();
120
+ const Label = ({ text }) => {
121
+ return label({ text });
122
+ };
87
123
  export {
88
124
  ActionForm,
89
125
  Button,
126
+ Divider,
90
127
  Dropdown,
128
+ Header,
129
+ Label,
130
+ MessageForm,
91
131
  ModalForm,
92
132
  Slider,
93
133
  Textfield,
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { world, system } from "@minecraft/server";
2
- import { A, M, e, a, c, d, s, b, t } from "./components-BZCbUNW6.js";
3
- import { MessageFormData } from "@minecraft/server-ui";
2
+ import { A, b, M, i, a, d, c, g, f, h, l, s, e, t } from "./components-avk6bHuS.js";
4
3
  class Keystone {
5
4
  constructor() {
6
5
  }
@@ -24,8 +23,8 @@ const _VLQDecoder = class _VLQDecoder {
24
23
  const result = [];
25
24
  let shift = 0;
26
25
  let value = 0;
27
- for (let i = 0; i < str.length; i++) {
28
- const digit = this.BASE64_CHARS.indexOf(str[i]);
26
+ for (let i2 = 0; i2 < str.length; i2++) {
27
+ const digit = this.BASE64_CHARS.indexOf(str[i2]);
29
28
  if (digit === -1) continue;
30
29
  const continuation = (digit & 32) !== 0;
31
30
  value += (digit & 31) << shift;
@@ -141,11 +140,10 @@ class SourceMapDebugger {
141
140
  const output = [];
142
141
  output.push("");
143
142
  output.push(`${COLOR.yellow}━━━━━━━━━━━━━━━━━━━━━━${COLOR.reset}`);
144
- output.push(`${COLOR.bold}${COLOR.cyan}📍 DEBUG${COLOR.reset}`);
145
143
  let position = null;
146
144
  const offset = this.sourceMap?._offset || 0;
147
- for (let i = 2; i < Math.min(stackLines.length, 8); i++) {
148
- const line = stackLines[i];
145
+ for (let i2 = 2; i2 < Math.min(stackLines.length, 8); i2++) {
146
+ const line = stackLines[i2];
149
147
  const match = /(?:\()?(?:[A-Za-z0-9._/-]+):(\d+)(?::(\d+))?\)?$/.exec(line);
150
148
  if (match) {
151
149
  const rawLineNum = parseInt(match[1]);
@@ -157,17 +155,17 @@ class SourceMapDebugger {
157
155
  }
158
156
  if (position) {
159
157
  const file = position.source;
160
- output.push(`${COLOR.blue}📄 ${file}:${position.line}:${position.column}${COLOR.reset}`);
161
- if (position.name) output.push(`${COLOR.cyan}🏷 ${position.name}${COLOR.reset}`);
158
+ output.push(`${COLOR.blue}${file}:${position.line}:${position.column}${COLOR.reset}`);
159
+ if (position.name) output.push(`${COLOR.cyan}${position.name}${COLOR.reset}`);
162
160
  if (position.content) {
163
161
  const lines = position.content.split("\n");
164
162
  const target = position.line - 1;
165
163
  const range = 2;
166
164
  output.push(`${COLOR.gray}─────────────────────${COLOR.reset}`);
167
- for (let i = Math.max(0, target - range); i <= Math.min(lines.length - 1, target + range); i++) {
168
- const num = `${(i + 1).toString().padStart(3, " ")}`;
169
- const content = lines[i];
170
- if (i === target) {
165
+ for (let i2 = Math.max(0, target - range); i2 <= Math.min(lines.length - 1, target + range); i2++) {
166
+ const num = `${(i2 + 1).toString().padStart(3, " ")}`;
167
+ const content = lines[i2];
168
+ if (i2 === target) {
171
169
  output.push(`${COLOR.red}${COLOR.bold}→ ${num}: ${COLOR.white}${content}${COLOR.reset}`);
172
170
  } else {
173
171
  output.push(`${COLOR.gray} ${num}: ${content}${COLOR.reset}`);
@@ -175,11 +173,11 @@ class SourceMapDebugger {
175
173
  }
176
174
  }
177
175
  } else {
178
- output.push(`${COLOR.gray}📍 Location: (source map not available)${COLOR.reset}`);
176
+ output.push(`${COLOR.gray}Location: (source map not available)${COLOR.reset}`);
179
177
  }
180
178
  output.push(`${COLOR.gray}─────────────────────${COLOR.reset}`);
181
- output.push(`${COLOR.bold}${COLOR.white}💾 Values:${COLOR.reset}`);
182
- args.forEach((arg, i) => {
179
+ output.push(`${COLOR.bold}${COLOR.white}Values:${COLOR.reset}`);
180
+ args.forEach((arg, i2) => {
183
181
  let val;
184
182
  if (arg === void 0) val = "undefined";
185
183
  else if (arg === null) val = "null";
@@ -194,7 +192,7 @@ class SourceMapDebugger {
194
192
  } else {
195
193
  val = String(arg);
196
194
  }
197
- output.push(`${COLOR.green}[${i}]:${COLOR.reset} ${val}`);
195
+ output.push(`${COLOR.green}[${i2}]:${COLOR.reset} ${val}`);
198
196
  });
199
197
  output.push(`${COLOR.yellow}━━━━━━━━━━━━━━━━━━━━━━${COLOR.reset}`);
200
198
  console.log(output.join("\n"));
@@ -1041,50 +1039,32 @@ function waitUntil(condition, opts) {
1041
1039
  });
1042
1040
  });
1043
1041
  }
1044
- class MessageForm {
1045
- constructor(config) {
1046
- this.config = config;
1047
- }
1048
- async send(player) {
1049
- const form = new MessageFormData().title(this.config.title).body(this.config.body).button1(this.config.yes.text).button2(this.config.no.text);
1050
- const res = await form.show(player);
1051
- if (res.canceled) {
1052
- this.config.previousForm?.send(player);
1053
- return;
1054
- }
1055
- if (res.selection === 0) {
1056
- this.config.yes.handler(player);
1057
- } else if (res.selection === 1) {
1058
- this.config.no.handler(player);
1059
- }
1060
- }
1061
- }
1062
- function createMessageForm(config) {
1063
- return new MessageForm(config);
1064
- }
1065
1042
  export {
1066
1043
  A as ActionForm,
1067
1044
  AxisAlignedBB,
1068
1045
  DelayedTimer,
1069
1046
  EventManager,
1070
- MessageForm,
1047
+ b as MessageForm,
1071
1048
  M as ModalForm,
1072
1049
  Priority,
1073
1050
  RepeatingTimer,
1074
1051
  UntilTimer,
1075
1052
  Vector3,
1076
- e as button,
1053
+ i as button,
1077
1054
  a as createActionForm,
1078
- createMessageForm,
1055
+ d as createMessageForm,
1079
1056
  c as createModalForm,
1080
1057
  debug,
1081
1058
  delayed,
1082
- d as dropdown,
1059
+ g as divider,
1060
+ f as dropdown,
1061
+ h as header,
1083
1062
  keystone,
1063
+ l as label,
1084
1064
  repeating,
1085
1065
  sleep,
1086
1066
  s as slider,
1087
- b as textField,
1067
+ e as textField,
1088
1068
  t as toggle,
1089
1069
  until,
1090
1070
  waitUntil
@@ -1,4 +1,4 @@
1
- import { resolve } from "path";
1
+ import { resolve, relative } from "path";
2
2
  import * as crypto from "node:crypto";
3
3
  import * as fs from "node:fs";
4
4
  const behaviorPacker = ({
@@ -42,9 +42,14 @@ const behaviorPacker = ({
42
42
  for (const [, file] of Object.entries(bundle)) {
43
43
  if (file.type === "chunk" && file.map) {
44
44
  const sourceMapData = file.map;
45
+ const projectRoot = process.cwd();
46
+ const outputDir = resolve(projectRoot, options.dir || "dist/behavior_pack/scripts");
45
47
  const embeddedSourceMap = {
46
48
  version: sourceMapData.version,
47
- sources: sourceMapData.sources,
49
+ sources: sourceMapData.sources.map((source) => {
50
+ const absolutePath = resolve(outputDir, source);
51
+ return relative(projectRoot, absolutePath);
52
+ }),
48
53
  sourcesContent: sourceMapData.sourcesContent,
49
54
  mappings: sourceMapData.mappings,
50
55
  names: sourceMapData.names,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keystonemc",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "ScriptAPI Wrapper",
5
5
  "type": "module",
6
6
  "scripts": {