@kitschpatrol/tweakpane-plugin-file-import 1.2.0-fork.1 → 1.2.0-fork.2

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,296 +1,396 @@
1
- import { ClassName, createPlugin, CompositeConstraint, parseRecord } from '@tweakpane/core';
2
-
3
- // Create a class name generator from the view name
4
- // ClassName('tmp') will generate a CSS class name like `tp-tmpv`
5
- const containerClassName = ClassName('ctn');
6
- const inputClassName = ClassName('input');
7
- const deleteButtonClassName = ClassName('btn');
8
- class FilePluginView {
9
- constructor(doc, config) {
10
- // Root
11
- this.element = doc.createElement('div');
12
- // Container
13
- this.container = doc.createElement('div');
14
- this.container.classList.add(containerClassName());
15
- config.viewProps.bindClassModifiers(this.container);
16
- // File input field
17
- this.input = doc.createElement('input');
18
- this.input.classList.add(inputClassName());
19
- this.input.setAttribute('type', 'file');
20
- this.input.setAttribute('accept', config.filetypes ? config.filetypes.join(',') : '*');
21
- this.input.style.height = `calc(20px * ${config.lineCount})`;
22
- // Icon
23
- this.fileIcon = doc.createElement('div');
24
- this.fileIcon.classList.add(containerClassName('icon'));
25
- // Text
26
- this.text = doc.createElement('span');
27
- this.text.classList.add(containerClassName('text'));
28
- // Warning text
29
- this.warning = doc.createElement('span');
30
- this.warning.classList.add(containerClassName('warning'));
31
- this.warning.innerHTML = config.invalidFiletypeMessage;
32
- this.warning.style.display = 'none';
33
- // Delete button
34
- this.deleteButton = doc.createElement('button');
35
- this.deleteButton.classList.add(deleteButtonClassName('b'));
36
- this.deleteButton.innerHTML = 'Delete';
37
- this.deleteButton.style.display = 'none';
38
- this.container.appendChild(this.input);
39
- this.container.appendChild(this.fileIcon);
40
- this.element.appendChild(this.container);
41
- this.element.appendChild(this.warning);
42
- this.element.appendChild(this.deleteButton);
43
- }
44
- /**
45
- * Changes the style of the container based on whether the user is dragging or not.
46
- * @param state if the user is dragging or not.
47
- */
48
- changeDraggingState(state) {
49
- var _a, _b;
50
- if (state) {
51
- (_a = this.container) === null || _a === void 0 ? void 0 : _a.classList.add(containerClassName('input_area_dragging'));
52
- }
53
- else {
54
- (_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove(containerClassName('input_area_dragging'));
55
- }
56
- }
1
+ // node_modules/.pnpm/@tweakpane+core@2.0.5/node_modules/@tweakpane/core/dist/misc/type-util.js
2
+ function forceCast(v) {
3
+ return v;
57
4
  }
58
-
59
- class FilePluginController {
60
- constructor(doc, config) {
61
- this.value = config.value;
62
- this.viewProps = config.viewProps;
63
- this.view = new FilePluginView(doc, {
64
- viewProps: this.viewProps,
65
- value: config.value,
66
- invalidFiletypeMessage: config.invalidFiletypeMessage,
67
- lineCount: config.lineCount,
68
- filetypes: config.filetypes,
69
- });
70
- this.config = config;
71
- // Bind event handlers
72
- this.onFile = this.onFile.bind(this);
73
- this.onDrop = this.onDrop.bind(this);
74
- this.onDragOver = this.onDragOver.bind(this);
75
- this.onDragLeave = this.onDragLeave.bind(this);
76
- this.onDeleteClick = this.onDeleteClick.bind(this);
77
- this.view.input.addEventListener('change', this.onFile);
78
- this.view.element.addEventListener('drop', this.onDrop);
79
- this.view.element.addEventListener('dragover', this.onDragOver);
80
- this.view.element.addEventListener('dragleave', this.onDragLeave);
81
- this.view.deleteButton.addEventListener('click', this.onDeleteClick);
82
- this.value.emitter.on('change', () => this.handleValueChange());
83
- // Dispose event handlers
84
- this.viewProps.handleDispose(() => {
85
- this.view.input.removeEventListener('change', this.onFile);
86
- this.view.element.removeEventListener('drop', this.onDrop);
87
- this.view.element.removeEventListener('dragover', this.onDragOver);
88
- this.view.element.removeEventListener('dragleave', this.onDragLeave);
89
- this.view.deleteButton.removeEventListener('click', this.onDeleteClick);
90
- });
91
- }
92
- /**
93
- * Called when the value of the input changes.
94
- * @param event change event.
95
- */
96
- onFile(_event) {
97
- const input = this.view.input;
98
- // Check if user has chosen a file.
99
- // If it's valid, we update the value. Otherwise, show warning.
100
- if (input.files && input.files.length > 0) {
101
- const file = input.files[0];
102
- if (!this.isFileValid(file)) {
103
- this.showWarning();
104
- }
105
- else {
106
- this.value.setRawValue(file);
107
- }
108
- }
109
- }
110
- /**
111
- * Shows warning text for 5 seconds.
112
- */
113
- showWarning() {
114
- this.view.warning.style.display = 'block';
115
- setTimeout(() => {
116
- // Resetting warning text
117
- this.view.warning.style.display = 'none';
118
- }, 5000);
119
- }
120
- /**
121
- * Checks if the file is valid with the given filetypes.
122
- * @param file File object
123
- * @returns true if the file is valid.
124
- */
125
- isFileValid(file) {
126
- var _a;
127
- const filetypes = this.config.filetypes;
128
- const fileExtension = '.' + ((_a = file.name.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
129
- return !(filetypes &&
130
- filetypes.length > 0 &&
131
- !filetypes.includes(fileExtension) &&
132
- fileExtension);
133
- }
134
- /**
135
- * Event handler when the delete HTML button is clicked.
136
- * It resets the `rawValue` of the controller.
137
- */
138
- onDeleteClick() {
139
- const file = this.value.rawValue;
140
- if (file) {
141
- // Resetting the value
142
- this.value.setRawValue(null);
143
- // Resetting the input
144
- this.view.input.value = '';
145
- // Resetting the warning text
146
- this.view.warning.style.display = 'none';
147
- }
148
- }
149
- /**
150
- * Called when the user drags over a file.
151
- * Updates the style of the container.
152
- * @param event drag event.
153
- */
154
- onDragOver(event) {
155
- event.preventDefault();
156
- this.view.changeDraggingState(true);
157
- }
158
- /**
159
- * Called when the user leaves the container while dragging.
160
- * Updates the style of the container.
161
- */
162
- onDragLeave() {
163
- this.view.changeDraggingState(false);
164
- }
165
- /**
166
- * Called when the user drops a file in the container.
167
- * Either shows a warning if it's invalid or updates the value if it's valid.
168
- * @param ev drag event.
169
- */
170
- onDrop(ev) {
171
- if (ev instanceof DragEvent) {
172
- // Prevent default behavior (Prevent file from being opened)
173
- ev.preventDefault();
174
- if (ev.dataTransfer) {
175
- if (ev.dataTransfer.files) {
176
- // We only change the value if the user has dropped a single file
177
- const filesArray = [ev.dataTransfer.files][0];
178
- if (filesArray.length == 1) {
179
- const file = filesArray.item(0);
180
- if (file) {
181
- if (!this.isFileValid(file)) {
182
- this.showWarning();
183
- }
184
- else {
185
- this.value.setRawValue(file);
186
- }
187
- }
188
- }
189
- }
190
- }
191
- }
192
- this.view.changeDraggingState(false);
193
- }
194
- /**
195
- * Called when the value (bound to the controller) changes (e.g. when the file is selected).
196
- */
197
- handleValueChange() {
198
- const fileObj = this.value.rawValue;
199
- const containerEl = this.view.container;
200
- const textEl = this.view.text;
201
- const fileIconEl = this.view.fileIcon;
202
- const deleteButton = this.view.deleteButton;
203
- if (fileObj) {
204
- // Setting the text of the file to the element
205
- textEl.textContent = fileObj.name;
206
- // Removing icon and adding text
207
- containerEl.appendChild(textEl);
208
- if (containerEl.contains(fileIconEl)) {
209
- containerEl.removeChild(fileIconEl);
210
- }
211
- // Resetting warning text
212
- this.view.warning.style.display = 'none';
213
- // Adding button to delete
214
- deleteButton.style.display = 'block';
215
- containerEl.style.border = 'unset';
216
- }
217
- else {
218
- // Setting the text of the file to the element
219
- textEl.textContent = '';
220
- // Removing text and adding icon
221
- containerEl.appendChild(fileIconEl);
222
- containerEl.removeChild(textEl);
223
- // Resetting warning text
224
- this.view.warning.style.display = 'none';
225
- // Hiding button and resetting border
226
- deleteButton.style.display = 'none';
227
- containerEl.style.border = '1px dashed #717070';
228
- }
229
- }
5
+ // node_modules/.pnpm/@tweakpane+core@2.0.5/node_modules/@tweakpane/core/dist/common/micro-parsers.js
6
+ function parseObject(value, keyToParserMap) {
7
+ return forceCast(Object.keys(keyToParserMap).reduce((tmp, key) => {
8
+ if (tmp === void 0) return;
9
+ const parser = keyToParserMap[key];
10
+ const result = parser(value[key]);
11
+ return result.succeeded ? Object.assign(Object.assign({}, tmp), { [key]: result.value }) : void 0;
12
+ }, {}));
13
+ }
14
+ function parseArray(value, parseItem) {
15
+ return value.reduce((tmp, item) => {
16
+ if (tmp === void 0) return;
17
+ const result = parseItem(item);
18
+ if (!result.succeeded || result.value === void 0) return;
19
+ return [...tmp, result.value];
20
+ }, []);
21
+ }
22
+ function isObject(value) {
23
+ if (value === null) return false;
24
+ return typeof value === "object";
25
+ }
26
+ function createMicroParserBuilder(parse) {
27
+ return (optional) => (v) => {
28
+ if (!optional && v === void 0) return {
29
+ succeeded: false,
30
+ value: void 0
31
+ };
32
+ if (optional && v === void 0) return {
33
+ succeeded: true,
34
+ value: void 0
35
+ };
36
+ const result = parse(v);
37
+ return result !== void 0 ? {
38
+ succeeded: true,
39
+ value: result
40
+ } : {
41
+ succeeded: false,
42
+ value: void 0
43
+ };
44
+ };
45
+ }
46
+ function createMicroParserBuilders(optional) {
47
+ return {
48
+ custom: (parse) => createMicroParserBuilder(parse)(optional),
49
+ boolean: createMicroParserBuilder((v) => typeof v === "boolean" ? v : void 0)(optional),
50
+ number: createMicroParserBuilder((v) => typeof v === "number" ? v : void 0)(optional),
51
+ string: createMicroParserBuilder((v) => typeof v === "string" ? v : void 0)(optional),
52
+ function: createMicroParserBuilder((v) => typeof v === "function" ? v : void 0)(optional),
53
+ constant: (value) => createMicroParserBuilder((v) => v === value ? value : void 0)(optional),
54
+ raw: createMicroParserBuilder((v) => v)(optional),
55
+ object: (keyToParserMap) => createMicroParserBuilder((v) => {
56
+ if (!isObject(v)) return;
57
+ return parseObject(v, keyToParserMap);
58
+ })(optional),
59
+ array: (itemParser) => createMicroParserBuilder((v) => {
60
+ if (!Array.isArray(v)) return;
61
+ return parseArray(v, itemParser);
62
+ })(optional)
63
+ };
64
+ }
65
+ const MicroParsers = {
66
+ optional: createMicroParserBuilders(true),
67
+ required: createMicroParserBuilders(false)
68
+ };
69
+ function parseRecord(value, keyToParserMap) {
70
+ const map = keyToParserMap(MicroParsers);
71
+ const result = MicroParsers.required.object(map)(value);
72
+ return result.succeeded ? result.value : void 0;
73
+ }
74
+ // node_modules/.pnpm/@tweakpane+core@2.0.5/node_modules/@tweakpane/core/dist/common/view/class-name.js
75
+ const PREFIX = "tp";
76
+ /**
77
+ * A utility function for generating BEM-like class name.
78
+ * @param viewName The name of the view. Used as part of the block name.
79
+ * @return A class name generator function.
80
+ */
81
+ function ClassName(viewName) {
82
+ /**
83
+ * Generates a class name.
84
+ * @param [opt_elementName] The name of the element.
85
+ * @param [opt_modifier] The name of the modifier.
86
+ * @return A class name.
87
+ */
88
+ const fn = (opt_elementName, opt_modifier) => {
89
+ return [
90
+ PREFIX,
91
+ "-",
92
+ viewName,
93
+ "v",
94
+ opt_elementName ? `_${opt_elementName}` : "",
95
+ opt_modifier ? `-${opt_modifier}` : ""
96
+ ].join("");
97
+ };
98
+ return fn;
99
+ }
100
+ // node_modules/.pnpm/@tweakpane+core@2.0.5/node_modules/@tweakpane/core/dist/misc/semver.js
101
+ /***
102
+ * A simple semantic versioning perser.
103
+ */
104
+ var Semver = class {
105
+ /**
106
+ * @hidden
107
+ */
108
+ constructor(text) {
109
+ const [core, prerelease] = text.split("-");
110
+ const coreComps = core.split(".");
111
+ this.major = parseInt(coreComps[0], 10);
112
+ this.minor = parseInt(coreComps[1], 10);
113
+ this.patch = parseInt(coreComps[2], 10);
114
+ this.prerelease = prerelease !== null && prerelease !== void 0 ? prerelease : null;
115
+ }
116
+ toString() {
117
+ const core = [
118
+ this.major,
119
+ this.minor,
120
+ this.patch
121
+ ].join(".");
122
+ return this.prerelease !== null ? [core, this.prerelease].join("-") : core;
123
+ }
124
+ };
125
+ // node_modules/.pnpm/@tweakpane+core@2.0.5/node_modules/@tweakpane/core/dist/version.js
126
+ const VERSION = new Semver("2.0.5");
127
+ // node_modules/.pnpm/@tweakpane+core@2.0.5/node_modules/@tweakpane/core/dist/plugin/plugin.js
128
+ /**
129
+ * Creates a plugin with the current core.
130
+ * @param plugin The plugin without the core version.
131
+ * @return A plugin with the core version.
132
+ */
133
+ function createPlugin(plugin) {
134
+ return Object.assign({ core: VERSION }, plugin);
135
+ }
136
+ // node_modules/.pnpm/@tweakpane+core@2.0.5/node_modules/@tweakpane/core/dist/common/constraint/composite.js
137
+ /**
138
+ * A constraint to combine multiple constraints.
139
+ * @template T The type of the value.
140
+ */
141
+ var CompositeConstraint = class {
142
+ constructor(constraints) {
143
+ this.constraints = constraints;
144
+ }
145
+ constrain(value) {
146
+ return this.constraints.reduce((result, c) => {
147
+ return c.constrain(result);
148
+ }, value);
149
+ }
150
+ };
151
+ // src/view/view.ts
152
+ const containerClassName = ClassName("ctn");
153
+ const inputClassName = ClassName("input");
154
+ const buttonClassName = ClassName("btn");
155
+ var FilePluginView = class {
156
+ clearButton;
157
+ container;
158
+ element;
159
+ fileIcon;
160
+ input;
161
+ text;
162
+ warning;
163
+ constructor(doc, config) {
164
+ this.element = doc.createElement("div");
165
+ this.container = doc.createElement("div");
166
+ this.container.classList.add(containerClassName());
167
+ config.viewProps.bindClassModifiers(this.container);
168
+ this.input = doc.createElement("input");
169
+ this.input.classList.add(inputClassName());
170
+ this.input.setAttribute("type", "file");
171
+ this.input.setAttribute("accept", config.filetypes ? config.filetypes.join(",") : "*");
172
+ this.input.style.height = `calc(20px * ${config.lineCount})`;
173
+ this.fileIcon = doc.createElement("div");
174
+ this.fileIcon.classList.add(containerClassName("icon"));
175
+ this.text = doc.createElement("span");
176
+ this.text.classList.add(containerClassName("text"));
177
+ this.warning = doc.createElement("span");
178
+ this.warning.classList.add(containerClassName("warning"));
179
+ this.warning.textContent = config.invalidFiletypeMessage;
180
+ this.warning.style.display = "none";
181
+ this.clearButton = doc.createElement("button");
182
+ this.clearButton.classList.add(buttonClassName("b"));
183
+ this.clearButton.textContent = "Delete";
184
+ this.clearButton.style.display = "none";
185
+ this.container.append(this.input);
186
+ this.container.append(this.fileIcon);
187
+ this.element.append(this.container);
188
+ this.element.append(this.warning);
189
+ this.element.append(this.clearButton);
190
+ }
191
+ /**
192
+ * Changes the style of the container based on whether the user is dragging or
193
+ * not.
194
+ *
195
+ * @param state If the user is dragging or not.
196
+ */
197
+ changeDraggingState(state) {
198
+ if (state) this.container.classList.add(containerClassName("input_area_dragging"));
199
+ else this.container.classList.remove(containerClassName("input_area_dragging"));
200
+ }
201
+ };
202
+ // src/controller/controller.ts
203
+ var FilePluginController = class {
204
+ value;
205
+ view;
206
+ viewProps;
207
+ config;
208
+ constructor(doc, config) {
209
+ this.value = config.value;
210
+ this.viewProps = config.viewProps;
211
+ this.view = new FilePluginView(doc, {
212
+ filetypes: config.filetypes,
213
+ invalidFiletypeMessage: config.invalidFiletypeMessage,
214
+ lineCount: config.lineCount,
215
+ value: config.value,
216
+ viewProps: this.viewProps
217
+ });
218
+ this.config = config;
219
+ this.onFile = this.onFile.bind(this);
220
+ this.onDrop = this.onDrop.bind(this);
221
+ this.onDragOver = this.onDragOver.bind(this);
222
+ this.onDragLeave = this.onDragLeave.bind(this);
223
+ this.onDeleteClick = this.onDeleteClick.bind(this);
224
+ this.view.input.addEventListener("change", this.onFile);
225
+ this.view.element.addEventListener("drop", this.onDrop);
226
+ this.view.element.addEventListener("dragover", this.onDragOver);
227
+ this.view.element.addEventListener("dragleave", this.onDragLeave);
228
+ this.view.clearButton.addEventListener("click", this.onDeleteClick);
229
+ this.value.emitter.on("change", () => {
230
+ this.handleValueChange();
231
+ });
232
+ this.viewProps.handleDispose(() => {
233
+ this.view.input.removeEventListener("change", this.onFile);
234
+ this.view.element.removeEventListener("drop", this.onDrop);
235
+ this.view.element.removeEventListener("dragover", this.onDragOver);
236
+ this.view.element.removeEventListener("dragleave", this.onDragLeave);
237
+ this.view.clearButton.removeEventListener("click", this.onDeleteClick);
238
+ });
239
+ }
240
+ /**
241
+ * Called when the value (bound to the controller) changes (e.g. when the file
242
+ * is selected).
243
+ */
244
+ handleValueChange() {
245
+ const fileObject = this.value.rawValue;
246
+ const containerElement = this.view.container;
247
+ const textElement = this.view.text;
248
+ const fileIconElement = this.view.fileIcon;
249
+ const { clearButton } = this.view;
250
+ if (fileObject) {
251
+ textElement.textContent = fileObject.name;
252
+ containerElement.append(textElement);
253
+ if (containerElement.contains(fileIconElement)) fileIconElement.remove();
254
+ this.view.warning.style.display = "none";
255
+ clearButton.style.display = "block";
256
+ containerElement.style.border = "unset";
257
+ } else {
258
+ textElement.textContent = "";
259
+ containerElement.append(fileIconElement);
260
+ textElement.remove();
261
+ this.view.warning.style.display = "none";
262
+ clearButton.style.display = "none";
263
+ containerElement.style.border = "1px dashed #717070";
264
+ }
265
+ }
266
+ /**
267
+ * Checks if the file is valid with the given filetypes.
268
+ *
269
+ * @param file File object
270
+ *
271
+ * @returns True if the file is valid.
272
+ */
273
+ isFileValid(file) {
274
+ const { filetypes } = this.config;
275
+ const fileExtension = "." + (file.name.split(".").pop()?.toLowerCase() ?? "");
276
+ return !filetypes || filetypes.length === 0 || filetypes.includes(fileExtension);
277
+ }
278
+ /**
279
+ * Event handler when the delete HTML button is clicked. It resets the
280
+ * `rawValue` of the controller.
281
+ */
282
+ onDeleteClick() {
283
+ if (!this.value.rawValue) return;
284
+ this.value.setRawValue(null);
285
+ this.view.input.value = "";
286
+ this.view.warning.style.display = "none";
287
+ }
288
+ /**
289
+ * Called when the user leaves the container while dragging. Updates the style
290
+ * of the container.
291
+ */
292
+ onDragLeave() {
293
+ this.view.changeDraggingState(false);
294
+ }
295
+ /**
296
+ * Called when the user drags over a file. Updates the style of the container.
297
+ *
298
+ * @param event Drag event.
299
+ */
300
+ onDragOver(event) {
301
+ event.preventDefault();
302
+ this.view.changeDraggingState(true);
303
+ }
304
+ /**
305
+ * Called when the user drops a file in the container. Either shows a warning
306
+ * if it's invalid or updates the value if it's valid.
307
+ *
308
+ * @param event Drag event.
309
+ */
310
+ onDrop(event) {
311
+ try {
312
+ if (!(event instanceof DragEvent)) return;
313
+ event.preventDefault();
314
+ const files = event.dataTransfer?.files;
315
+ if (files?.length !== 1) return;
316
+ const file = files.item(0);
317
+ if (!file) return;
318
+ if (this.isFileValid(file)) this.value.setRawValue(file);
319
+ else this.showWarning();
320
+ } finally {
321
+ this.view.changeDraggingState(false);
322
+ }
323
+ }
324
+ /**
325
+ * Called when the value of the input changes.
326
+ *
327
+ * @param _event Change event.
328
+ */
329
+ onFile(_event) {
330
+ const file = this.view.input.files?.item(0);
331
+ if (!file) return;
332
+ if (this.isFileValid(file)) this.value.setRawValue(file);
333
+ else this.showWarning();
334
+ }
335
+ /**
336
+ * Shows warning text for 5 seconds.
337
+ */
338
+ showWarning() {
339
+ this.view.warning.style.display = "block";
340
+ setTimeout(() => {
341
+ this.view.warning.style.display = "none";
342
+ }, 5e3);
343
+ }
344
+ };
345
+ // src/plugin.ts
346
+ function readFile(exValue) {
347
+ return exValue instanceof File ? exValue : null;
348
+ }
349
+ function writeFile(target, inValue) {
350
+ target.write(inValue);
230
351
  }
231
-
232
352
  const TweakpaneFileInputPlugin = createPlugin({
233
- id: 'file-input',
234
- // type: The plugin type.
235
- type: 'input',
236
- accept(exValue, params) {
237
- if (typeof exValue !== 'string') {
238
- // Return null to deny the user input
239
- return null;
240
- }
241
- // Parse parameters object
242
- const result = parseRecord(params, (p) => ({
243
- // `view` option may be useful to provide a custom control for primitive values
244
- view: p.required.constant('file-input'),
245
- invalidFiletypeMessage: p.optional.string,
246
- lineCount: p.optional.number,
247
- filetypes: p.optional.array(p.required.string),
248
- }));
249
- if (!result) {
250
- return null;
251
- }
252
- // Return a typed value and params to accept the user input
253
- return {
254
- initialValue: exValue,
255
- params: result,
256
- };
257
- },
258
- binding: {
259
- reader(_args) {
260
- return (exValue) => {
261
- // Convert an external unknown value into the internal value
262
- return exValue instanceof File ? exValue : null;
263
- };
264
- },
265
- constraint(_args) {
266
- return new CompositeConstraint([]);
267
- },
268
- writer(_args) {
269
- return (target, inValue) => {
270
- // Use `target.write()` to write the primitive value to the target,
271
- // or `target.writeProperty()` to write a property of the target
272
- target.write(inValue);
273
- };
274
- },
275
- },
276
- controller(args) {
277
- var _a, _b;
278
- const defaultNumberOfLines = 3;
279
- const defaultFiletypeWarningText = 'Unaccepted file type.';
280
- // Create a controller for the plugin
281
- return new FilePluginController(args.document, {
282
- value: args.value,
283
- viewProps: args.viewProps,
284
- invalidFiletypeMessage: (_a = args.params.invalidFiletypeMessage) !== null && _a !== void 0 ? _a : defaultFiletypeWarningText,
285
- lineCount: (_b = args.params.lineCount) !== null && _b !== void 0 ? _b : defaultNumberOfLines,
286
- filetypes: args.params.filetypes,
287
- });
288
- },
353
+ accept(exValue, params) {
354
+ if (typeof exValue !== "string") return null;
355
+ const result = parseRecord(params, (p) => ({
356
+ filetypes: p.optional.array(p.required.string),
357
+ invalidFiletypeMessage: p.optional.string,
358
+ lineCount: p.optional.number,
359
+ view: p.required.constant("file-input")
360
+ }));
361
+ if (!result) return null;
362
+ return {
363
+ initialValue: exValue,
364
+ params: result
365
+ };
366
+ },
367
+ binding: {
368
+ constraint(_args) {
369
+ return new CompositeConstraint([]);
370
+ },
371
+ reader(_args) {
372
+ return readFile;
373
+ },
374
+ writer(_args) {
375
+ return writeFile;
376
+ }
377
+ },
378
+ controller(args) {
379
+ return new FilePluginController(args.document, {
380
+ filetypes: args.params.filetypes,
381
+ invalidFiletypeMessage: args.params.invalidFiletypeMessage ?? "Unaccepted file type.",
382
+ lineCount: args.params.lineCount ?? 3,
383
+ value: args.value,
384
+ viewProps: args.viewProps
385
+ });
386
+ },
387
+ id: "file-input",
388
+ type: "input"
289
389
  });
290
-
291
- // Export your plugin(s) as constant `plugins`
292
- const id = 'file-input';
293
- const css = '.tp-ctnv{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:rgba(0,0,0,0);border-width:0;font-family:inherit;font-size:inherit;font-weight:inherit;margin:0;outline:none;padding:0}.tp-ctnv{background-color:var(--in-bg);border-radius:var(--bld-br);box-sizing:border-box;color:var(--in-fg);font-family:inherit;height:var(--cnt-usz);line-height:var(--cnt-usz);min-width:0;width:100%}.tp-ctnv:hover{background-color:var(--in-bg-h)}.tp-ctnv:focus{background-color:var(--in-bg-f)}.tp-ctnv:active{background-color:var(--in-bg-a)}.tp-ctnv:disabled{opacity:.5}.tp-ctnv{cursor:pointer;display:flex;justify-content:center;align-items:center;overflow:hidden;position:relative;height:100%;width:100%;border:1px dashed #717070;border-radius:5px}.tp-ctnv.tp-v-disabled{opacity:.5}.tp-ctnv_input_area_dragging{border:1px dashed #6774ff;background-color:rgba(88,88,185,.231372549)}.tp-ctnv_warning{color:var(--in-fg);bottom:2px;display:inline-block;font-size:.9em;height:-moz-max-content;height:max-content;line-height:1.5;opacity:.5;white-space:normal;width:-moz-max-content;width:max-content;word-wrap:break-word;text-align:right;width:100%;margin-top:var(--cnt-vp)}.tp-ctnv_text{color:var(--in-fg);bottom:2px;display:inline-block;font-size:.9em;height:-moz-max-content;height:max-content;line-height:.9;margin:.2rem;max-height:100%;max-width:100%;opacity:.5;position:absolute;right:2px;text-align:right;white-space:normal;width:-moz-max-content;width:max-content;word-wrap:break-word}.tp-ctnv_frac{background-color:var(--in-fg);border-radius:1px;height:2px;left:50%;margin-top:-1px;position:absolute;top:50%}.tp-ctnv_icon{box-sizing:border-box;position:absolute;display:block;transform:scale(var(--ggs, 1));width:16px;height:6px;border:2px solid;border-top:0;border-bottom-left-radius:2px;border-bottom-right-radius:2px;margin-top:8px;opacity:.5}.tp-ctnv_icon::after{content:"";display:block;box-sizing:border-box;position:absolute;width:8px;height:8px;border-left:2px solid;border-top:2px solid;transform:rotate(45deg);left:2px;bottom:4px}.tp-ctnv_icon::before{content:"";display:block;box-sizing:border-box;position:absolute;border-radius:3px;width:2px;height:10px;background:currentColor;left:5px;bottom:3px}.tp-btnv_b{margin-top:10px}.tp-inputv{opacity:0}';
390
+ // src/styles/plugin.scss?inline
391
+ var plugin_default = ".tp-ctnv{appearance:none;font-family:inherit;font-size:inherit;font-weight:inherit;background-color:#0000;background-color:var(--in-bg);border-radius:var(--bld-br);box-sizing:border-box;color:var(--in-fg);height:var(--cnt-usz);font-family:inherit;line-height:var(--cnt-usz);border-width:0;outline:none;width:100%;min-width:0;margin:0;padding:0}.tp-ctnv:hover{background-color:var(--in-bg-h)}.tp-ctnv:focus{background-color:var(--in-bg-f)}.tp-ctnv:active{background-color:var(--in-bg-a)}.tp-ctnv:disabled{opacity:.5}.tp-ctnv{cursor:pointer;border:1px dashed #717070;border-radius:5px;flex-wrap:nowrap;justify-content:center;align-items:center;width:100%;height:100%;display:flex;position:relative;overflow:hidden}.tp-ctnv.tp-v-disabled{opacity:.5}.tp-ctnv_input_area_dragging{background-color:#5858b93b;border:1px dashed #6774ff}.tp-ctnv_warning{width:100%;height:max-content;margin-top:var(--cnt-vp);color:var(--in-fg);text-align:right;overflow-wrap:break-word;white-space:normal;opacity:.5;font-size:.9em;line-height:1.5;display:inline-block;bottom:2px}.tp-ctnv_text{width:max-content;max-width:100%;height:max-content;max-height:100%;color:var(--in-fg);text-align:right;overflow-wrap:break-word;white-space:normal;opacity:.5;margin:.2rem;font-size:.9em;line-height:.9;display:inline-block;position:absolute;bottom:2px;right:2px}.tp-ctnv_frac{background-color:var(--in-fg);border-radius:1px;height:2px;margin-top:-1px;position:absolute;top:50%;left:50%}.tp-ctnv_icon{transform:scale(var(--ggs,1));box-sizing:border-box;opacity:.5;border:2px solid;border-top:0;border-bottom-right-radius:2px;border-bottom-left-radius:2px;width:16px;height:6px;margin-top:8px;display:block;position:absolute}.tp-ctnv_icon:after{content:\"\";box-sizing:border-box;border-top:2px solid;border-left:2px solid;width:8px;height:8px;display:block;position:absolute;bottom:4px;left:2px;transform:rotate(45deg)}.tp-ctnv_icon:before{content:\"\";box-sizing:border-box;background:currentColor;border-radius:3px;width:2px;height:10px;display:block;position:absolute;bottom:3px;left:5px}.tp-btnv_b{margin-top:10px}.tp-inputv{opacity:0}\n";
392
+ // src/index.ts
393
+ const id = "file-input";
394
+ const css = plugin_default;
294
395
  const plugins = [TweakpaneFileInputPlugin];
295
-
296
396
  export { css, id, plugins };