intelligent-system-design-language 0.3.21 → 0.3.23
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/.claude/agents/langium-language-designer.md +38 -38
- package/.claude/agents/typescript-vscode-expert.md +29 -29
- package/.claude/agents/ui-ux-designer.md +36 -36
- package/.claude/settings.local.json +33 -33
- package/.idea/inspectionProfiles/Project_Default.xml +6 -6
- package/.idea/isdl.iml +13 -13
- package/.idea/modules.xml +8 -8
- package/.idea/vcs.xml +6 -6
- package/.idea/watcherTasks.xml +3 -3
- package/.vscodeignore +18 -18
- package/LICENSE +673 -673
- package/README.md +86 -86
- package/bin/cli.js +4 -4
- package/bin/lsp.js +8 -8
- package/out/_backgrounds.scss +91 -91
- package/out/_handlebars.scss +497 -497
- package/out/_isdlStyles.scss +1444 -1381
- package/out/_vuetifyOverrides.scss +425 -425
- package/out/_vuetifyStyles.scss +31957 -31957
- package/out/cli/components/_backgrounds.scss +91 -91
- package/out/cli/components/_handlebars.scss +497 -497
- package/out/cli/components/_isdlStyles.scss +1444 -1381
- package/out/cli/components/_vuetifyOverrides.scss +425 -425
- package/out/cli/components/_vuetifyStyles.scss +31957 -31957
- package/out/cli/components/active-effect-sheet-generator.js +453 -453
- package/out/cli/components/chat-card-generator.js +654 -651
- package/out/cli/components/chat-card-generator.js.map +1 -1
- package/out/cli/components/css-generator.js +4 -4
- package/out/cli/components/damage-roll-generator.js +160 -160
- package/out/cli/components/datamodel-generator.js +264 -257
- package/out/cli/components/datamodel-generator.js.map +1 -1
- package/out/cli/components/derived-data-generator.js +923 -923
- package/out/cli/components/hotbar-drop-hook-generator.js +82 -82
- package/out/cli/components/init-hook-generator.js +495 -495
- package/out/cli/components/language-generator.js +1 -1
- package/out/cli/components/language-generator.js.map +1 -1
- package/out/cli/components/measured-template-preview.js +221 -221
- package/out/cli/components/method-generator.js +979 -887
- package/out/cli/components/method-generator.js.map +1 -1
- package/out/cli/components/ready-hook-generator.js +404 -404
- package/out/cli/components/token-generator.js +116 -116
- package/out/cli/components/vue/base-components/vue-attribute.js +138 -138
- package/out/cli/components/vue/base-components/vue-boolean.js +64 -64
- package/out/cli/components/vue/base-components/vue-calculator.js +93 -93
- package/out/cli/components/vue/base-components/vue-damage-application.js +356 -356
- package/out/cli/components/vue/base-components/vue-damage-bonuses.js +165 -165
- package/out/cli/components/vue/base-components/vue-damage-resistances.js +196 -196
- package/out/cli/components/vue/base-components/vue-damage-track.js +121 -121
- package/out/cli/components/vue/base-components/vue-date-time.js +42 -42
- package/out/cli/components/vue/base-components/vue-dice.js +98 -98
- package/out/cli/components/vue/base-components/vue-die.js +73 -73
- package/out/cli/components/vue/base-components/vue-document-choice.js +149 -149
- package/out/cli/components/vue/base-components/vue-document-choices.js +179 -179
- package/out/cli/components/vue/base-components/vue-document-link.js +60 -60
- package/out/cli/components/vue/base-components/vue-extended-choice.js +88 -88
- package/out/cli/components/vue/base-components/vue-inventory.js +519 -519
- package/out/cli/components/vue/base-components/vue-macro-choice.js +138 -138
- package/out/cli/components/vue/base-components/vue-measured-template.js +530 -530
- package/out/cli/components/vue/base-components/vue-money.js +483 -483
- package/out/cli/components/vue/base-components/vue-number.js +174 -174
- package/out/cli/components/vue/base-components/vue-paperdoll.js +43 -43
- package/out/cli/components/vue/base-components/vue-parent-property-reference.js +76 -76
- package/out/cli/components/vue/base-components/vue-prosemirror.js +18 -18
- package/out/cli/components/vue/base-components/vue-resource.js +136 -136
- package/out/cli/components/vue/base-components/vue-roll-visualizer.js +286 -109
- package/out/cli/components/vue/base-components/vue-roll-visualizer.js.map +1 -1
- package/out/cli/components/vue/base-components/vue-self-property-reference.js +62 -62
- package/out/cli/components/vue/base-components/vue-string-choice.js +98 -98
- package/out/cli/components/vue/base-components/vue-string-choices.js +203 -203
- package/out/cli/components/vue/base-components/vue-string.js +60 -60
- package/out/cli/components/vue/base-components/vue-text-field.js +53 -53
- package/out/cli/components/vue/base-components/vue-tracker.js +431 -431
- package/out/cli/components/vue/vue-action-component-generator.js +64 -64
- package/out/cli/components/vue/vue-active-effect-sheet-generator.js +856 -856
- package/out/cli/components/vue/vue-datatable-sheet-class-generator.js +292 -292
- package/out/cli/components/vue/vue-datatable2-component-generator.js +824 -824
- package/out/cli/components/vue/vue-document-creation-app.js +121 -121
- package/out/cli/components/vue/vue-document-creation-sheet.js +94 -94
- package/out/cli/components/vue/vue-generator.js +40 -40
- package/out/cli/components/vue/vue-mixin.js +296 -296
- package/out/cli/components/vue/vue-pinned-datatable-component-generator.js +260 -260
- package/out/cli/components/vue/vue-prompt-generator.js +91 -76
- package/out/cli/components/vue/vue-prompt-generator.js.map +1 -1
- package/out/cli/components/vue/vue-prompt-sheet-class-generator.js +317 -317
- package/out/cli/components/vue/vue-sheet-application-generator.js +1177 -1167
- package/out/cli/components/vue/vue-sheet-application-generator.js.map +1 -1
- package/out/cli/components/vue/vue-sheet-class-generator.js +510 -510
- package/out/cli/generator.js +438 -433
- package/out/cli/generator.js.map +1 -1
- package/out/extension/github/githubAuthProvider.js +71 -29
- package/out/extension/github/githubAuthProvider.js.map +1 -1
- package/out/extension/github/githubGistManager.js +4 -3
- package/out/extension/github/githubGistManager.js.map +1 -1
- package/out/extension/github/githubManager.js +40 -38
- package/out/extension/github/githubManager.js.map +1 -1
- package/out/extension/github/githubQuickActions.js +120 -120
- package/out/extension/github/system-workflow.yml +47 -47
- package/out/extension/main.cjs +909 -532
- package/out/extension/main.cjs.map +3 -3
- package/out/extension/package.json +419 -419
- package/out/language/generated/ast.js +51 -2
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.js +14240 -13991
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/intelligent-system-design-language-validator.js +32 -2
- package/out/language/intelligent-system-design-language-validator.js.map +1 -1
- package/out/language/isdl-scope-provider.js +14 -1
- package/out/language/isdl-scope-provider.js.map +1 -1
- package/out/language/main.cjs +913 -569
- package/out/language/main.cjs.map +3 -3
- package/out/package.json +419 -419
- package/out/progressbar.min.js +6 -6
- package/out/styles.scss +762 -747
- package/out/test/validating/diagnostics.test.js +40 -0
- package/out/test/validating/diagnostics.test.js.map +1 -1
- package/package.json +419 -419
|
@@ -49,12 +49,12 @@ export function generatePromptSheetClass(name, entry, id, document, prompt, dest
|
|
|
49
49
|
: expandToNode `return ${isStringLiteral ? `"${valueExpr}"` : valueExpr};`;
|
|
50
50
|
return { name: p.name.toLowerCase(), body };
|
|
51
51
|
}).filter((x) => x !== undefined);
|
|
52
|
-
const valueFieldSeeds = joinToNode(valueFields.map(vf => expandToNode `
|
|
53
|
-
const ${vf.name}ValueFunc = (system) => {
|
|
54
|
-
const context = { object: this.document };
|
|
55
|
-
${vf.body}
|
|
56
|
-
};
|
|
57
|
-
foundry.utils.setProperty(this.#promptData, "${promptPath}.${vf.name}", ${vf.name}ValueFunc(this.document.system));
|
|
52
|
+
const valueFieldSeeds = joinToNode(valueFields.map(vf => expandToNode `
|
|
53
|
+
const ${vf.name}ValueFunc = (system) => {
|
|
54
|
+
const context = { object: this.document };
|
|
55
|
+
${vf.body}
|
|
56
|
+
};
|
|
57
|
+
foundry.utils.setProperty(this.#promptData, "${promptPath}.${vf.name}", ${vf.name}ValueFunc(this.document.system));
|
|
58
58
|
`), { appendNewLineIfNotEmpty: true });
|
|
59
59
|
const generatedFileDir = path.join(destination, "system", "sheets", "vue", type, "prompts");
|
|
60
60
|
const generatedFilePath = path.join(generatedFileDir, `${document.name.toLowerCase()}-${name}-prompt-app.mjs`);
|
|
@@ -62,317 +62,317 @@ export function generatePromptSheetClass(name, entry, id, document, prompt, dest
|
|
|
62
62
|
fs.mkdirSync(generatedFileDir, { recursive: true });
|
|
63
63
|
}
|
|
64
64
|
const vueComponentName = `${document.name.toLowerCase()}-${type}-${name.toLowerCase()}-prompt`;
|
|
65
|
-
const fileNode = expandToNode `
|
|
66
|
-
import VueRenderingMixin from '../../VueRenderingMixin.mjs';
|
|
67
|
-
import { ${document.name}${titleize(type)}${name}Prompt } from "../../components/components.vue.es.mjs";
|
|
68
|
-
|
|
69
|
-
export default class ${document.name}${name}PromptApp extends VueRenderingMixin(foundry.applications.api.ApplicationV2) {
|
|
70
|
-
|
|
71
|
-
document;
|
|
72
|
-
promptResolve;
|
|
73
|
-
#promptResolved = false;
|
|
74
|
-
constructor(document, options = {}) {
|
|
75
|
-
super(options);
|
|
76
|
-
this.#dragDrop = this.#createDragDropHandlers();
|
|
77
|
-
this.document = document;
|
|
78
|
-
this.promptResolve = options.promptResolve;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Plain, writable scratch copy of the document's system data that the Vue v-models bind
|
|
82
|
-
// to (context.system points here). Using a toObject() clone -- not the live DataModel --
|
|
83
|
-
// means every field type is writable, including getter-only document-reference fields.
|
|
84
|
-
#promptData;
|
|
85
|
-
|
|
86
|
-
// Resolve the awaiting action with the user's input, harvested from the scratch data.
|
|
87
|
-
// Shape matches the legacy dialog path: { ...fields, system: { ...fields } } so
|
|
88
|
-
// userInput.X access is unchanged.
|
|
89
|
-
_resolvePrompt() {
|
|
90
|
-
if (this.#promptResolved) return;
|
|
91
|
-
this.#promptResolved = true;
|
|
92
|
-
// Read from the live reactive context the inputs actually wrote to (not #promptData,
|
|
93
|
-
// which _prepareContext reassigns on every render).
|
|
94
|
-
const liveSystem = this.vueRoot?.context?.system ?? this.#promptData;
|
|
95
|
-
const data = foundry.utils.deepClone(foundry.utils.getProperty(liveSystem, "${promptPath}")) ?? {};
|
|
96
|
-
// Flatten single-choice fields ({value,icon,color}) to their chosen value.
|
|
97
|
-
for (const key of ${JSON.stringify(choiceFieldNames)}) {
|
|
98
|
-
if (data[key] && typeof data[key] === "object" && "value" in data[key]) data[key] = data[key].value;
|
|
99
|
-
}
|
|
100
|
-
// Flatten dice fields ({die, number}) to their formula string (number + die).
|
|
101
|
-
for (const key of ${JSON.stringify(diceFieldNames)}) {
|
|
102
|
-
if (data[key] && typeof data[key] === "object" && "die" in data[key]) data[key] = \`\${data[key].number}\${data[key].die}\`;
|
|
103
|
-
}
|
|
104
|
-
this.promptResolve?.({ ...data, system: data });
|
|
105
|
-
this.close();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
_cancelPrompt() {
|
|
109
|
-
if (this.#promptResolved) return;
|
|
110
|
-
this.#promptResolved = true;
|
|
111
|
-
this.promptResolve?.({});
|
|
112
|
-
this.close();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async close(options = {}) {
|
|
116
|
-
// If closed without an explicit submit/cancel, don't leave the action hanging.
|
|
117
|
-
if (!this.#promptResolved) {
|
|
118
|
-
this.#promptResolved = true;
|
|
119
|
-
this.promptResolve?.({});
|
|
120
|
-
}
|
|
121
|
-
return super.close(options);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
vueParts = {
|
|
125
|
-
"${vueComponentName}": {
|
|
126
|
-
component: ${document.name}${titleize(type)}${name}Prompt,
|
|
127
|
-
template: "<${vueComponentName} :context=\\"context\\">Vue rendering for application failed.</${vueComponentName}>"
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
_arrayEntryKey = 0;
|
|
132
|
-
_renderKey = 0;
|
|
133
|
-
|
|
134
|
-
/** @override */
|
|
135
|
-
static DEFAULT_OPTIONS = {
|
|
136
|
-
classes: ["${id}", "dialog", "vue-sheet", "isdl-prompt", "${type}", "${document.name.toLowerCase()}-prompt"],
|
|
137
|
-
position: {
|
|
138
|
-
width: 400,
|
|
139
|
-
// Size to content so short prompts aren't a tall window of empty space; the
|
|
140
|
-
// window's max-height: 100% caps tall prompts, at which point the field list
|
|
141
|
-
// scrolls and the Submit/Cancel footer stays pinned.
|
|
142
|
-
height: "auto",
|
|
143
|
-
},
|
|
144
|
-
window: {
|
|
145
|
-
resizable: true,
|
|
146
|
-
title: "${name} Prompt",
|
|
147
|
-
},
|
|
148
|
-
tag: "form",
|
|
149
|
-
actions: {
|
|
150
|
-
},
|
|
151
|
-
changeActions: {
|
|
152
|
-
},
|
|
153
|
-
// Custom property that's merged into this.options
|
|
154
|
-
dragDrop: [
|
|
155
|
-
{dropSelector: ".single-document"},
|
|
156
|
-
{dragSelector: ".paper-doll-slot", dropSelector: ".paper-doll-slot"}
|
|
157
|
-
],
|
|
158
|
-
form: {
|
|
159
|
-
submitOnChange: false,
|
|
160
|
-
submitOnClose: false,
|
|
161
|
-
closeOnSubmit: false,
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
async _prepareContext(options) {
|
|
166
|
-
// Fresh, writable scratch copy of system data for the prompt's inputs to bind to.
|
|
167
|
-
this.#promptData = foundry.utils.deepClone(this.document.toObject().system);
|
|
168
|
-
|
|
169
|
-
// Seed calculated (value:) fields with their computed result so they display
|
|
170
|
-
// read-only. Evaluated once here against the live document; a value expression
|
|
171
|
-
// that references a sibling prompt field uses prep-time values, not live input.
|
|
172
|
-
${valueFieldSeeds}
|
|
173
|
-
// Output initialization
|
|
174
|
-
const context = {
|
|
175
|
-
// Validates both permissions and compendium status
|
|
176
|
-
editable: true,
|
|
177
|
-
owner: this.document.isOwner,
|
|
178
|
-
limited: this.document.limited,
|
|
179
|
-
|
|
180
|
-
// Add the document.
|
|
181
|
-
object: this.document.toObject(),
|
|
182
|
-
document: this.document,
|
|
183
|
-
|
|
184
|
-
// Add the data to context.data for easier access, as well as flags.
|
|
185
|
-
system: this.#promptData,
|
|
186
|
-
flags: this.document.flags,
|
|
187
|
-
|
|
188
|
-
// Roll data.
|
|
189
|
-
rollData: this.document.getRollData() ?? {},
|
|
190
|
-
|
|
191
|
-
// Editors
|
|
192
|
-
editors: {},
|
|
193
|
-
|
|
194
|
-
// Force re-renders. Defined in the vue mixin.
|
|
195
|
-
_renderKey: this._renderKey ?? 0,
|
|
196
|
-
_arrayEntryKey: this._arrayEntryKey ?? 0,
|
|
197
|
-
|
|
198
|
-
// Necessary for formInput and formFields helpers
|
|
199
|
-
fields: this.document.schema.fields,
|
|
200
|
-
systemFields: this.document.system.schema.fields
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// Callbacks the Vue Submit/Cancel buttons invoke.
|
|
204
|
-
context.promptSubmit = () => this._resolvePrompt();
|
|
205
|
-
context.promptCancel = () => this._cancelPrompt();
|
|
206
|
-
|
|
207
|
-
return context;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Field components (i-die, i-money, etc.) inject "rawDocument" and call .update() to
|
|
211
|
-
// persist on change. A prompt is transient scratch input, so override rawDocument with
|
|
212
|
-
// a proxy whose .update() is a no-op: fields still read/write the in-memory context
|
|
213
|
-
// (which we harvest on submit), but nothing is written to the actual document.
|
|
214
|
-
_getProvidedData() {
|
|
215
|
-
const realDocument = this.document;
|
|
216
|
-
const noPersistDocument = new Proxy(realDocument, {
|
|
217
|
-
get(target, prop) {
|
|
218
|
-
if (prop === "update" || prop === "updateSource") return async () => {};
|
|
219
|
-
const value = target[prop];
|
|
220
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
return { rawDocument: noPersistDocument };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Actions performed after any render of the Application.
|
|
228
|
-
* Post-render steps are not awaited by the render process.
|
|
229
|
-
* @param {ApplicationRenderContext} context Prepared context data
|
|
230
|
-
* @param {RenderOptions} options Provided render options
|
|
231
|
-
* @protected
|
|
232
|
-
*/
|
|
233
|
-
_onRender(context, options) {
|
|
234
|
-
this.#dragDrop.forEach((d) => d.bind(this.element));
|
|
235
|
-
// You may want to add other special handling here
|
|
236
|
-
// Foundry comes with a large number of utility classes, e.g. SearchFilter
|
|
237
|
-
// That you may want to implement yourself.
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
// Drag and Drop
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Returns an array of DragDrop instances
|
|
245
|
-
* @type {DragDrop[]}
|
|
246
|
-
*/
|
|
247
|
-
get dragDrop() {
|
|
248
|
-
return this.#dragDrop;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Define whether a user is able to begin a dragstart workflow for a given drag selector
|
|
253
|
-
* @param {string} selector The candidate HTML selector for dragging
|
|
254
|
-
* @returns {boolean} Can the current user drag this selector?
|
|
255
|
-
* @protected
|
|
256
|
-
*/
|
|
257
|
-
_canDragStart(selector) {
|
|
258
|
-
return this.isEditable;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector
|
|
263
|
-
* @param {string} selector The candidate HTML selector for the drop target
|
|
264
|
-
* @returns {boolean} Can the current user drop on this selector?
|
|
265
|
-
* @protected
|
|
266
|
-
*/
|
|
267
|
-
_canDragDrop(selector) {
|
|
268
|
-
return this.isEditable;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Callback actions which occur at the beginning of a drag start workflow.
|
|
273
|
-
* @param {DragEvent} event The originating DragEvent
|
|
274
|
-
* @protected
|
|
275
|
-
*/
|
|
276
|
-
_onDragStart(event) {
|
|
277
|
-
console.log("Drag Start");
|
|
278
|
-
|
|
279
|
-
if (event.currentTarget.classList.contains("paper-doll-slot")) {
|
|
280
|
-
// Remove the item from the slot
|
|
281
|
-
const name = event.currentTarget.dataset.name;
|
|
282
|
-
const update = {};
|
|
283
|
-
update[name] = null;
|
|
284
|
-
this.document.update(update);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
const tr = event.currentTarget.closest("tr");
|
|
288
|
-
const data = {
|
|
289
|
-
type: tr.dataset.type == "ActiveEffect" ? "ActiveEffect" : "Item",
|
|
290
|
-
uuid: tr.dataset.uuid
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
event.dataTransfer.setData("text/plain", JSON.stringify(data));
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Callback actions which occur when a dragged element is over a drop target.
|
|
299
|
-
* @param {DragEvent} event The originating DragEvent
|
|
300
|
-
* @protected
|
|
301
|
-
*/
|
|
302
|
-
_onDragOver(event) {}
|
|
303
|
-
|
|
304
|
-
/* -------------------------------------------- */
|
|
305
|
-
|
|
306
|
-
async _onDrop(event) {
|
|
307
|
-
const data = JSON.parse(event.dataTransfer.getData("text/plain"));
|
|
308
|
-
|
|
309
|
-
// If the drop target is a single document, handle it differently
|
|
310
|
-
const linkedClasses = [ "single-document", "paper-doll-slot" ];
|
|
311
|
-
const eventClasses = Array.from(event.currentTarget.classList);
|
|
312
|
-
if (eventClasses.find(c => linkedClasses.includes(c))) {
|
|
313
|
-
const doc = await fromUuid(data.uuid);
|
|
314
|
-
if ( !doc ) return;
|
|
315
|
-
if ( doc.type !== event.currentTarget.dataset.type ) {
|
|
316
|
-
ui.notifications.error(\`Expected a \${event.currentTarget.dataset.type} type Document, but got a \${doc.type} type one instead. \`);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const update = {};
|
|
321
|
-
update[event.currentTarget.dataset.name] = data.uuid;
|
|
322
|
-
await this.document.update(update);
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const dropTypes = ["Item", "ActiveEffect"];
|
|
327
|
-
if ( !dropTypes.includes(data.type) ) return;
|
|
328
|
-
const item = await fromUuid(data.uuid);
|
|
329
|
-
if ( !item ) return;
|
|
330
|
-
|
|
331
|
-
// Prevent duplicates when dropping an item that's already owned by this document
|
|
332
|
-
if ( item.parent?.uuid === this.document.uuid ) return;
|
|
333
|
-
|
|
334
|
-
if ( data.type === "ActiveEffect" ) {
|
|
335
|
-
ActiveEffect.createDocuments([item], {parent: this.document})
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
Item.createDocuments([item], {parent: this.document})
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/* -------------------------------------------- */
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Returns an array of DragDrop instances
|
|
346
|
-
* @type {DragDrop[]}
|
|
347
|
-
*/
|
|
348
|
-
get dragDrop() {
|
|
349
|
-
return this.#dragDrop;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// This is marked as private because there's no real need
|
|
353
|
-
// for subclasses or external hooks to mess with it directly
|
|
354
|
-
#dragDrop;
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Create drag-and-drop workflow handlers for this Application
|
|
358
|
-
* @returns {DragDrop[]} An array of DragDrop handlers
|
|
359
|
-
* @private
|
|
360
|
-
*/
|
|
361
|
-
#createDragDropHandlers() {
|
|
362
|
-
return this.options.dragDrop.map((d) => {
|
|
363
|
-
d.permissions = {
|
|
364
|
-
dragstart: this._canDragStart.bind(this),
|
|
365
|
-
drop: this._canDragDrop.bind(this)
|
|
366
|
-
};
|
|
367
|
-
d.callbacks = {
|
|
368
|
-
dragstart: this._onDragStart.bind(this),
|
|
369
|
-
dragover: this._onDragOver.bind(this),
|
|
370
|
-
drop: this._onDrop.bind(this)
|
|
371
|
-
};
|
|
372
|
-
return new DragDrop(d);
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
}
|
|
65
|
+
const fileNode = expandToNode `
|
|
66
|
+
import VueRenderingMixin from '../../VueRenderingMixin.mjs';
|
|
67
|
+
import { ${document.name}${titleize(type)}${name}Prompt } from "../../components/components.vue.es.mjs";
|
|
68
|
+
|
|
69
|
+
export default class ${document.name}${name}PromptApp extends VueRenderingMixin(foundry.applications.api.ApplicationV2) {
|
|
70
|
+
|
|
71
|
+
document;
|
|
72
|
+
promptResolve;
|
|
73
|
+
#promptResolved = false;
|
|
74
|
+
constructor(document, options = {}) {
|
|
75
|
+
super(options);
|
|
76
|
+
this.#dragDrop = this.#createDragDropHandlers();
|
|
77
|
+
this.document = document;
|
|
78
|
+
this.promptResolve = options.promptResolve;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Plain, writable scratch copy of the document's system data that the Vue v-models bind
|
|
82
|
+
// to (context.system points here). Using a toObject() clone -- not the live DataModel --
|
|
83
|
+
// means every field type is writable, including getter-only document-reference fields.
|
|
84
|
+
#promptData;
|
|
85
|
+
|
|
86
|
+
// Resolve the awaiting action with the user's input, harvested from the scratch data.
|
|
87
|
+
// Shape matches the legacy dialog path: { ...fields, system: { ...fields } } so
|
|
88
|
+
// userInput.X access is unchanged.
|
|
89
|
+
_resolvePrompt() {
|
|
90
|
+
if (this.#promptResolved) return;
|
|
91
|
+
this.#promptResolved = true;
|
|
92
|
+
// Read from the live reactive context the inputs actually wrote to (not #promptData,
|
|
93
|
+
// which _prepareContext reassigns on every render).
|
|
94
|
+
const liveSystem = this.vueRoot?.context?.system ?? this.#promptData;
|
|
95
|
+
const data = foundry.utils.deepClone(foundry.utils.getProperty(liveSystem, "${promptPath}")) ?? {};
|
|
96
|
+
// Flatten single-choice fields ({value,icon,color}) to their chosen value.
|
|
97
|
+
for (const key of ${JSON.stringify(choiceFieldNames)}) {
|
|
98
|
+
if (data[key] && typeof data[key] === "object" && "value" in data[key]) data[key] = data[key].value;
|
|
99
|
+
}
|
|
100
|
+
// Flatten dice fields ({die, number}) to their formula string (number + die).
|
|
101
|
+
for (const key of ${JSON.stringify(diceFieldNames)}) {
|
|
102
|
+
if (data[key] && typeof data[key] === "object" && "die" in data[key]) data[key] = \`\${data[key].number}\${data[key].die}\`;
|
|
103
|
+
}
|
|
104
|
+
this.promptResolve?.({ ...data, system: data });
|
|
105
|
+
this.close();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_cancelPrompt() {
|
|
109
|
+
if (this.#promptResolved) return;
|
|
110
|
+
this.#promptResolved = true;
|
|
111
|
+
this.promptResolve?.({});
|
|
112
|
+
this.close();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async close(options = {}) {
|
|
116
|
+
// If closed without an explicit submit/cancel, don't leave the action hanging.
|
|
117
|
+
if (!this.#promptResolved) {
|
|
118
|
+
this.#promptResolved = true;
|
|
119
|
+
this.promptResolve?.({});
|
|
120
|
+
}
|
|
121
|
+
return super.close(options);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
vueParts = {
|
|
125
|
+
"${vueComponentName}": {
|
|
126
|
+
component: ${document.name}${titleize(type)}${name}Prompt,
|
|
127
|
+
template: "<${vueComponentName} :context=\\"context\\">Vue rendering for application failed.</${vueComponentName}>"
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
_arrayEntryKey = 0;
|
|
132
|
+
_renderKey = 0;
|
|
133
|
+
|
|
134
|
+
/** @override */
|
|
135
|
+
static DEFAULT_OPTIONS = {
|
|
136
|
+
classes: ["${id}", "dialog", "vue-sheet", "isdl-prompt", "${type}", "${document.name.toLowerCase()}-prompt"],
|
|
137
|
+
position: {
|
|
138
|
+
width: 400,
|
|
139
|
+
// Size to content so short prompts aren't a tall window of empty space; the
|
|
140
|
+
// window's max-height: 100% caps tall prompts, at which point the field list
|
|
141
|
+
// scrolls and the Submit/Cancel footer stays pinned.
|
|
142
|
+
height: "auto",
|
|
143
|
+
},
|
|
144
|
+
window: {
|
|
145
|
+
resizable: true,
|
|
146
|
+
title: "${name} Prompt",
|
|
147
|
+
},
|
|
148
|
+
tag: "form",
|
|
149
|
+
actions: {
|
|
150
|
+
},
|
|
151
|
+
changeActions: {
|
|
152
|
+
},
|
|
153
|
+
// Custom property that's merged into this.options
|
|
154
|
+
dragDrop: [
|
|
155
|
+
{dropSelector: ".single-document"},
|
|
156
|
+
{dragSelector: ".paper-doll-slot", dropSelector: ".paper-doll-slot"}
|
|
157
|
+
],
|
|
158
|
+
form: {
|
|
159
|
+
submitOnChange: false,
|
|
160
|
+
submitOnClose: false,
|
|
161
|
+
closeOnSubmit: false,
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
async _prepareContext(options) {
|
|
166
|
+
// Fresh, writable scratch copy of system data for the prompt's inputs to bind to.
|
|
167
|
+
this.#promptData = foundry.utils.deepClone(this.document.toObject().system);
|
|
168
|
+
|
|
169
|
+
// Seed calculated (value:) fields with their computed result so they display
|
|
170
|
+
// read-only. Evaluated once here against the live document; a value expression
|
|
171
|
+
// that references a sibling prompt field uses prep-time values, not live input.
|
|
172
|
+
${valueFieldSeeds}
|
|
173
|
+
// Output initialization
|
|
174
|
+
const context = {
|
|
175
|
+
// Validates both permissions and compendium status
|
|
176
|
+
editable: true,
|
|
177
|
+
owner: this.document.isOwner,
|
|
178
|
+
limited: this.document.limited,
|
|
179
|
+
|
|
180
|
+
// Add the document.
|
|
181
|
+
object: this.document.toObject(),
|
|
182
|
+
document: this.document,
|
|
183
|
+
|
|
184
|
+
// Add the data to context.data for easier access, as well as flags.
|
|
185
|
+
system: this.#promptData,
|
|
186
|
+
flags: this.document.flags,
|
|
187
|
+
|
|
188
|
+
// Roll data.
|
|
189
|
+
rollData: this.document.getRollData() ?? {},
|
|
190
|
+
|
|
191
|
+
// Editors
|
|
192
|
+
editors: {},
|
|
193
|
+
|
|
194
|
+
// Force re-renders. Defined in the vue mixin.
|
|
195
|
+
_renderKey: this._renderKey ?? 0,
|
|
196
|
+
_arrayEntryKey: this._arrayEntryKey ?? 0,
|
|
197
|
+
|
|
198
|
+
// Necessary for formInput and formFields helpers
|
|
199
|
+
fields: this.document.schema.fields,
|
|
200
|
+
systemFields: this.document.system.schema.fields
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Callbacks the Vue Submit/Cancel buttons invoke.
|
|
204
|
+
context.promptSubmit = () => this._resolvePrompt();
|
|
205
|
+
context.promptCancel = () => this._cancelPrompt();
|
|
206
|
+
|
|
207
|
+
return context;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Field components (i-die, i-money, etc.) inject "rawDocument" and call .update() to
|
|
211
|
+
// persist on change. A prompt is transient scratch input, so override rawDocument with
|
|
212
|
+
// a proxy whose .update() is a no-op: fields still read/write the in-memory context
|
|
213
|
+
// (which we harvest on submit), but nothing is written to the actual document.
|
|
214
|
+
_getProvidedData() {
|
|
215
|
+
const realDocument = this.document;
|
|
216
|
+
const noPersistDocument = new Proxy(realDocument, {
|
|
217
|
+
get(target, prop) {
|
|
218
|
+
if (prop === "update" || prop === "updateSource") return async () => {};
|
|
219
|
+
const value = target[prop];
|
|
220
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return { rawDocument: noPersistDocument };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Actions performed after any render of the Application.
|
|
228
|
+
* Post-render steps are not awaited by the render process.
|
|
229
|
+
* @param {ApplicationRenderContext} context Prepared context data
|
|
230
|
+
* @param {RenderOptions} options Provided render options
|
|
231
|
+
* @protected
|
|
232
|
+
*/
|
|
233
|
+
_onRender(context, options) {
|
|
234
|
+
this.#dragDrop.forEach((d) => d.bind(this.element));
|
|
235
|
+
// You may want to add other special handling here
|
|
236
|
+
// Foundry comes with a large number of utility classes, e.g. SearchFilter
|
|
237
|
+
// That you may want to implement yourself.
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
// Drag and Drop
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Returns an array of DragDrop instances
|
|
245
|
+
* @type {DragDrop[]}
|
|
246
|
+
*/
|
|
247
|
+
get dragDrop() {
|
|
248
|
+
return this.#dragDrop;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Define whether a user is able to begin a dragstart workflow for a given drag selector
|
|
253
|
+
* @param {string} selector The candidate HTML selector for dragging
|
|
254
|
+
* @returns {boolean} Can the current user drag this selector?
|
|
255
|
+
* @protected
|
|
256
|
+
*/
|
|
257
|
+
_canDragStart(selector) {
|
|
258
|
+
return this.isEditable;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector
|
|
263
|
+
* @param {string} selector The candidate HTML selector for the drop target
|
|
264
|
+
* @returns {boolean} Can the current user drop on this selector?
|
|
265
|
+
* @protected
|
|
266
|
+
*/
|
|
267
|
+
_canDragDrop(selector) {
|
|
268
|
+
return this.isEditable;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Callback actions which occur at the beginning of a drag start workflow.
|
|
273
|
+
* @param {DragEvent} event The originating DragEvent
|
|
274
|
+
* @protected
|
|
275
|
+
*/
|
|
276
|
+
_onDragStart(event) {
|
|
277
|
+
console.log("Drag Start");
|
|
278
|
+
|
|
279
|
+
if (event.currentTarget.classList.contains("paper-doll-slot")) {
|
|
280
|
+
// Remove the item from the slot
|
|
281
|
+
const name = event.currentTarget.dataset.name;
|
|
282
|
+
const update = {};
|
|
283
|
+
update[name] = null;
|
|
284
|
+
this.document.update(update);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const tr = event.currentTarget.closest("tr");
|
|
288
|
+
const data = {
|
|
289
|
+
type: tr.dataset.type == "ActiveEffect" ? "ActiveEffect" : "Item",
|
|
290
|
+
uuid: tr.dataset.uuid
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
event.dataTransfer.setData("text/plain", JSON.stringify(data));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Callback actions which occur when a dragged element is over a drop target.
|
|
299
|
+
* @param {DragEvent} event The originating DragEvent
|
|
300
|
+
* @protected
|
|
301
|
+
*/
|
|
302
|
+
_onDragOver(event) {}
|
|
303
|
+
|
|
304
|
+
/* -------------------------------------------- */
|
|
305
|
+
|
|
306
|
+
async _onDrop(event) {
|
|
307
|
+
const data = JSON.parse(event.dataTransfer.getData("text/plain"));
|
|
308
|
+
|
|
309
|
+
// If the drop target is a single document, handle it differently
|
|
310
|
+
const linkedClasses = [ "single-document", "paper-doll-slot" ];
|
|
311
|
+
const eventClasses = Array.from(event.currentTarget.classList);
|
|
312
|
+
if (eventClasses.find(c => linkedClasses.includes(c))) {
|
|
313
|
+
const doc = await fromUuid(data.uuid);
|
|
314
|
+
if ( !doc ) return;
|
|
315
|
+
if ( doc.type !== event.currentTarget.dataset.type ) {
|
|
316
|
+
ui.notifications.error(\`Expected a \${event.currentTarget.dataset.type} type Document, but got a \${doc.type} type one instead. \`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const update = {};
|
|
321
|
+
update[event.currentTarget.dataset.name] = data.uuid;
|
|
322
|
+
await this.document.update(update);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const dropTypes = ["Item", "ActiveEffect"];
|
|
327
|
+
if ( !dropTypes.includes(data.type) ) return;
|
|
328
|
+
const item = await fromUuid(data.uuid);
|
|
329
|
+
if ( !item ) return;
|
|
330
|
+
|
|
331
|
+
// Prevent duplicates when dropping an item that's already owned by this document
|
|
332
|
+
if ( item.parent?.uuid === this.document.uuid ) return;
|
|
333
|
+
|
|
334
|
+
if ( data.type === "ActiveEffect" ) {
|
|
335
|
+
ActiveEffect.createDocuments([item], {parent: this.document})
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
Item.createDocuments([item], {parent: this.document})
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/* -------------------------------------------- */
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Returns an array of DragDrop instances
|
|
346
|
+
* @type {DragDrop[]}
|
|
347
|
+
*/
|
|
348
|
+
get dragDrop() {
|
|
349
|
+
return this.#dragDrop;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// This is marked as private because there's no real need
|
|
353
|
+
// for subclasses or external hooks to mess with it directly
|
|
354
|
+
#dragDrop;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Create drag-and-drop workflow handlers for this Application
|
|
358
|
+
* @returns {DragDrop[]} An array of DragDrop handlers
|
|
359
|
+
* @private
|
|
360
|
+
*/
|
|
361
|
+
#createDragDropHandlers() {
|
|
362
|
+
return this.options.dragDrop.map((d) => {
|
|
363
|
+
d.permissions = {
|
|
364
|
+
dragstart: this._canDragStart.bind(this),
|
|
365
|
+
drop: this._canDragDrop.bind(this)
|
|
366
|
+
};
|
|
367
|
+
d.callbacks = {
|
|
368
|
+
dragstart: this._onDragStart.bind(this),
|
|
369
|
+
dragover: this._onDragOver.bind(this),
|
|
370
|
+
drop: this._onDrop.bind(this)
|
|
371
|
+
};
|
|
372
|
+
return new DragDrop(d);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
376
|
`;
|
|
377
377
|
fs.writeFileSync(generatedFilePath, toString(fileNode));
|
|
378
378
|
}
|