@kitschpatrol/tweakpane-plugin-file-import 1.1.2-beta.1

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/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2021 cocopon <cocopon@me.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @kitschpatrol/tweakpane-plugin-file-import
2
+
3
+ [![NPM Package @kitschpatrol/tweakpane-plugin-file-import](https://img.shields.io/npm/v/@kitschpatrol/tweakpane-plugin-file-import.svg)](https://npmjs.com/package/@kitschpatrol/tweakpane-plugin-file-import)
4
+
5
+ ## Overview
6
+
7
+ **This is a fork of [LuchoTurtle](https://github.com/LuchoTurtle)'s [tweakpane-plugin-file-import](https://github.com/LuchoTurtle/tweakpane-plugin-file-import) with externalized dependencies.**
8
+
9
+ This allows for smaller bundled file sizes in projects using multiple Tweakpane plugins.
10
+
11
+ It is published to NPM primarily for the [_Svelte Tweakpane UI_](https://kitschpatrol.com/svelte-tweakpane-ui) project, and will be kept in sync with the upstream version of the plugin, with minimal changes other than dependency externalization.
12
+
13
+ For most use cases, you probably don't want this fork!
14
+
15
+ ## Background
16
+
17
+ The [Rollup](https://rollupjs.org) configuration provided in the [Tweakpane plugin template](https://github.com/tweakpane/plugin-template) does not externalize [`@tweakpane/core`](https://github.com/cocopon/tweakpane/tree/main/packages/core) as a production dependency.
18
+
19
+ Instead, it gets built into the single-file plugin artifact, which is what's published to NPM and imported by plugin consumers. This makes it easy to import as an ES module from a URL, but means that larger projects importing multiple Tweakpane plugins end up with duplicate copies of the `@tweakpane/core` code, adding about ~100 Kb to the final minified build for each plugin after the first.
20
+
21
+ Externalizing this dependency allows build tools like [vite](https://vitejs.dev) to share a single instance of the `@tweakpane/core` code across multiple plugins.
22
+
23
+ If you're not using a bundler, direct ESM imports from URLs can still work if needed by defining the `@tweakpane/core` dependency in an [importmap](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap).
24
+
25
+ ## Implementation notes
26
+
27
+ PNPM is used as the package manager.
28
+
29
+ ## Versioning
30
+
31
+ In addition to the dependency externalization change, this fork also includes assorted dependency updates. In an effort to stay in sync with future upstream versions, intra-minor-version releases of the fork are tagged as "betas" of what would / will be the next patch release upstream.
@@ -0,0 +1,296 @@
1
+ import { ClassName, createPlugin, parseRecord, CompositeConstraint } 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
+ }
57
+ }
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
+ }
230
+ }
231
+
232
+ 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
+ },
289
+ });
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}';
294
+ const plugins = [TweakpaneFileInputPlugin];
295
+
296
+ export { css, id, plugins };
@@ -0,0 +1 @@
1
+ import{ClassName as e,createPlugin as t,parseRecord as i,CompositeConstraint as n}from"@tweakpane/core";const a=e("ctn"),o=e("input"),s=e("btn");class r{constructor(e,t){this.element=e.createElement("div"),this.container=e.createElement("div"),this.container.classList.add(a()),t.viewProps.bindClassModifiers(this.container),this.input=e.createElement("input"),this.input.classList.add(o()),this.input.setAttribute("type","file"),this.input.setAttribute("accept",t.filetypes?t.filetypes.join(","):"*"),this.input.style.height=`calc(20px * ${t.lineCount})`,this.fileIcon=e.createElement("div"),this.fileIcon.classList.add(a("icon")),this.text=e.createElement("span"),this.text.classList.add(a("text")),this.warning=e.createElement("span"),this.warning.classList.add(a("warning")),this.warning.innerHTML=t.invalidFiletypeMessage,this.warning.style.display="none",this.deleteButton=e.createElement("button"),this.deleteButton.classList.add(s("b")),this.deleteButton.innerHTML="Delete",this.deleteButton.style.display="none",this.container.appendChild(this.input),this.container.appendChild(this.fileIcon),this.element.appendChild(this.container),this.element.appendChild(this.warning),this.element.appendChild(this.deleteButton)}changeDraggingState(e){var t,i;e?null===(t=this.container)||void 0===t||t.classList.add(a("input_area_dragging")):null===(i=this.container)||void 0===i||i.classList.remove(a("input_area_dragging"))}}class l{constructor(e,t){this.value=t.value,this.viewProps=t.viewProps,this.view=new r(e,{viewProps:this.viewProps,value:t.value,invalidFiletypeMessage:t.invalidFiletypeMessage,lineCount:t.lineCount,filetypes:t.filetypes}),this.config=t,this.onFile=this.onFile.bind(this),this.onDrop=this.onDrop.bind(this),this.onDragOver=this.onDragOver.bind(this),this.onDragLeave=this.onDragLeave.bind(this),this.onDeleteClick=this.onDeleteClick.bind(this),this.view.input.addEventListener("change",this.onFile),this.view.element.addEventListener("drop",this.onDrop),this.view.element.addEventListener("dragover",this.onDragOver),this.view.element.addEventListener("dragleave",this.onDragLeave),this.view.deleteButton.addEventListener("click",this.onDeleteClick),this.value.emitter.on("change",(()=>this.handleValueChange())),this.viewProps.handleDispose((()=>{this.view.input.removeEventListener("change",this.onFile),this.view.element.removeEventListener("drop",this.onDrop),this.view.element.removeEventListener("dragover",this.onDragOver),this.view.element.removeEventListener("dragleave",this.onDragLeave),this.view.deleteButton.removeEventListener("click",this.onDeleteClick)}))}onFile(e){const t=this.view.input;if(t.files&&t.files.length>0){const e=t.files[0];this.isFileValid(e)?this.value.setRawValue(e):this.showWarning()}}showWarning(){this.view.warning.style.display="block",setTimeout((()=>{this.view.warning.style.display="none"}),5e3)}isFileValid(e){var t;const i=this.config.filetypes,n="."+(null===(t=e.name.split(".").pop())||void 0===t?void 0:t.toLowerCase());return!(i&&i.length>0&&!i.includes(n)&&n)}onDeleteClick(){this.value.rawValue&&(this.value.setRawValue(null),this.view.input.value="",this.view.warning.style.display="none")}onDragOver(e){e.preventDefault(),this.view.changeDraggingState(!0)}onDragLeave(){this.view.changeDraggingState(!1)}onDrop(e){if(e instanceof DragEvent&&(e.preventDefault(),e.dataTransfer&&e.dataTransfer.files)){const t=e.dataTransfer.files;if(1==t.length){const e=t.item(0);e&&(this.isFileValid(e)?this.value.setRawValue(e):this.showWarning())}}this.view.changeDraggingState(!1)}handleValueChange(){const e=this.value.rawValue,t=this.view.container,i=this.view.text,n=this.view.fileIcon,a=this.view.deleteButton;e?(i.textContent=e.name,t.appendChild(i),t.contains(n)&&t.removeChild(n),this.view.warning.style.display="none",a.style.display="block",t.style.border="unset"):(i.textContent="",t.appendChild(n),t.removeChild(i),this.view.warning.style.display="none",a.style.display="none",t.style.border="1px dashed #717070")}}const h="file-input",p='.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}',d=[t({id:"file-input",type:"input",accept(e,t){if("string"!=typeof e)return null;const n=i(t,(e=>({view:e.required.constant("file-input"),invalidFiletypeMessage:e.optional.string,lineCount:e.optional.number,filetypes:e.optional.array(e.required.string)})));return n?{initialValue:e,params:n}:null},binding:{reader:e=>e=>e instanceof File?e:null,constraint:e=>new n([]),writer:e=>(e,t)=>{e.write(t)}},controller(e){var t,i;return new l(e.document,{value:e.value,viewProps:e.viewProps,invalidFiletypeMessage:null!==(t=e.params.invalidFiletypeMessage)&&void 0!==t?t:"Unaccepted file type.",lineCount:null!==(i=e.params.lineCount)&&void 0!==i?i:3,filetypes:e.params.filetypes})}})];export{p as css,h as id,d as plugins};
@@ -0,0 +1,58 @@
1
+ import { Controller, Value, ViewProps } from '@tweakpane/core';
2
+ import { FilePluginView } from '../view/view.js';
3
+ interface Config {
4
+ value: Value<File | null>;
5
+ viewProps: ViewProps;
6
+ invalidFiletypeMessage: string;
7
+ lineCount: number;
8
+ filetypes?: string[];
9
+ }
10
+ export declare class FilePluginController implements Controller<FilePluginView> {
11
+ readonly value: Value<File | null>;
12
+ readonly view: FilePluginView;
13
+ readonly viewProps: ViewProps;
14
+ private readonly config;
15
+ constructor(doc: Document, config: Config);
16
+ /**
17
+ * Called when the value of the input changes.
18
+ * @param event change event.
19
+ */
20
+ private onFile;
21
+ /**
22
+ * Shows warning text for 5 seconds.
23
+ */
24
+ private showWarning;
25
+ /**
26
+ * Checks if the file is valid with the given filetypes.
27
+ * @param file File object
28
+ * @returns true if the file is valid.
29
+ */
30
+ private isFileValid;
31
+ /**
32
+ * Event handler when the delete HTML button is clicked.
33
+ * It resets the `rawValue` of the controller.
34
+ */
35
+ private onDeleteClick;
36
+ /**
37
+ * Called when the user drags over a file.
38
+ * Updates the style of the container.
39
+ * @param event drag event.
40
+ */
41
+ private onDragOver;
42
+ /**
43
+ * Called when the user leaves the container while dragging.
44
+ * Updates the style of the container.
45
+ */
46
+ private onDragLeave;
47
+ /**
48
+ * Called when the user drops a file in the container.
49
+ * Either shows a warning if it's invalid or updates the value if it's valid.
50
+ * @param ev drag event.
51
+ */
52
+ private onDrop;
53
+ /**
54
+ * Called when the value (bound to the controller) changes (e.g. when the file is selected).
55
+ */
56
+ private handleValueChange;
57
+ }
58
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const id = "file-input";
2
+ export declare const css = "__css__";
3
+ export declare const plugins: import("@tweakpane/core").InputBindingPlugin<File | null, string, import("./plugin.js").PluginInputParams>[];
@@ -0,0 +1,8 @@
1
+ import { BaseInputParams, InputBindingPlugin } from '@tweakpane/core';
2
+ export interface PluginInputParams extends BaseInputParams {
3
+ view: 'file-input';
4
+ invalidFiletypeMessage?: string;
5
+ lineCount?: number;
6
+ filetypes?: string[];
7
+ }
8
+ export declare const TweakpaneFileInputPlugin: InputBindingPlugin<File | null, string, PluginInputParams>;
@@ -0,0 +1,24 @@
1
+ import { Value, View, ViewProps } from '@tweakpane/core';
2
+ interface Config {
3
+ value: Value<File | null>;
4
+ viewProps: ViewProps;
5
+ invalidFiletypeMessage: string;
6
+ lineCount: number;
7
+ filetypes?: string[];
8
+ }
9
+ export declare class FilePluginView implements View {
10
+ readonly element: HTMLElement;
11
+ readonly container: HTMLElement;
12
+ input: HTMLInputElement;
13
+ text: HTMLSpanElement;
14
+ warning: HTMLSpanElement;
15
+ fileIcon: HTMLElement;
16
+ deleteButton: HTMLButtonElement;
17
+ constructor(doc: Document, config: Config);
18
+ /**
19
+ * Changes the style of the container based on whether the user is dragging or not.
20
+ * @param state if the user is dragging or not.
21
+ */
22
+ changeDraggingState(state: boolean): void;
23
+ }
24
+ export {};
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@kitschpatrol/tweakpane-plugin-file-import",
3
+ "version": "1.1.2-beta.1",
4
+ "type": "module",
5
+ "description": "A fork of tweakpane-plugin-file-import with build optimizations.",
6
+ "repository": "github:kitschpatrol/tweakpane-plugin-image",
7
+ "homepage": "https://github.com/kitschpatrol/tweakpane-plugin-file-import",
8
+ "author": "LuchoTurtle",
9
+ "license": "MIT",
10
+ "engines": {
11
+ "node": ">=18.0.0",
12
+ "pnpm": ">=9.0.0"
13
+ },
14
+ "main": "dist/tweakpane-plugin-file-import.js",
15
+ "types": "dist/types/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "keywords": [
20
+ "npm-package",
21
+ "tweakpane",
22
+ "tweakpane-plugin"
23
+ ],
24
+ "peerDependencies": {
25
+ "tweakpane": "^4.0.0"
26
+ },
27
+ "dependencies": {
28
+ "@tweakpane/core": "^2.0.4"
29
+ },
30
+ "devDependencies": {
31
+ "@rollup/plugin-alias": "^5.1.1",
32
+ "@rollup/plugin-node-resolve": "^15.3.0",
33
+ "@rollup/plugin-replace": "^6.0.1",
34
+ "@rollup/plugin-terser": "^0.4.4",
35
+ "@rollup/plugin-typescript": "^12.1.1",
36
+ "@typescript-eslint/eslint-plugin": "^8.11.0",
37
+ "@typescript-eslint/parser": "^8.11.0",
38
+ "autoprefixer": "^10.4.20",
39
+ "bumpp": "^9.7.1",
40
+ "eslint": "^9.13.0",
41
+ "eslint-config-prettier": "^9.1.0",
42
+ "eslint-plugin-prettier": "^5.2.1",
43
+ "eslint-plugin-simple-import-sort": "^12.1.1",
44
+ "http-server": "^14.1.1",
45
+ "npm-run-all": "^4.1.5",
46
+ "onchange": "^7.1.0",
47
+ "postcss": "^8.4.47",
48
+ "prettier": "^3.3.3",
49
+ "prettier-plugin-pkg": "^0.18.1",
50
+ "release-it": "^17.10.0",
51
+ "rimraf": "^6.0.1",
52
+ "rollup": "^4.24.0",
53
+ "rollup-plugin-cleanup": "3.2.1",
54
+ "sass": "^1.80.3",
55
+ "typescript": "^5.6.3"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "scripts": {
61
+ "build": "run-p build:*",
62
+ "build:dev": "rollup --config rollup.config.js",
63
+ "build:dts": "tsc --project tsconfig-dts.json",
64
+ "build:prod": "rollup --config rollup.config.js --environment BUILD:production",
65
+ "clean": "rimraf dist",
66
+ "format": "run-p format:*",
67
+ "format:scss": "prettier --parser scss --write \"src/sass/**/*.scss\"",
68
+ "format:ts": "eslint --fix \"src/**/*.ts\"",
69
+ "release": "bumpp --commit 'Release: %s' --tag '%s' && pnpm run build && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
70
+ "server": "http-server -c-1 -o /test/browser.html",
71
+ "start": "run-p watch server",
72
+ "test": "eslint \"src/**/*.ts\"",
73
+ "watch": "run-p watch:*",
74
+ "watch:sass": "onchange --initial --kill \"src/sass/**/*.scss\" -- npm run build:dev",
75
+ "watch:ts": "onchange --initial --kill \"src/**/*.ts\" -- rollup --config rollup.config.js"
76
+ }
77
+ }