@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.
- package/dist/tweakpane-plugin-file-import.d.ts +11 -0
- package/dist/tweakpane-plugin-file-import.js +390 -290
- package/dist/tweakpane-plugin-file-import.lite.js +247 -0
- package/dist/tweakpane-plugin-file-import.lite.min.js +2 -0
- package/dist/tweakpane-plugin-file-import.min.js +2 -1
- package/package.json +56 -59
- package/readme.md +73 -7
- package/dist/types/controller/controller.d.ts +0 -58
- package/dist/types/index.d.ts +0 -3
- package/dist/types/plugin.d.ts +0 -8
- package/dist/types/view/view.d.ts +0 -24
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { ClassName, CompositeConstraint, createPlugin, parseRecord } from "@tweakpane/core";
|
|
2
|
+
// src/view/view.ts
|
|
3
|
+
const containerClassName = ClassName("ctn");
|
|
4
|
+
const inputClassName = ClassName("input");
|
|
5
|
+
const buttonClassName = ClassName("btn");
|
|
6
|
+
var FilePluginView = class {
|
|
7
|
+
clearButton;
|
|
8
|
+
container;
|
|
9
|
+
element;
|
|
10
|
+
fileIcon;
|
|
11
|
+
input;
|
|
12
|
+
text;
|
|
13
|
+
warning;
|
|
14
|
+
constructor(doc, config) {
|
|
15
|
+
this.element = doc.createElement("div");
|
|
16
|
+
this.container = doc.createElement("div");
|
|
17
|
+
this.container.classList.add(containerClassName());
|
|
18
|
+
config.viewProps.bindClassModifiers(this.container);
|
|
19
|
+
this.input = doc.createElement("input");
|
|
20
|
+
this.input.classList.add(inputClassName());
|
|
21
|
+
this.input.setAttribute("type", "file");
|
|
22
|
+
this.input.setAttribute("accept", config.filetypes ? config.filetypes.join(",") : "*");
|
|
23
|
+
this.input.style.height = `calc(20px * ${config.lineCount})`;
|
|
24
|
+
this.fileIcon = doc.createElement("div");
|
|
25
|
+
this.fileIcon.classList.add(containerClassName("icon"));
|
|
26
|
+
this.text = doc.createElement("span");
|
|
27
|
+
this.text.classList.add(containerClassName("text"));
|
|
28
|
+
this.warning = doc.createElement("span");
|
|
29
|
+
this.warning.classList.add(containerClassName("warning"));
|
|
30
|
+
this.warning.textContent = config.invalidFiletypeMessage;
|
|
31
|
+
this.warning.style.display = "none";
|
|
32
|
+
this.clearButton = doc.createElement("button");
|
|
33
|
+
this.clearButton.classList.add(buttonClassName("b"));
|
|
34
|
+
this.clearButton.textContent = "Delete";
|
|
35
|
+
this.clearButton.style.display = "none";
|
|
36
|
+
this.container.append(this.input);
|
|
37
|
+
this.container.append(this.fileIcon);
|
|
38
|
+
this.element.append(this.container);
|
|
39
|
+
this.element.append(this.warning);
|
|
40
|
+
this.element.append(this.clearButton);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Changes the style of the container based on whether the user is dragging or
|
|
44
|
+
* not.
|
|
45
|
+
*
|
|
46
|
+
* @param state If the user is dragging or not.
|
|
47
|
+
*/
|
|
48
|
+
changeDraggingState(state) {
|
|
49
|
+
if (state) this.container.classList.add(containerClassName("input_area_dragging"));
|
|
50
|
+
else this.container.classList.remove(containerClassName("input_area_dragging"));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
// src/controller/controller.ts
|
|
54
|
+
var FilePluginController = class {
|
|
55
|
+
value;
|
|
56
|
+
view;
|
|
57
|
+
viewProps;
|
|
58
|
+
config;
|
|
59
|
+
constructor(doc, config) {
|
|
60
|
+
this.value = config.value;
|
|
61
|
+
this.viewProps = config.viewProps;
|
|
62
|
+
this.view = new FilePluginView(doc, {
|
|
63
|
+
filetypes: config.filetypes,
|
|
64
|
+
invalidFiletypeMessage: config.invalidFiletypeMessage,
|
|
65
|
+
lineCount: config.lineCount,
|
|
66
|
+
value: config.value,
|
|
67
|
+
viewProps: this.viewProps
|
|
68
|
+
});
|
|
69
|
+
this.config = config;
|
|
70
|
+
this.onFile = this.onFile.bind(this);
|
|
71
|
+
this.onDrop = this.onDrop.bind(this);
|
|
72
|
+
this.onDragOver = this.onDragOver.bind(this);
|
|
73
|
+
this.onDragLeave = this.onDragLeave.bind(this);
|
|
74
|
+
this.onDeleteClick = this.onDeleteClick.bind(this);
|
|
75
|
+
this.view.input.addEventListener("change", this.onFile);
|
|
76
|
+
this.view.element.addEventListener("drop", this.onDrop);
|
|
77
|
+
this.view.element.addEventListener("dragover", this.onDragOver);
|
|
78
|
+
this.view.element.addEventListener("dragleave", this.onDragLeave);
|
|
79
|
+
this.view.clearButton.addEventListener("click", this.onDeleteClick);
|
|
80
|
+
this.value.emitter.on("change", () => {
|
|
81
|
+
this.handleValueChange();
|
|
82
|
+
});
|
|
83
|
+
this.viewProps.handleDispose(() => {
|
|
84
|
+
this.view.input.removeEventListener("change", this.onFile);
|
|
85
|
+
this.view.element.removeEventListener("drop", this.onDrop);
|
|
86
|
+
this.view.element.removeEventListener("dragover", this.onDragOver);
|
|
87
|
+
this.view.element.removeEventListener("dragleave", this.onDragLeave);
|
|
88
|
+
this.view.clearButton.removeEventListener("click", this.onDeleteClick);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Called when the value (bound to the controller) changes (e.g. when the file
|
|
93
|
+
* is selected).
|
|
94
|
+
*/
|
|
95
|
+
handleValueChange() {
|
|
96
|
+
const fileObject = this.value.rawValue;
|
|
97
|
+
const containerElement = this.view.container;
|
|
98
|
+
const textElement = this.view.text;
|
|
99
|
+
const fileIconElement = this.view.fileIcon;
|
|
100
|
+
const { clearButton } = this.view;
|
|
101
|
+
if (fileObject) {
|
|
102
|
+
textElement.textContent = fileObject.name;
|
|
103
|
+
containerElement.append(textElement);
|
|
104
|
+
if (containerElement.contains(fileIconElement)) fileIconElement.remove();
|
|
105
|
+
this.view.warning.style.display = "none";
|
|
106
|
+
clearButton.style.display = "block";
|
|
107
|
+
containerElement.style.border = "unset";
|
|
108
|
+
} else {
|
|
109
|
+
textElement.textContent = "";
|
|
110
|
+
containerElement.append(fileIconElement);
|
|
111
|
+
textElement.remove();
|
|
112
|
+
this.view.warning.style.display = "none";
|
|
113
|
+
clearButton.style.display = "none";
|
|
114
|
+
containerElement.style.border = "1px dashed #717070";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Checks if the file is valid with the given filetypes.
|
|
119
|
+
*
|
|
120
|
+
* @param file File object
|
|
121
|
+
*
|
|
122
|
+
* @returns True if the file is valid.
|
|
123
|
+
*/
|
|
124
|
+
isFileValid(file) {
|
|
125
|
+
const { filetypes } = this.config;
|
|
126
|
+
const fileExtension = "." + (file.name.split(".").pop()?.toLowerCase() ?? "");
|
|
127
|
+
return !filetypes || filetypes.length === 0 || filetypes.includes(fileExtension);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Event handler when the delete HTML button is clicked. It resets the
|
|
131
|
+
* `rawValue` of the controller.
|
|
132
|
+
*/
|
|
133
|
+
onDeleteClick() {
|
|
134
|
+
if (!this.value.rawValue) return;
|
|
135
|
+
this.value.setRawValue(null);
|
|
136
|
+
this.view.input.value = "";
|
|
137
|
+
this.view.warning.style.display = "none";
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Called when the user leaves the container while dragging. Updates the style
|
|
141
|
+
* of the container.
|
|
142
|
+
*/
|
|
143
|
+
onDragLeave() {
|
|
144
|
+
this.view.changeDraggingState(false);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Called when the user drags over a file. Updates the style of the container.
|
|
148
|
+
*
|
|
149
|
+
* @param event Drag event.
|
|
150
|
+
*/
|
|
151
|
+
onDragOver(event) {
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
this.view.changeDraggingState(true);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Called when the user drops a file in the container. Either shows a warning
|
|
157
|
+
* if it's invalid or updates the value if it's valid.
|
|
158
|
+
*
|
|
159
|
+
* @param event Drag event.
|
|
160
|
+
*/
|
|
161
|
+
onDrop(event) {
|
|
162
|
+
try {
|
|
163
|
+
if (!(event instanceof DragEvent)) return;
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
const files = event.dataTransfer?.files;
|
|
166
|
+
if (files?.length !== 1) return;
|
|
167
|
+
const file = files.item(0);
|
|
168
|
+
if (!file) return;
|
|
169
|
+
if (this.isFileValid(file)) this.value.setRawValue(file);
|
|
170
|
+
else this.showWarning();
|
|
171
|
+
} finally {
|
|
172
|
+
this.view.changeDraggingState(false);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Called when the value of the input changes.
|
|
177
|
+
*
|
|
178
|
+
* @param _event Change event.
|
|
179
|
+
*/
|
|
180
|
+
onFile(_event) {
|
|
181
|
+
const file = this.view.input.files?.item(0);
|
|
182
|
+
if (!file) return;
|
|
183
|
+
if (this.isFileValid(file)) this.value.setRawValue(file);
|
|
184
|
+
else this.showWarning();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Shows warning text for 5 seconds.
|
|
188
|
+
*/
|
|
189
|
+
showWarning() {
|
|
190
|
+
this.view.warning.style.display = "block";
|
|
191
|
+
setTimeout(() => {
|
|
192
|
+
this.view.warning.style.display = "none";
|
|
193
|
+
}, 5e3);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
// src/plugin.ts
|
|
197
|
+
function readFile(exValue) {
|
|
198
|
+
return exValue instanceof File ? exValue : null;
|
|
199
|
+
}
|
|
200
|
+
function writeFile(target, inValue) {
|
|
201
|
+
target.write(inValue);
|
|
202
|
+
}
|
|
203
|
+
const TweakpaneFileInputPlugin = createPlugin({
|
|
204
|
+
accept(exValue, params) {
|
|
205
|
+
if (typeof exValue !== "string") return null;
|
|
206
|
+
const result = parseRecord(params, (p) => ({
|
|
207
|
+
filetypes: p.optional.array(p.required.string),
|
|
208
|
+
invalidFiletypeMessage: p.optional.string,
|
|
209
|
+
lineCount: p.optional.number,
|
|
210
|
+
view: p.required.constant("file-input")
|
|
211
|
+
}));
|
|
212
|
+
if (!result) return null;
|
|
213
|
+
return {
|
|
214
|
+
initialValue: exValue,
|
|
215
|
+
params: result
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
binding: {
|
|
219
|
+
constraint(_args) {
|
|
220
|
+
return new CompositeConstraint([]);
|
|
221
|
+
},
|
|
222
|
+
reader(_args) {
|
|
223
|
+
return readFile;
|
|
224
|
+
},
|
|
225
|
+
writer(_args) {
|
|
226
|
+
return writeFile;
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
controller(args) {
|
|
230
|
+
return new FilePluginController(args.document, {
|
|
231
|
+
filetypes: args.params.filetypes,
|
|
232
|
+
invalidFiletypeMessage: args.params.invalidFiletypeMessage ?? "Unaccepted file type.",
|
|
233
|
+
lineCount: args.params.lineCount ?? 3,
|
|
234
|
+
value: args.value,
|
|
235
|
+
viewProps: args.viewProps
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
id: "file-input",
|
|
239
|
+
type: "input"
|
|
240
|
+
});
|
|
241
|
+
// src/styles/plugin.scss?inline
|
|
242
|
+
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";
|
|
243
|
+
// src/index.ts
|
|
244
|
+
const id = "file-input";
|
|
245
|
+
const css = plugin_default;
|
|
246
|
+
const plugins = [TweakpaneFileInputPlugin];
|
|
247
|
+
export { css, id, plugins };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ClassName as e,CompositeConstraint as t,createPlugin as n,parseRecord as r}from"@tweakpane/core";const i=e(`ctn`),a=e(`input`),o=e(`btn`);var s=class{clearButton;container;element;fileIcon;input;text;warning;constructor(e,t){this.element=e.createElement(`div`),this.container=e.createElement(`div`),this.container.classList.add(i()),t.viewProps.bindClassModifiers(this.container),this.input=e.createElement(`input`),this.input.classList.add(a()),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(i(`icon`)),this.text=e.createElement(`span`),this.text.classList.add(i(`text`)),this.warning=e.createElement(`span`),this.warning.classList.add(i(`warning`)),this.warning.textContent=t.invalidFiletypeMessage,this.warning.style.display=`none`,this.clearButton=e.createElement(`button`),this.clearButton.classList.add(o(`b`)),this.clearButton.textContent=`Delete`,this.clearButton.style.display=`none`,this.container.append(this.input),this.container.append(this.fileIcon),this.element.append(this.container),this.element.append(this.warning),this.element.append(this.clearButton)}changeDraggingState(e){e?this.container.classList.add(i(`input_area_dragging`)):this.container.classList.remove(i(`input_area_dragging`))}},c=class{value;view;viewProps;config;constructor(e,t){this.value=t.value,this.viewProps=t.viewProps,this.view=new s(e,{filetypes:t.filetypes,invalidFiletypeMessage:t.invalidFiletypeMessage,lineCount:t.lineCount,value:t.value,viewProps:this.viewProps}),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.clearButton.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.clearButton.removeEventListener(`click`,this.onDeleteClick)})}handleValueChange(){let e=this.value.rawValue,t=this.view.container,n=this.view.text,r=this.view.fileIcon,{clearButton:i}=this.view;e?(n.textContent=e.name,t.append(n),t.contains(r)&&r.remove(),this.view.warning.style.display=`none`,i.style.display=`block`,t.style.border=`unset`):(n.textContent=``,t.append(r),n.remove(),this.view.warning.style.display=`none`,i.style.display=`none`,t.style.border=`1px dashed #717070`)}isFileValid(e){let{filetypes:t}=this.config,n=`.`+(e.name.split(`.`).pop()?.toLowerCase()??``);return!t||t.length===0||t.includes(n)}onDeleteClick(){this.value.rawValue&&(this.value.setRawValue(null),this.view.input.value=``,this.view.warning.style.display=`none`)}onDragLeave(){this.view.changeDraggingState(!1)}onDragOver(e){e.preventDefault(),this.view.changeDraggingState(!0)}onDrop(e){try{if(!(e instanceof DragEvent))return;e.preventDefault();let t=e.dataTransfer?.files;if(t?.length!==1)return;let n=t.item(0);if(!n)return;this.isFileValid(n)?this.value.setRawValue(n):this.showWarning()}finally{this.view.changeDraggingState(!1)}}onFile(e){let t=this.view.input.files?.item(0);t&&(this.isFileValid(t)?this.value.setRawValue(t):this.showWarning())}showWarning(){this.view.warning.style.display=`block`,setTimeout(()=>{this.view.warning.style.display=`none`},5e3)}};function l(e){return e instanceof File?e:null}function u(e,t){e.write(t)}const d=n({accept(e,t){if(typeof e!=`string`)return null;let n=r(t,e=>({filetypes:e.optional.array(e.required.string),invalidFiletypeMessage:e.optional.string,lineCount:e.optional.number,view:e.required.constant(`file-input`)}));return n?{initialValue:e,params:n}:null},binding:{constraint(e){return new t([])},reader(e){return l},writer(e){return u}},controller(e){return new c(e.document,{filetypes:e.params.filetypes,invalidFiletypeMessage:e.params.invalidFiletypeMessage??`Unaccepted file type.`,lineCount:e.params.lineCount??3,value:e.value,viewProps:e.viewProps})},id:`file-input`,type:`input`});var f=`.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}
|
|
2
|
+
`;const p=`file-input`,m=f,h=[d];export{m as css,p as id,h as plugins};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function e(e){return e}function t(t,n){return e(Object.keys(n).reduce((e,r)=>{if(e===void 0)return;let i=n[r],a=i(t[r]);return a.succeeded?Object.assign(Object.assign({},e),{[r]:a.value}):void 0},{}))}function n(e,t){return e.reduce((e,n)=>{if(e===void 0)return;let r=t(n);if(r.succeeded&&r.value!==void 0)return[...e,r.value]},[])}function r(e){return typeof e==`object`&&!!e}function i(e){return t=>n=>{if(!t&&n===void 0)return{succeeded:!1,value:void 0};if(t&&n===void 0)return{succeeded:!0,value:void 0};let r=e(n);return r===void 0?{succeeded:!1,value:void 0}:{succeeded:!0,value:r}}}function a(e){return{custom:t=>i(t)(e),boolean:i(e=>typeof e==`boolean`?e:void 0)(e),number:i(e=>typeof e==`number`?e:void 0)(e),string:i(e=>typeof e==`string`?e:void 0)(e),function:i(e=>typeof e==`function`?e:void 0)(e),constant:t=>i(e=>e===t?t:void 0)(e),raw:i(e=>e)(e),object:n=>i(e=>{if(r(e))return t(e,n)})(e),array:t=>i(e=>{if(Array.isArray(e))return n(e,t)})(e)}}const o={optional:a(!0),required:a(!1)};function s(e,t){let n=t(o),r=o.required.object(n)(e);return r.succeeded?r.value:void 0}function c(e){return(t,n)=>[`tp`,`-`,e,`v`,t?`_${t}`:``,n?`-${n}`:``].join(``)}const l=new class{constructor(e){let[t,n]=e.split(`-`),r=t.split(`.`);this.major=parseInt(r[0],10),this.minor=parseInt(r[1],10),this.patch=parseInt(r[2],10),this.prerelease=n??null}toString(){let e=[this.major,this.minor,this.patch].join(`.`);return this.prerelease===null?e:[e,this.prerelease].join(`-`)}}(`2.0.5`);function u(e){return Object.assign({core:l},e)}var d=class{constructor(e){this.constraints=e}constrain(e){return this.constraints.reduce((e,t)=>t.constrain(e),e)}};const f=c(`ctn`),p=c(`input`),m=c(`btn`);var h=class{clearButton;container;element;fileIcon;input;text;warning;constructor(e,t){this.element=e.createElement(`div`),this.container=e.createElement(`div`),this.container.classList.add(f()),t.viewProps.bindClassModifiers(this.container),this.input=e.createElement(`input`),this.input.classList.add(p()),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(f(`icon`)),this.text=e.createElement(`span`),this.text.classList.add(f(`text`)),this.warning=e.createElement(`span`),this.warning.classList.add(f(`warning`)),this.warning.textContent=t.invalidFiletypeMessage,this.warning.style.display=`none`,this.clearButton=e.createElement(`button`),this.clearButton.classList.add(m(`b`)),this.clearButton.textContent=`Delete`,this.clearButton.style.display=`none`,this.container.append(this.input),this.container.append(this.fileIcon),this.element.append(this.container),this.element.append(this.warning),this.element.append(this.clearButton)}changeDraggingState(e){e?this.container.classList.add(f(`input_area_dragging`)):this.container.classList.remove(f(`input_area_dragging`))}},g=class{value;view;viewProps;config;constructor(e,t){this.value=t.value,this.viewProps=t.viewProps,this.view=new h(e,{filetypes:t.filetypes,invalidFiletypeMessage:t.invalidFiletypeMessage,lineCount:t.lineCount,value:t.value,viewProps:this.viewProps}),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.clearButton.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.clearButton.removeEventListener(`click`,this.onDeleteClick)})}handleValueChange(){let e=this.value.rawValue,t=this.view.container,n=this.view.text,r=this.view.fileIcon,{clearButton:i}=this.view;e?(n.textContent=e.name,t.append(n),t.contains(r)&&r.remove(),this.view.warning.style.display=`none`,i.style.display=`block`,t.style.border=`unset`):(n.textContent=``,t.append(r),n.remove(),this.view.warning.style.display=`none`,i.style.display=`none`,t.style.border=`1px dashed #717070`)}isFileValid(e){let{filetypes:t}=this.config,n=`.`+(e.name.split(`.`).pop()?.toLowerCase()??``);return!t||t.length===0||t.includes(n)}onDeleteClick(){this.value.rawValue&&(this.value.setRawValue(null),this.view.input.value=``,this.view.warning.style.display=`none`)}onDragLeave(){this.view.changeDraggingState(!1)}onDragOver(e){e.preventDefault(),this.view.changeDraggingState(!0)}onDrop(e){try{if(!(e instanceof DragEvent))return;e.preventDefault();let t=e.dataTransfer?.files;if(t?.length!==1)return;let n=t.item(0);if(!n)return;this.isFileValid(n)?this.value.setRawValue(n):this.showWarning()}finally{this.view.changeDraggingState(!1)}}onFile(e){let t=this.view.input.files?.item(0);t&&(this.isFileValid(t)?this.value.setRawValue(t):this.showWarning())}showWarning(){this.view.warning.style.display=`block`,setTimeout(()=>{this.view.warning.style.display=`none`},5e3)}};function _(e){return e instanceof File?e:null}function v(e,t){e.write(t)}const y=u({accept(e,t){if(typeof e!=`string`)return null;let n=s(t,e=>({filetypes:e.optional.array(e.required.string),invalidFiletypeMessage:e.optional.string,lineCount:e.optional.number,view:e.required.constant(`file-input`)}));return n?{initialValue:e,params:n}:null},binding:{constraint(e){return new d([])},reader(e){return _},writer(e){return v}},controller(e){return new g(e.document,{filetypes:e.params.filetypes,invalidFiletypeMessage:e.params.invalidFiletypeMessage??`Unaccepted file type.`,lineCount:e.params.lineCount??3,value:e.value,viewProps:e.viewProps})},id:`file-input`,type:`input`});var b=`.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}
|
|
2
|
+
`;const x=`file-input`,S=b,C=[y];export{S as css,x as id,C as plugins};
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/tweakpane-plugin-file-import",
|
|
3
|
-
"version": "1.2.0-fork.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "1.2.0-fork.2",
|
|
5
4
|
"description": "Fork of tweakpane-plugin-file-import with build optimizations.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"npm-package",
|
|
7
|
+
"tweakpane",
|
|
8
|
+
"tweakpane-plugin"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/kitschpatrol/tweakpane-plugin-file-import",
|
|
6
11
|
"repository": {
|
|
7
12
|
"type": "git",
|
|
8
13
|
"url": "git+https://github.com/kitschpatrol/tweakpane-plugin-file-import.git"
|
|
9
14
|
},
|
|
10
|
-
"
|
|
15
|
+
"license": "MIT",
|
|
11
16
|
"author": "Luís Arteiro",
|
|
12
17
|
"maintainers": [
|
|
13
18
|
{
|
|
@@ -16,77 +21,69 @@
|
|
|
16
21
|
"url": "https://ericmika.com"
|
|
17
22
|
}
|
|
18
23
|
],
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/tweakpane-plugin-file-import.d.ts",
|
|
29
|
+
"default": "./dist/tweakpane-plugin-file-import.js"
|
|
30
|
+
},
|
|
31
|
+
"./lite": {
|
|
32
|
+
"types": "./dist/tweakpane-plugin-file-import.d.ts",
|
|
33
|
+
"default": "./dist/tweakpane-plugin-file-import.lite.js"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
28
36
|
},
|
|
29
|
-
"main": "dist/tweakpane-plugin-file-import.js",
|
|
30
|
-
"
|
|
37
|
+
"main": "./dist/tweakpane-plugin-file-import.js",
|
|
38
|
+
"module": "./dist/tweakpane-plugin-file-import.js",
|
|
39
|
+
"types": "./dist/tweakpane-plugin-file-import.d.ts",
|
|
31
40
|
"files": [
|
|
32
41
|
"dist"
|
|
33
42
|
],
|
|
34
|
-
"keywords": [
|
|
35
|
-
"npm-package",
|
|
36
|
-
"tweakpane",
|
|
37
|
-
"tweakpane-plugin"
|
|
38
|
-
],
|
|
39
|
-
"peerDependencies": {
|
|
40
|
-
"tweakpane": "^4.0.0"
|
|
41
|
-
},
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@tweakpane/core": "^2.0.5"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@rollup/plugin-typescript": "^12.3.0",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^8.71.2",
|
|
53
|
-
"@typescript-eslint/parser": "^8.71.2",
|
|
54
|
-
"autoprefixer": "^10.6.1",
|
|
47
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
48
|
+
"@kitschpatrol/chagent": "^0.5.0",
|
|
49
|
+
"@kitschpatrol/shared-config": "^8.14.1",
|
|
50
|
+
"@tsdown/css": "^0.23.7",
|
|
51
|
+
"@types/node": "~24.13.6",
|
|
55
52
|
"bumpp": "^12.3.0",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
60
|
-
"http-server": "^14.1.1",
|
|
61
|
-
"mdat": "^3.6.2",
|
|
62
|
-
"postcss": "^8.5.30",
|
|
63
|
-
"prettier": "^3.9.10",
|
|
64
|
-
"prettier-plugin-pkg": "^0.22.1",
|
|
65
|
-
"rollup": "^4.64.6",
|
|
66
|
-
"rollup-plugin-cleanup": "3.2.1",
|
|
67
|
-
"sass": "^1.105.1",
|
|
53
|
+
"happy-dom": "^21.0.4",
|
|
54
|
+
"publint": "^0.3.25",
|
|
55
|
+
"sass": "^1.108.1",
|
|
68
56
|
"shx": "^0.4.0",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
57
|
+
"stylelint-config-standard-scss": "^17.0.0",
|
|
58
|
+
"tsdown": "^0.23.7",
|
|
59
|
+
"tweakpane": "^4.0.5",
|
|
60
|
+
"typescript": "~6.0.3",
|
|
61
|
+
"vite": "^8.3.7",
|
|
62
|
+
"vitest": "^5.1.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"tweakpane": "^4.0.0"
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": "^18.0.0 || ^20.0.0 || ^22.0.0 || ^24.0.0 || >=26.0.0"
|
|
69
|
+
},
|
|
70
|
+
"devEngines": {
|
|
71
|
+
"runtime": {
|
|
72
|
+
"name": "node",
|
|
73
|
+
"version": "^24.16.0 || >=26.3.0"
|
|
74
|
+
}
|
|
71
75
|
},
|
|
72
76
|
"publishConfig": {
|
|
73
77
|
"access": "public"
|
|
74
78
|
},
|
|
75
79
|
"scripts": {
|
|
76
|
-
"build": "
|
|
77
|
-
"build:dev": "rollup --config rollup.config.js",
|
|
78
|
-
"build:dts": "tsc --project tsconfig-dts.json",
|
|
79
|
-
"build:prod": "rollup --config rollup.config.js --environment BUILD:production",
|
|
80
|
-
"clean": "shx rm -rf dist",
|
|
80
|
+
"build": "tsdown",
|
|
81
81
|
"clean-deep": "shx rm -f pnpm-lock.yaml && git clean -fdX",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"start": "pnpm run '/^(watch|server)$/'",
|
|
89
|
-
"test": "eslint \"src/**/*.ts\" && mdat check",
|
|
90
|
-
"watch": "rollup --config rollup.config.js --watch --no-watch.clearScreen"
|
|
82
|
+
"dev": "vite",
|
|
83
|
+
"fix": "ksc fix",
|
|
84
|
+
"lint": "ksc lint",
|
|
85
|
+
"release": "bumpp --preid fork --commit 'Release: %s' --tag '%s' --all --execute 'chagent' && pnpm build && pnpm publish --otp $(op item get npm --otp) --tag latest",
|
|
86
|
+
"test": "vitest run",
|
|
87
|
+
"watch": "tsdown --watch"
|
|
91
88
|
}
|
|
92
89
|
}
|
package/readme.md
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/@kitschpatrol/tweakpane-plugin-file-import)
|
|
10
10
|
[](https://opensource.org/license/mit)
|
|
11
|
+
[](https://github.com/kitschpatrol/tweakpane-plugin-file-import/actions/workflows/ci.yml)
|
|
11
12
|
[](https://www.npmjs.com/package/@kitschpatrol/tweakpane-plugin-file-import)
|
|
12
13
|
|
|
13
14
|
<!-- /badges -->
|
|
@@ -20,15 +21,70 @@
|
|
|
20
21
|
|
|
21
22
|
## Overview
|
|
22
23
|
|
|
23
|
-
This is a fork of [Luís Arteiro](https://github.com/LuchoTurtle)
|
|
24
|
+
This is a fork of [Luís Arteiro's](https://github.com/LuchoTurtle) [tweakpane-plugin-file-import](https://github.com/LuchoTurtle/tweakpane-plugin-file-import) with externalized dependencies.
|
|
24
25
|
|
|
25
26
|
This allows for smaller bundled file sizes in projects using multiple Tweakpane plugins.
|
|
26
27
|
|
|
27
28
|
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.
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
See the [upstream readme](https://github.com/LuchoTurtle/tweakpane-plugin-file-import#readme) for details on the original plugin and its usage.
|
|
30
31
|
|
|
31
|
-
##
|
|
32
|
+
## Fork changes
|
|
33
|
+
|
|
34
|
+
- Publishes as `@kitschpatrol/tweakpane-plugin-file-import` instead of `tweakpane-plugin-file-import`.
|
|
35
|
+
- Adds a `/lite` export that imports `@tweakpane/core` instead of bundling it so projects can share one copy of `core` across multiple plugins.
|
|
36
|
+
- Exports public parameter types.
|
|
37
|
+
- Migrates the repository structure to align with the Tweakpane plugin template provided by [@kitschpatrol/create-project](https://github.com/kitschpatrol/create-project), which includes:
|
|
38
|
+
- [pnpm](https://pnpm.io/) instead of npm for local development
|
|
39
|
+
- [tsdown](https://tsdown.dev/) for bundling, type generation, and SCSS processing
|
|
40
|
+
- [vite](https://vite.dev/) for live-reloading the demo project
|
|
41
|
+
- [vitest](https://vitest.dev/) for automated tests
|
|
42
|
+
- [ksc](https://github.com/kitschpatrol/shared-config) for linting and shared configuration
|
|
43
|
+
- [chagent](https://github.com/kitschpatrol/chagent) for release notes
|
|
44
|
+
- Clears the drag state even when drop processing throws.
|
|
45
|
+
|
|
46
|
+
## Getting started
|
|
47
|
+
|
|
48
|
+
### Dependencies
|
|
49
|
+
|
|
50
|
+
The plugin requires [Tweakpane 4](https://www.npmjs.com/package/tweakpane).
|
|
51
|
+
|
|
52
|
+
The `/lite` export path imports [@tweakpane/core](https://www.npmjs.com/package/@tweakpane/core) rather than bundling it. It is installed as a dependency of this plugin, so only projects without a bundler need to provide it directly.
|
|
53
|
+
|
|
54
|
+
If you're using Svelte 4 or 5 as a front-end library, take a look at [Svelte Tweakpane UI](https://kitschpatrol.com/svelte-tweakpane-ui), which wraps Tweakpane in a set of Svelte-friendly components, including the [`<File>`](https://kitschpatrol.com/svelte-tweakpane-ui/docs/components/file) control from this plugin.
|
|
55
|
+
|
|
56
|
+
<!-- installation -->
|
|
57
|
+
|
|
58
|
+
### Installation
|
|
59
|
+
|
|
60
|
+
Add it to your project:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
npm install @kitschpatrol/tweakpane-plugin-file-import
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
<!-- /installation -->
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import * as TweakpanePluginFileImport from '@kitschpatrol/tweakpane-plugin-file-import'
|
|
72
|
+
import { Pane } from 'tweakpane'
|
|
73
|
+
|
|
74
|
+
const pane = new Pane()
|
|
75
|
+
pane.registerPlugin(TweakpanePluginFileImport)
|
|
76
|
+
|
|
77
|
+
const parameters = { file: '' }
|
|
78
|
+
pane.addBinding(parameters, 'file', {
|
|
79
|
+
filetypes: ['.png', '.jpg'],
|
|
80
|
+
lineCount: 3,
|
|
81
|
+
view: 'file-input',
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
To share core through your bundler, import `@kitschpatrol/tweakpane-plugin-file-import/lite` instead.
|
|
86
|
+
|
|
87
|
+
## Implementation notes
|
|
32
88
|
|
|
33
89
|
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.
|
|
34
90
|
|
|
@@ -38,16 +94,26 @@ Externalizing this dependency allows build tools like [vite](https://vite.dev) t
|
|
|
38
94
|
|
|
39
95
|
If you're not using a bundler, direct ESM imports from URLs can still work by defining the `@tweakpane/core` dependency in an [importmap](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap).
|
|
40
96
|
|
|
41
|
-
## Implementation notes
|
|
42
|
-
|
|
43
|
-
PNPM is used as the package manager.
|
|
44
|
-
|
|
45
97
|
## Versioning
|
|
46
98
|
|
|
47
99
|
In addition to the dependency externalization change, this fork also includes dependency updates. In an effort to stay in sync with future upstream versions, release version numbers are tagged with a "fork" suffix and an incrementing number.
|
|
48
100
|
|
|
101
|
+
<!-- contributing -->
|
|
102
|
+
|
|
103
|
+
## Contributing
|
|
104
|
+
|
|
105
|
+
[Issues](https://github.com/kitschpatrol/tweakpane-plugin-file-import/issues) are welcome and appreciated.
|
|
106
|
+
|
|
107
|
+
Please open an issue to discuss changes before submitting a pull request. Unsolicited PRs (especially AI-generated ones) are unlikely to be merged.
|
|
108
|
+
|
|
109
|
+
This repository uses [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config) (via its `ksc` CLI) for linting and formatting, plus [MDAT](https://github.com/kitschpatrol/mdat) for readme placeholder expansion.
|
|
110
|
+
|
|
111
|
+
<!-- /contributing -->
|
|
112
|
+
|
|
49
113
|
## License
|
|
50
114
|
|
|
51
115
|
Original plugin: [MIT](license.txt) © Luís Arteiro
|
|
52
116
|
|
|
117
|
+
Original template contributions: [MIT](license.txt) © [cocopon](https://github.com/cocopon)
|
|
118
|
+
|
|
53
119
|
Fork modifications: [MIT](license.txt) © [Eric Mika](https://ericmika.com)
|
|
@@ -1,58 +0,0 @@
|
|
|
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 {};
|
package/dist/types/index.d.ts
DELETED
package/dist/types/plugin.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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>;
|