@potch/html-bin 2.1.2 → 2.2.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/README.md +6 -8
- package/build/index.min.js +1 -1
- package/build/index.min.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +50 -24
- package/src/style.css +19 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -115,12 +115,16 @@ const createEditors = (sources, parents, updateFactory) => {
|
|
|
115
115
|
create a bin component.
|
|
116
116
|
Options:
|
|
117
117
|
- `container` (optional Element): will automatically append the bin if provided
|
|
118
|
+
- `extraClasses`: a string of extra CSS classes to append to the bin element
|
|
118
119
|
- `sources`: object with optional `{ js, css, html }` strings of source to put
|
|
119
|
-
|
|
120
|
+
in the corresponding editors
|
|
120
121
|
- `split`: number from [0, 1] specifying the ratio between the editor and
|
|
121
|
-
|
|
122
|
+
preview panes. default is `0.5`.
|
|
123
|
+
- `splitMode`: (default `true`) whether to have the preview in split screen
|
|
124
|
+
with code tabs.
|
|
122
125
|
- `width`: CSS string to override default `--bin-width` value
|
|
123
126
|
- `height`: CSS string to override default `--bin-height` value
|
|
127
|
+
|
|
124
128
|
Returns object with the following fields:
|
|
125
129
|
- `el`: Element of the outermost HTML element of the bin
|
|
126
130
|
- `editors`: contains `{ js, css, html }` properties with the CodeMirror
|
|
@@ -133,6 +137,7 @@ Returns object with the following fields:
|
|
|
133
137
|
*/
|
|
134
138
|
export const createBin = ({
|
|
135
139
|
container,
|
|
140
|
+
extraClasses = "",
|
|
136
141
|
sources: rawSources,
|
|
137
142
|
split = 0.5,
|
|
138
143
|
initialTab = "js",
|
|
@@ -164,6 +169,8 @@ export const createBin = ({
|
|
|
164
169
|
}
|
|
165
170
|
});
|
|
166
171
|
|
|
172
|
+
const isFullScreen = signal(false);
|
|
173
|
+
|
|
167
174
|
const isMiniMode = computed(() => {
|
|
168
175
|
const w = actualWidth.value;
|
|
169
176
|
return !splitMode || w <= 700;
|
|
@@ -335,9 +342,11 @@ export const createBin = ({
|
|
|
335
342
|
{
|
|
336
343
|
className: computed(
|
|
337
344
|
() =>
|
|
338
|
-
"bin" +
|
|
345
|
+
"bin " +
|
|
346
|
+
extraClasses +
|
|
339
347
|
maybe(isMiniMode.value, " bin--mini-mode") +
|
|
340
|
-
maybe(resizing.value, " bin--resizing")
|
|
348
|
+
maybe(resizing.value, " bin--resizing") +
|
|
349
|
+
maybe(isFullScreen.value, " bin--fullscreen")
|
|
341
350
|
),
|
|
342
351
|
},
|
|
343
352
|
_(
|
|
@@ -360,6 +369,21 @@ export const createBin = ({
|
|
|
360
369
|
_(
|
|
361
370
|
"div",
|
|
362
371
|
{ className: "bin__menu" },
|
|
372
|
+
_(
|
|
373
|
+
"button",
|
|
374
|
+
{
|
|
375
|
+
className: "bin__preview__expand bin__iconbutton",
|
|
376
|
+
title: "show the code tabs",
|
|
377
|
+
"aria-label": "show the code tabs",
|
|
378
|
+
style: computed(() => ({
|
|
379
|
+
display: splitOverride.value === 0 ? "block" : "none",
|
|
380
|
+
})),
|
|
381
|
+
onclick: () => {
|
|
382
|
+
splitOverride.value = null;
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
"⏭️"
|
|
386
|
+
),
|
|
363
387
|
_(
|
|
364
388
|
"div",
|
|
365
389
|
{ className: "bin__tab bin__preview_tab bin__tab--active" },
|
|
@@ -375,26 +399,21 @@ export const createBin = ({
|
|
|
375
399
|
"🔁"
|
|
376
400
|
)
|
|
377
401
|
),
|
|
378
|
-
_(
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
innerText: computed(() => (splitOverride.value === 0 ? "⏭️" : "↔️")),
|
|
391
|
-
style: computed(() => ({
|
|
392
|
-
order: splitOverride.value === 0 ? -1 : "unset",
|
|
393
|
-
})),
|
|
394
|
-
onclick: () => {
|
|
395
|
-
splitOverride.value = splitOverride.value === 0 ? null : 0;
|
|
402
|
+
_(
|
|
403
|
+
"button",
|
|
404
|
+
{
|
|
405
|
+
className: "bin__preview__expand bin__iconbutton",
|
|
406
|
+
title: "show only the preview",
|
|
407
|
+
"aria-label": "show only the preview",
|
|
408
|
+
style: computed(() => ({
|
|
409
|
+
display: splitOverride.value === 0 ? "none" : "block",
|
|
410
|
+
})),
|
|
411
|
+
onclick: () => {
|
|
412
|
+
splitOverride.value = 0;
|
|
413
|
+
},
|
|
396
414
|
},
|
|
397
|
-
|
|
415
|
+
"↔️"
|
|
416
|
+
)
|
|
398
417
|
),
|
|
399
418
|
editorPanes.js,
|
|
400
419
|
editorPanes.css,
|
|
@@ -410,7 +429,14 @@ export const createBin = ({
|
|
|
410
429
|
src: previewURL,
|
|
411
430
|
}),
|
|
412
431
|
_("div", { className: "bin__controls" })
|
|
413
|
-
)
|
|
432
|
+
),
|
|
433
|
+
_("button", {
|
|
434
|
+
className: "bin__fullscreen bin__iconbutton",
|
|
435
|
+
title: "toggle fullscreen mode",
|
|
436
|
+
"aria-label": "toggle fullscreen mode",
|
|
437
|
+
innerText: computed(() => (isFullScreen.value ? "↖️" : "↘️")),
|
|
438
|
+
onclick: () => (isFullScreen.value = !isFullScreen.value),
|
|
439
|
+
})
|
|
414
440
|
);
|
|
415
441
|
|
|
416
442
|
if (width) binEl.style.setProperty("--bin-width", width);
|
package/src/style.css
CHANGED
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
container-type: inline-size;
|
|
25
25
|
container-name: bin;
|
|
26
26
|
|
|
27
|
+
line-height: 1;
|
|
28
|
+
|
|
27
29
|
--bg: #aaa;
|
|
28
30
|
--resizer-split: 0.5;
|
|
29
31
|
--margin: 2px;
|
|
@@ -33,6 +35,16 @@
|
|
|
33
35
|
--code-comment: #a3b0d9;
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
.bin--fullscreen {
|
|
39
|
+
--bin-width: 100svw !important;
|
|
40
|
+
--bin-height: 100svh !important;
|
|
41
|
+
position: fixed;
|
|
42
|
+
inset: 0;
|
|
43
|
+
height: 100svh;
|
|
44
|
+
max-height: 100svh;
|
|
45
|
+
z-index: 99;
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
.bin__widget {
|
|
37
49
|
position: absolute;
|
|
38
50
|
width: 100%;
|
|
@@ -102,6 +114,13 @@
|
|
|
102
114
|
margin-inline: 0.5rem;
|
|
103
115
|
}
|
|
104
116
|
|
|
117
|
+
.bin__fullscreen {
|
|
118
|
+
position: absolute;
|
|
119
|
+
bottom: 0.5rem;
|
|
120
|
+
right: 0.5rem;
|
|
121
|
+
padding: 0.25rem;
|
|
122
|
+
}
|
|
123
|
+
|
|
105
124
|
.bin__resizer {
|
|
106
125
|
user-select: none;
|
|
107
126
|
grid-area: resizer;
|