@kubohiroya/turbowarp-plus-editor-code-views 0.5.0 → 0.7.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.
@@ -0,0 +1,236 @@
1
+ import { type Plan, type Refusal, type VmLike } from './variable-merge-plan.ts';
2
+ export { applyPlan, findVariable, planMerge, planScopeChange, refreshEditor, undoPlan } from './variable-merge-plan.ts';
3
+ export type { Plan, PlanResult, Refusal, UndoRecord, VmLike, Warning } from './variable-merge-plan.ts';
4
+ /**
5
+ * Entry points for merging variables and changing their scope.
6
+ *
7
+ * - Renaming a variable or list to the name of another one it can see offers to merge it into
8
+ * that one, instead of only refusing.
9
+ * - The palette's variable and list blocks get "Make it for all sprites" / "Make it for this
10
+ * sprite only" in their context menu.
11
+ *
12
+ * Both go through scratch-blocks' own functions (`Variables.renameVariable`,
13
+ * `Variables.validateScalarVarOrListName_` and the data blocks' context menu mixins), so the fork
14
+ * needs no hook. The change itself is made on the VM and the workspace is reloaded from it.
15
+ */
16
+ type Kind = 'variable' | 'list';
17
+ declare const MESSAGES: {
18
+ en: {
19
+ variable: string;
20
+ list: string;
21
+ stage: string;
22
+ mergeTitle: (kind: Kind) => string;
23
+ mergeLead: (a: string, b: string) => string;
24
+ mergeBody: (a: string, b: string, n: number) => string;
25
+ perTarget: (target: string, n: number) => string;
26
+ values: (a: string, b: string, aValue: string, bValue: string) => string;
27
+ sensing: (n: number) => string;
28
+ makeGlobal: string;
29
+ makeLocal: string;
30
+ globalLead: (a: string) => string;
31
+ localLead: (a: string, sprite: string) => string;
32
+ warnShare: string;
33
+ warnSplit: string;
34
+ warnDynamic: string;
35
+ refusedTitle: string;
36
+ refusals: {
37
+ same: string;
38
+ missing: string;
39
+ type: string;
40
+ cloud: string;
41
+ stage: string;
42
+ 'not-visible': (owner: string, targets: string) => string;
43
+ 'used-elsewhere': (sprite: string, targets: string) => string;
44
+ 'name-taken': (targets: string) => string;
45
+ };
46
+ merge: string;
47
+ change: string;
48
+ cancel: string;
49
+ ok: string;
50
+ merged: (a: string, b: string) => string;
51
+ madeGlobal: (a: string) => string;
52
+ madeLocal: (a: string) => string;
53
+ undo: string;
54
+ undone: string;
55
+ close: string;
56
+ failed: string;
57
+ items: (n: number) => string;
58
+ };
59
+ ja: {
60
+ variable: string;
61
+ list: string;
62
+ stage: string;
63
+ mergeTitle: (kind: Kind) => string;
64
+ mergeLead: (a: string, b: string) => string;
65
+ mergeBody: (a: string, b: string, n: number) => string;
66
+ perTarget: (target: string, n: number) => string;
67
+ values: (a: string, b: string, aValue: string, bValue: string) => string;
68
+ sensing: (n: number) => string;
69
+ makeGlobal: string;
70
+ makeLocal: string;
71
+ globalLead: (a: string) => string;
72
+ localLead: (a: string, sprite: string) => string;
73
+ warnShare: string;
74
+ warnSplit: string;
75
+ warnDynamic: string;
76
+ refusedTitle: string;
77
+ refusals: {
78
+ same: string;
79
+ missing: string;
80
+ type: string;
81
+ cloud: string;
82
+ stage: string;
83
+ 'not-visible': (owner: string, targets: string) => string;
84
+ 'used-elsewhere': (sprite: string, targets: string) => string;
85
+ 'name-taken': (targets: string) => string;
86
+ };
87
+ merge: string;
88
+ change: string;
89
+ cancel: string;
90
+ ok: string;
91
+ merged: (a: string, b: string) => string;
92
+ madeGlobal: (a: string) => string;
93
+ madeLocal: (a: string) => string;
94
+ undo: string;
95
+ undone: string;
96
+ close: string;
97
+ failed: string;
98
+ items: (n: number) => string;
99
+ };
100
+ 'ja-hira': {
101
+ variable: string;
102
+ list: string;
103
+ stage: string;
104
+ mergeTitle: (kind: Kind) => string;
105
+ mergeLead: (a: string, b: string) => string;
106
+ mergeBody: (a: string, b: string, n: number) => string;
107
+ perTarget: (target: string, n: number) => string;
108
+ values: (a: string, b: string, aValue: string, bValue: string) => string;
109
+ sensing: (n: number) => string;
110
+ makeGlobal: string;
111
+ makeLocal: string;
112
+ globalLead: (a: string) => string;
113
+ localLead: (a: string, sprite: string) => string;
114
+ warnShare: string;
115
+ warnSplit: string;
116
+ warnDynamic: string;
117
+ refusedTitle: string;
118
+ refusals: {
119
+ same: string;
120
+ missing: string;
121
+ type: string;
122
+ cloud: string;
123
+ stage: string;
124
+ 'not-visible': (owner: string, targets: string) => string;
125
+ 'used-elsewhere': (sprite: string, targets: string) => string;
126
+ 'name-taken': (targets: string) => string;
127
+ };
128
+ merge: string;
129
+ change: string;
130
+ cancel: string;
131
+ ok: string;
132
+ merged: (a: string, b: string) => string;
133
+ madeGlobal: (a: string) => string;
134
+ madeLocal: (a: string) => string;
135
+ undo: string;
136
+ undone: string;
137
+ close: string;
138
+ failed: string;
139
+ items: (n: number) => string;
140
+ };
141
+ };
142
+ export type VariableMergeMessages = typeof MESSAGES.en;
143
+ /**
144
+ * Messages for a locale: `ja-Hira` gets hiragana, other `ja` Japanese, anything else English.
145
+ * @param {string} locale The editor's language.
146
+ * @returns {VariableMergeMessages} The messages.
147
+ */
148
+ export declare const variableMergeMessages: (locale: string) => VariableMergeMessages;
149
+ /**
150
+ * The sentences a confirmation shows for a plan.
151
+ * @param {Plan} plan The plan.
152
+ * @param {VariableMergeMessages} m The messages.
153
+ * @returns {{title: string, lead: string, details: string[], warnings: string[], confirm: string}} What to show.
154
+ */
155
+ export declare const describePlan: (plan: Plan, m: VariableMergeMessages) => {
156
+ title: string;
157
+ lead: string;
158
+ details: string[];
159
+ warnings: string[];
160
+ confirm: string;
161
+ };
162
+ /**
163
+ * The sentence for a refusal.
164
+ * @param {Refusal} refusal Why the change cannot be made.
165
+ * @param {VariableMergeMessages} m The messages.
166
+ * @returns {string} The sentence.
167
+ */
168
+ export declare const describeRefusal: (refusal: Refusal, m: VariableMergeMessages) => string;
169
+ /**
170
+ * Ask before a change, or explain why it cannot be made when there is no `onConfirm`.
171
+ * @returns {HTMLDialogElement} The open dialog.
172
+ */
173
+ export declare const openVariableMergeDialog: (document: Document, { title, lead, details, warnings, confirm, cancel, onConfirm }: {
174
+ title: string;
175
+ lead: string;
176
+ details?: string[];
177
+ warnings?: string[];
178
+ confirm: string;
179
+ cancel?: string;
180
+ onConfirm?: () => void;
181
+ }) => HTMLDialogElement;
182
+ /**
183
+ * Say what changed, with an Undo button when the change can be undone. One notice per document:
184
+ * a new one replaces the last. It hides after `timeout` ms unless the pointer or focus is on it.
185
+ * @returns {() => void} A function that removes it.
186
+ */
187
+ export declare const showVariableMergeNotice: (document: Document, text: string, m: VariableMergeMessages, onUndo?: () => void, timeout?: number) => () => void;
188
+ type ScratchBlocksLike = {
189
+ Variables?: Record<string, unknown> & {
190
+ renameVariable?: (...args: unknown[]) => unknown;
191
+ createVariable?: (...args: unknown[]) => unknown;
192
+ validateScalarVarOrListName_?: (...args: unknown[]) => unknown;
193
+ trimName_?: (name: string) => string;
194
+ CLOUD_PREFIX?: string;
195
+ };
196
+ Constants?: {
197
+ Data?: Record<string, {
198
+ customContextMenu?: (options: unknown[]) => void;
199
+ }>;
200
+ };
201
+ ScratchMsgs?: {
202
+ currentLocale_?: string;
203
+ };
204
+ getMainWorkspace?: () => unknown;
205
+ };
206
+ /**
207
+ * Patch ScratchBlocks so renames offer merging and the palette offers scope changes.
208
+ * @param {VmLike} vm The VM; its `blockListener` identifies the code area's workspace.
209
+ * @param {object} ScratchBlocks The loaded ScratchBlocks.
210
+ * @param {object} options How to find the document and the language, and where errors go.
211
+ * @returns {() => void} A function that removes the patches.
212
+ */
213
+ export declare function installVariableMerge(vm: VmLike & {
214
+ blockListener?: unknown;
215
+ }, ScratchBlocks: ScratchBlocksLike, { document: fallbackDocument, locale, onError }?: {
216
+ document?: Document;
217
+ locale?: string | (() => string);
218
+ onError?: (error: unknown) => void;
219
+ }): () => void;
220
+ /**
221
+ * Install the merge and scope-change entry points once ScratchBlocks has loaded.
222
+ * @param {object} options The VM, how to get ScratchBlocks, and optionally the document and language.
223
+ * @returns {{ready: Promise<void>, dispose(): void}} Resolves once installed; dispose removes the patches.
224
+ */
225
+ export declare function attachVariableMerge({ vm, getBlockly, document, locale, onError }: {
226
+ vm: VmLike & {
227
+ blockListener?: unknown;
228
+ };
229
+ getBlockly: () => ScratchBlocksLike | Promise<ScratchBlocksLike>;
230
+ document?: Document;
231
+ locale?: string | (() => string);
232
+ onError?: (error: unknown) => void;
233
+ }): {
234
+ ready: Promise<void>;
235
+ dispose(): void;
236
+ };