@classic-homes/files-svelte 0.5.0 → 0.6.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 +63 -1
- package/dist/lib/FileBranch.svelte +278 -0
- package/dist/lib/FileBranch.svelte.d.ts +39 -0
- package/dist/lib/FileBreadcrumbs.svelte +5 -1
- package/dist/lib/FileBreadcrumbs.svelte.d.ts +2 -0
- package/dist/lib/FileBrowser.svelte +475 -87
- package/dist/lib/FileBrowser.svelte.d.ts +21 -2
- package/dist/lib/FileList.svelte +103 -62
- package/dist/lib/FileList.svelte.d.ts +7 -0
- package/dist/lib/FilePreview.svelte +110 -11
- package/dist/lib/FilePreview.svelte.d.ts +14 -1
- package/dist/lib/FileTree.svelte +13 -18
- package/dist/lib/tree-rows.d.ts +18 -0
- package/dist/lib/tree-rows.js +26 -0
- package/dist/lib/utils.d.ts +13 -0
- package/dist/lib/utils.js +37 -0
- package/package.json +1 -1
package/dist/lib/utils.js
CHANGED
|
@@ -42,3 +42,40 @@ export function isTextInput(target) {
|
|
|
42
42
|
}
|
|
43
43
|
return target.getAttribute('role') === 'combobox' || target.getAttribute('role') === 'textbox';
|
|
44
44
|
}
|
|
45
|
+
/** Names this short are never split: there's little to gain. */
|
|
46
|
+
const SPLIT_MIN_LENGTH = 17;
|
|
47
|
+
/** Longest extension (after the dot) kept whole in the tail. */
|
|
48
|
+
const SPLIT_MAX_EXTENSION = 10;
|
|
49
|
+
/** Characters of the stem kept before the extension. */
|
|
50
|
+
const SPLIT_STEM_KEEP = 6;
|
|
51
|
+
function graphemes(text) {
|
|
52
|
+
const Segmenter = Intl.Segmenter;
|
|
53
|
+
if (Segmenter) {
|
|
54
|
+
return Array.from(new Segmenter(undefined, { granularity: 'grapheme' }).segment(text), (s) => s.segment);
|
|
55
|
+
}
|
|
56
|
+
return Array.from(text); // code points: never splits a surrogate pair
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Split a file name for middle truncation: the head shrinks (ellipsis), the
|
|
60
|
+
* tail always shows. The tail is the extension (from the last dot, unless the
|
|
61
|
+
* dot leads the name or the extension is over 10 characters) plus the 6
|
|
62
|
+
* characters before it, never splitting a character (grapheme). The split moves
|
|
63
|
+
* left off whitespace, so neither part starts or ends with a space and the
|
|
64
|
+
* name renders exactly as one span would. `null` for names of 16 characters or
|
|
65
|
+
* fewer, or when no head would be left.
|
|
66
|
+
*/
|
|
67
|
+
export function splitNameTail(name) {
|
|
68
|
+
if (name.length < SPLIT_MIN_LENGTH)
|
|
69
|
+
return null;
|
|
70
|
+
const dot = name.lastIndexOf('.');
|
|
71
|
+
const extLength = dot > 0 && name.length - dot - 1 <= SPLIT_MAX_EXTENSION ? name.length - dot : 0;
|
|
72
|
+
const parts = graphemes(name.slice(0, name.length - extLength));
|
|
73
|
+
let at = Math.max(0, parts.length - SPLIT_STEM_KEEP);
|
|
74
|
+
const isSpace = (s) => s !== undefined && /^\s+$/u.test(s);
|
|
75
|
+
while (at > 0 && (isSpace(parts[at - 1]) || isSpace(parts[at])))
|
|
76
|
+
at--;
|
|
77
|
+
if (at === 0)
|
|
78
|
+
return null;
|
|
79
|
+
const head = parts.slice(0, at).join('');
|
|
80
|
+
return { head, tail: name.slice(head.length) };
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classic-homes/files-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Svelte network-drive file browser for Classic Theme: FileBrowser plus FileList, FileBreadcrumbs, FileIcon, FilePreview and FileDetails, with previews through the document viewers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/lib/index.js",
|