@neo4j-ndl/react 4.21.2 → 4.22.0
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/lib/cjs/dropzone/stories/dropzone-full.story.js +5 -5
- package/lib/cjs/dropzone/stories/dropzone-full.story.js.map +1 -1
- package/lib/cjs/helpers/index.js +1 -0
- package/lib/cjs/helpers/index.js.map +1 -1
- package/lib/cjs/helpers/platform.js +59 -0
- package/lib/cjs/helpers/platform.js.map +1 -0
- package/lib/cjs/kbd/kbd-utils.js +6 -22
- package/lib/cjs/kbd/kbd-utils.js.map +1 -1
- package/lib/cjs/next/tree-view/TreeView.js +384 -66
- package/lib/cjs/next/tree-view/TreeView.js.map +1 -1
- package/lib/cjs/next/tree-view/selection.js +181 -0
- package/lib/cjs/next/tree-view/selection.js.map +1 -0
- package/lib/cjs/next/tree-view/stories/index.js +13 -1
- package/lib/cjs/next/tree-view/stories/index.js.map +1 -1
- package/lib/cjs/next/tree-view/stories/tree-view-large.story.js +57 -0
- package/lib/cjs/next/tree-view/stories/tree-view-large.story.js.map +1 -0
- package/lib/cjs/next/tree-view/stories/tree-view-lazy.story.js +1 -0
- package/lib/cjs/next/tree-view/stories/tree-view-lazy.story.js.map +1 -1
- package/lib/cjs/next/tree-view/stories/tree-view-multi.story.js +16 -40
- package/lib/cjs/next/tree-view/stories/tree-view-multi.story.js.map +1 -1
- package/lib/cjs/next/tree-view/stories/tree-view-multiple-replace.story.js +38 -0
- package/lib/cjs/next/tree-view/stories/tree-view-multiple-replace.story.js.map +1 -0
- package/lib/cjs/next/tree-view/stories/tree-view-non-selectable-folders.story.js +7 -4
- package/lib/cjs/next/tree-view/stories/tree-view-non-selectable-folders.story.js.map +1 -1
- package/lib/cjs/next/tree-view/stories/tree-view-root-selection.story.js +125 -0
- package/lib/cjs/next/tree-view/stories/tree-view-root-selection.story.js.map +1 -0
- package/lib/cjs/toast/ToastControlled.js +1 -1
- package/lib/cjs/toast/ToastControlled.js.map +1 -1
- package/lib/esm/dropzone/stories/dropzone-full.story.js +5 -5
- package/lib/esm/dropzone/stories/dropzone-full.story.js.map +1 -1
- package/lib/esm/helpers/index.js +1 -0
- package/lib/esm/helpers/index.js.map +1 -1
- package/lib/esm/helpers/platform.js +55 -0
- package/lib/esm/helpers/platform.js.map +1 -0
- package/lib/esm/kbd/kbd-utils.js +2 -18
- package/lib/esm/kbd/kbd-utils.js.map +1 -1
- package/lib/esm/next/tree-view/TreeView.js +385 -67
- package/lib/esm/next/tree-view/TreeView.js.map +1 -1
- package/lib/esm/next/tree-view/selection.js +175 -0
- package/lib/esm/next/tree-view/selection.js.map +1 -0
- package/lib/esm/next/tree-view/stories/index.js +9 -0
- package/lib/esm/next/tree-view/stories/index.js.map +1 -1
- package/lib/esm/next/tree-view/stories/tree-view-large.story.js +55 -0
- package/lib/esm/next/tree-view/stories/tree-view-large.story.js.map +1 -0
- package/lib/esm/next/tree-view/stories/tree-view-lazy.story.js +1 -0
- package/lib/esm/next/tree-view/stories/tree-view-lazy.story.js.map +1 -1
- package/lib/esm/next/tree-view/stories/tree-view-multi.story.js +16 -40
- package/lib/esm/next/tree-view/stories/tree-view-multi.story.js.map +1 -1
- package/lib/esm/next/tree-view/stories/tree-view-multiple-replace.story.js +36 -0
- package/lib/esm/next/tree-view/stories/tree-view-multiple-replace.story.js.map +1 -0
- package/lib/esm/next/tree-view/stories/tree-view-non-selectable-folders.story.js +7 -4
- package/lib/esm/next/tree-view/stories/tree-view-non-selectable-folders.story.js.map +1 -1
- package/lib/esm/next/tree-view/stories/tree-view-root-selection.story.js +123 -0
- package/lib/esm/next/tree-view/stories/tree-view-root-selection.story.js.map +1 -0
- package/lib/esm/toast/ToastControlled.js +1 -1
- package/lib/esm/toast/ToastControlled.js.map +1 -1
- package/lib/types/helpers/index.d.ts +1 -0
- package/lib/types/helpers/index.d.ts.map +1 -1
- package/lib/types/helpers/platform.d.ts +29 -0
- package/lib/types/helpers/platform.d.ts.map +1 -0
- package/lib/types/kbd/kbd-utils.d.ts +2 -5
- package/lib/types/kbd/kbd-utils.d.ts.map +1 -1
- package/lib/types/next/tree-view/TreeView.d.ts +29 -5
- package/lib/types/next/tree-view/TreeView.d.ts.map +1 -1
- package/lib/types/next/tree-view/selection.d.ts +78 -0
- package/lib/types/next/tree-view/selection.d.ts.map +1 -0
- package/lib/types/next/tree-view/stories/index.d.ts +6 -0
- package/lib/types/next/tree-view/stories/index.d.ts.map +1 -1
- package/lib/types/next/tree-view/stories/tree-view-large.story.d.ts +24 -0
- package/lib/types/next/tree-view/stories/tree-view-large.story.d.ts.map +1 -0
- package/lib/types/next/tree-view/stories/tree-view-lazy.story.d.ts.map +1 -1
- package/lib/types/next/tree-view/stories/tree-view-multi.story.d.ts +10 -0
- package/lib/types/next/tree-view/stories/tree-view-multi.story.d.ts.map +1 -1
- package/lib/types/next/tree-view/stories/tree-view-multiple-replace.story.d.ts +29 -0
- package/lib/types/next/tree-view/stories/tree-view-multiple-replace.story.d.ts.map +1 -0
- package/lib/types/next/tree-view/stories/tree-view-non-selectable-folders.story.d.ts +5 -0
- package/lib/types/next/tree-view/stories/tree-view-non-selectable-folders.story.d.ts.map +1 -1
- package/lib/types/next/tree-view/stories/tree-view-root-selection.story.d.ts +24 -0
- package/lib/types/next/tree-view/stories/tree-view-root-selection.story.d.ts.map +1 -0
- package/package.json +2 -2
- package/skills/ndl-react/SKILL.md +1 -1
- package/skills/ndl-react/components/next/tree-view.md +358 -104
package/lib/esm/helpers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,YAAY,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport * from './debounce';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport * from './debounce';\nexport * from './platform';\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Neo4j.
|
|
7
|
+
*
|
|
8
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* `navigator.platform` comes first because it describes the machine the
|
|
23
|
+
* keyboard is attached to, while the user agent and its client hints can be
|
|
24
|
+
* pinned to another platform by the embedder.
|
|
25
|
+
*/
|
|
26
|
+
function getPlatformHint() {
|
|
27
|
+
var _a;
|
|
28
|
+
if (typeof navigator === 'undefined') {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
const navigatorWithHints = navigator;
|
|
32
|
+
return (navigator.platform ||
|
|
33
|
+
((_a = navigatorWithHints.userAgentData) === null || _a === void 0 ? void 0 : _a.platform) ||
|
|
34
|
+
navigator.userAgent ||
|
|
35
|
+
'');
|
|
36
|
+
}
|
|
37
|
+
/** Detects the operating system the keyboard is attached to. */
|
|
38
|
+
export function detectOS() {
|
|
39
|
+
const platform = getPlatformHint();
|
|
40
|
+
if (/mac|iphone|ipad|ipod/i.test(platform)) {
|
|
41
|
+
return 'mac';
|
|
42
|
+
}
|
|
43
|
+
if (/win/i.test(platform)) {
|
|
44
|
+
return 'windows';
|
|
45
|
+
}
|
|
46
|
+
return 'linux';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Apple platforms take `Cmd` where the rest take `Ctrl`, since `Ctrl` + click
|
|
50
|
+
* is the macOS context menu gesture.
|
|
51
|
+
*/
|
|
52
|
+
export function isApplePlatform() {
|
|
53
|
+
return detectOS() === 'mac';
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../../src/helpers/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH;;;;GAIG;AACH,SAAS,eAAe;;IACtB,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE,CAAC;QACrC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,kBAAkB,GAAG,SAE1B,CAAC;IACF,OAAO,CACL,SAAS,CAAC,QAAQ;SAClB,MAAA,kBAAkB,CAAC,aAAa,0CAAE,QAAQ,CAAA;QAC1C,SAAS,CAAC,SAAS;QACnB,EAAE,CACH,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,QAAQ;IACtB,MAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;IACnC,IAAI,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,QAAQ,EAAE,KAAK,KAAK,CAAC;AAC9B,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport type OperatingSystem = 'mac' | 'windows' | 'linux';\n\n/**\n * `navigator.platform` comes first because it describes the machine the\n * keyboard is attached to, while the user agent and its client hints can be\n * pinned to another platform by the embedder.\n */\nfunction getPlatformHint(): string {\n if (typeof navigator === 'undefined') {\n return '';\n }\n const navigatorWithHints = navigator as Navigator & {\n userAgentData?: { platform?: string };\n };\n return (\n navigator.platform ||\n navigatorWithHints.userAgentData?.platform ||\n navigator.userAgent ||\n ''\n );\n}\n\n/** Detects the operating system the keyboard is attached to. */\nexport function detectOS(): OperatingSystem {\n const platform = getPlatformHint();\n if (/mac|iphone|ipad|ipod/i.test(platform)) {\n return 'mac';\n }\n if (/win/i.test(platform)) {\n return 'windows';\n }\n return 'linux';\n}\n\n/**\n * Apple platforms take `Cmd` where the rest take `Ctrl`, since `Ctrl` + click\n * is the macOS context menu gesture.\n */\nexport function isApplePlatform(): boolean {\n return detectOS() === 'mac';\n}\n"]}
|
package/lib/esm/kbd/kbd-utils.js
CHANGED
|
@@ -19,24 +19,8 @@
|
|
|
19
19
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
export function detectOS() {
|
|
26
|
-
if (typeof window === 'undefined') {
|
|
27
|
-
return 'linux';
|
|
28
|
-
}
|
|
29
|
-
const userAgent = window.navigator.userAgent.toLowerCase();
|
|
30
|
-
if (userAgent.includes('mac')) {
|
|
31
|
-
return 'mac';
|
|
32
|
-
}
|
|
33
|
-
else if (userAgent.includes('win')) {
|
|
34
|
-
return 'windows';
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return 'linux';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
22
|
+
import { detectOS } from '../helpers/platform';
|
|
23
|
+
export { detectOS };
|
|
40
24
|
/**
|
|
41
25
|
* Returns OS-aware keyboard key symbols
|
|
42
26
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kbd-utils.js","sourceRoot":"","sources":["../../../src/kbd/kbd-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kbd-utils.js","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AG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1E,MAAM,SAAS,GAAG,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;SAC3B,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;SAC1C,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;SAAM,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACzC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport type { ReactNode } from 'react';\n\nimport { detectOS, type OperatingSystem } from '../helpers/platform';\n\nexport { detectOS, type OperatingSystem };\n\nexport type KbdKey =\n | 'meta'\n | 'shift'\n | 'ctrl'\n | 'enter'\n | 'delete'\n | 'escape'\n | 'tab'\n | 'capslock'\n | 'up'\n | 'right'\n | 'down'\n | 'left'\n | 'pageup'\n | 'pagedown'\n | 'home'\n | 'end'\n | 'space'\n | 'fn'\n | 'alt';\n\n/**\n * Returns OS-aware keyboard key symbols\n */\nexport function getKbdKeysMap(\n os: OperatingSystem = detectOS(),\n): Record<KbdKey, string> {\n const baseMap: Record<KbdKey, string> = {\n alt: os === 'mac' ? '⌥' : 'alt',\n capslock: '⇪',\n ctrl: os === 'mac' ? '⌃' : 'ctrl',\n delete: os === 'mac' ? '⌫' : 'delete',\n down: '↓',\n end: 'end',\n enter: '↵',\n escape: '⎋',\n fn: 'Fn',\n home: 'home',\n left: '←',\n meta: os === 'mac' ? '⌘' : os === 'windows' ? '⊞' : 'meta',\n pagedown: '⇟',\n pageup: '⇞',\n right: '→',\n shift: '⇧',\n space: '␣',\n tab: '⇥',\n up: '↑',\n };\n\n return baseMap;\n}\n\n/**\n * Returns OS-aware keyboard key labels\n */\nexport function getKbdKeysLabelMap(\n os: OperatingSystem = detectOS(),\n): Record<KbdKey, string> {\n return {\n alt: 'Alt',\n capslock: 'Caps Lock',\n ctrl: 'Control',\n delete: 'Delete',\n down: 'Down',\n end: 'End',\n enter: 'Enter',\n escape: 'Escape',\n fn: 'Fn',\n home: 'Home',\n left: 'Left',\n meta: os === 'mac' ? 'Command' : os === 'windows' ? 'Windows' : 'Meta',\n pagedown: 'Page Down',\n pageup: 'Page Up',\n right: 'Right',\n shift: 'Shift',\n space: 'Space',\n tab: 'Tab',\n up: 'Up',\n };\n}\n\nfunction resolveKeyLabel(\n key: KbdKey | ReactNode,\n labels: Record<KbdKey, string>,\n): string {\n if (key === null || key === undefined || typeof key === 'boolean') {\n return '';\n }\n if (typeof key === 'string') {\n return key in labels ? labels[key as KbdKey] : key;\n }\n if (typeof key === 'number') {\n return String(key);\n }\n return '';\n}\n\nexport function getKbdScreenReaderFriendlyText(\n keys: readonly (KbdKey | ReactNode)[] | undefined,\n modifierKeys: readonly KbdKey[] | undefined,\n os: OperatingSystem = detectOS(),\n): string {\n const labels = getKbdKeysLabelMap(os);\n const modStr = (modifierKeys ?? []).map((key) => labels[key]).join(' + ');\n const keyLabels = (keys ?? [])\n .map((key) => resolveKeyLabel(key, labels))\n .filter(Boolean);\n let keyStr = '';\n if (keyLabels.length === 1) {\n keyStr = keyLabels[0];\n } else if (keyLabels.length > 1) {\n keyStr = keyLabels.join(' then ');\n }\n const body = [modStr, keyStr].filter(Boolean).join(' + ');\n return body ? `Shortcut: ${body}` : '';\n}\n"]}
|