native-document 1.0.138 → 1.0.140
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/components.js +1 -1
- package/devtools/ComponentRegistry.js +3 -2
- package/dist/native-document.components.min.css +1 -0
- package/dist/native-document.components.min.js +11506 -8566
- package/dist/native-document.dev.js +2645 -2166
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/index.js +1 -0
- package/package.json +5 -2
- package/rollup.config.js +5 -2
- package/src/components/$traits/has-draggable/HasDraggable.js +69 -0
- package/src/components/$traits/has-draggable/has-draggable.css +8 -0
- package/src/components/$traits/{HasItems.js → has-items/HasItems.js} +2 -11
- package/src/components/$traits/has-position/HasFullPosition.js +51 -0
- package/src/components/$traits/has-position/HasPosition.js +23 -0
- package/src/components/$traits/has-resizable/HasResizable.js +113 -0
- package/src/components/$traits/has-resizable/has-resizable.css +121 -0
- package/src/components/$traits/has-validation/HasValidation.js +86 -0
- package/src/components/BaseComponent.js +109 -4
- package/src/components/accordion/Accordion.js +37 -31
- package/src/components/accordion/AccordionItem.js +14 -21
- package/src/components/alert/Alert.js +48 -40
- package/src/components/avatar/Avatar.js +4 -3
- package/src/components/avatar/AvatarGroup.js +8 -2
- package/src/components/badge/Badge.js +7 -7
- package/src/components/base-component.css +0 -0
- package/src/components/breadcrumb/BreadCrumb.js +30 -21
- package/src/components/button/Button.js +3 -14
- package/src/components/context-menu/ContextMenu.js +49 -26
- package/src/components/dropdown/Dropdown.js +172 -34
- package/src/components/dropdown/DropdownDivider.js +4 -3
- package/src/components/dropdown/DropdownGroup.js +19 -19
- package/src/components/dropdown/DropdownItem.js +24 -18
- package/src/components/dropdown/helpers.js +52 -0
- package/src/components/form/FormControl.js +207 -108
- package/src/components/form/field/Field.js +106 -174
- package/src/components/form/field/FieldCollection.js +110 -203
- package/src/components/form/field/types/AutocompleteField.js +26 -5
- package/src/components/form/field/types/CheckboxField.js +4 -4
- package/src/components/form/field/types/CheckboxGroupField.js +11 -5
- package/src/components/form/field/types/ColorField.js +4 -4
- package/src/components/form/field/types/DateField.js +110 -18
- package/src/components/form/field/types/EmailField.js +2 -2
- package/src/components/form/field/types/FileField.js +87 -21
- package/src/components/form/field/types/HiddenField.js +4 -4
- package/src/components/form/field/types/ImageField.js +4 -4
- package/src/components/form/field/types/NumberField.js +5 -5
- package/src/components/form/field/types/PasswordField.js +28 -6
- package/src/components/form/field/types/RadioField.js +12 -8
- package/src/components/form/field/types/RangeField.js +29 -5
- package/src/components/form/field/types/SearchField.js +4 -4
- package/src/components/form/field/types/SelectField.js +75 -8
- package/src/components/form/field/types/StringField.js +4 -4
- package/src/components/form/field/types/TelField.js +4 -4
- package/src/components/form/field/types/TextAreaField.js +7 -5
- package/src/components/form/field/types/TimeField.js +52 -6
- package/src/components/form/field/types/UrlField.js +4 -5
- package/src/components/form/field/types/file-field-mode/FileAvatarMode.js +104 -0
- package/src/components/form/field/types/file-field-mode/FileDropzoneMode.js +59 -0
- package/src/components/form/field/types/file-field-mode/FileItemPreview.js +74 -0
- package/src/components/form/field/types/file-field-mode/FileNativeMode.js +21 -0
- package/src/components/form/field/types/file-field-mode/FileUploadButtonMode.js +59 -0
- package/src/components/form/field/types/file-field-mode/FileWallMode.js +53 -0
- package/src/components/form/index.js +14 -2
- package/src/components/form/validation/Validation.js +9 -0
- package/src/components/list/List.js +1 -1
- package/src/components/list/ListGroup.js +1 -1
- package/src/components/menu/HasMenuItem.js +133 -0
- package/src/components/menu/Menu.js +47 -56
- package/src/components/menu/MenuGroup.js +36 -8
- package/src/components/menu/MenuItem.js +24 -10
- package/src/components/menu/MenuLink.js +2 -0
- package/src/components/modal/Modal.js +153 -23
- package/src/components/pagination/Pagination.js +55 -21
- package/src/components/popover/Popover.js +127 -40
- package/src/components/progress/Progress.js +14 -24
- package/src/components/skeleton/Skeleton.js +36 -13
- package/src/components/slider/Slider.js +96 -70
- package/src/components/spinner/Spinner.js +4 -2
- package/src/components/splitter/Splitter.js +15 -8
- package/src/components/splitter/SplitterGutter.js +28 -7
- package/src/components/splitter/SplitterPanel.js +9 -15
- package/src/components/splitter/index.js +3 -1
- package/src/components/stacks/AbsoluteStack.js +33 -0
- package/src/components/stacks/FixedStack.js +33 -0
- package/src/components/stacks/PositionStack.js +146 -0
- package/src/components/stacks/RelativeStack.js +33 -0
- package/src/components/{layouts → stacks}/Stack.js +22 -3
- package/src/components/{layouts → stacks}/index.js +6 -4
- package/src/components/stepper/Stepper.js +159 -67
- package/src/components/stepper/StepperStep.js +49 -12
- package/src/components/switch/Switch.js +59 -29
- package/src/components/switch/index.js +6 -0
- package/src/components/table/Column.js +22 -26
- package/src/components/table/ColumnGroup.js +4 -13
- package/src/components/table/DataTable.js +388 -103
- package/src/components/table/SimpleTable.js +28 -143
- package/src/components/tabs/Tabs.js +142 -44
- package/src/components/toast/Toast.js +40 -35
- package/src/components/tooltip/Tooltip.js +152 -35
- package/src/core/data/ObservableArray.js +94 -30
- package/src/core/data/ObservableChecker.js +20 -75
- package/src/core/data/ObservableItem.js +35 -3
- package/src/core/data/observable-helpers/computed.js +2 -1
- package/src/core/data/observable-helpers/object.js +13 -8
- package/src/core/data/observable-helpers/observable.is-to.js +196 -0
- package/src/core/elements/anchor/anchor.js +3 -2
- package/src/core/elements/control/for-each-array.js +44 -30
- package/src/core/elements/control/for-each.js +6 -3
- package/src/core/elements/control/show-if.js +11 -6
- package/src/core/elements/control/switch.js +2 -1
- package/src/core/elements/index.js +1 -1
- package/src/core/elements/svg.js +61 -0
- package/src/core/utils/HasEventEmitter.js +6 -0
- package/src/core/utils/debug-manager.js +2 -5
- package/src/core/utils/filters/standard.js +2 -1
- package/src/core/utils/property-accumulator.js +35 -6
- package/src/core/utils/shortcut-manager.js +242 -0
- package/src/core/utils/validator.js +1 -1
- package/src/core/wrappers/AttributesWrapper.js +41 -4
- package/src/core/wrappers/DocumentObserver.js +0 -1
- package/src/core/wrappers/HtmlElementWrapper.js +1 -1
- package/src/core/wrappers/NDElement.js +15 -2
- package/src/core/wrappers/SvgElementWrapper.js +15 -0
- package/src/core/wrappers/prototypes/attributes-extensions.js +4 -1
- package/src/core/wrappers/prototypes/nd-element-extensions.js +8 -1
- package/src/router/Router.js +0 -1
- package/src/ui/components/accordion/AccordionItemRender.js +63 -0
- package/src/ui/components/accordion/AccordionRender.js +34 -0
- package/src/ui/components/accordion/accordion.css +121 -0
- package/src/ui/components/alert/AlertRender.js +80 -0
- package/src/ui/components/alert/alert.css +163 -0
- package/src/ui/components/avatar/avata-group/AvatarGroupRender.js +49 -0
- package/src/ui/components/avatar/avata-group/avatar-group.css +38 -0
- package/src/ui/components/avatar/avatar/AvatarRender.js +87 -0
- package/src/ui/components/avatar/avatar/avatar.css +189 -0
- package/src/ui/components/badge/BadgeRender.js +24 -0
- package/src/ui/components/badge/badge.css +168 -0
- package/src/ui/components/breadcrumb/BreadcrumbRender.js +43 -0
- package/src/ui/components/breadcrumb/breadcrumb.css +55 -0
- package/src/ui/components/button/ButtonRender.js +65 -0
- package/src/ui/components/button/button.css +288 -354
- package/src/ui/components/contextmenu/ContextmenuRender.js +70 -0
- package/src/ui/components/contextmenu/contextmenu.css +36 -0
- package/src/ui/components/divider/DividerRender.js +70 -0
- package/src/ui/components/divider/divider.css +70 -0
- package/src/ui/components/dropdown/DropdownRender.js +92 -0
- package/src/ui/components/dropdown/divider/DropdownDividerRender.js +9 -0
- package/src/ui/components/dropdown/divider/dropdown-divider.css +0 -0
- package/src/ui/components/dropdown/dropdown.css +179 -0
- package/src/ui/components/dropdown/group/DropdownGroupRender.js +23 -0
- package/src/ui/components/dropdown/group/dropdown-group.css +0 -0
- package/src/ui/components/dropdown/item/DropdownItemRender.js +29 -0
- package/src/ui/components/dropdown/item/dropdown-item.css +0 -0
- package/src/ui/components/form/FieldCollectionRender.js +110 -0
- package/src/ui/components/form/FormControlRender.js +84 -0
- package/src/ui/components/form/field-collection.css +55 -0
- package/src/ui/components/form/fields/AutocompleteFieldRender.js +143 -0
- package/src/ui/components/form/fields/CheckboxFieldRender.js +59 -0
- package/src/ui/components/form/fields/CheckboxGroupFieldRender.js +92 -0
- package/src/ui/components/form/fields/ColorFieldRender.js +30 -0
- package/src/ui/components/form/fields/DateFieldRender.js +154 -0
- package/src/ui/components/form/fields/EmailFieldRender.js +5 -0
- package/src/ui/components/form/fields/FieldRender.js +117 -0
- package/src/ui/components/form/fields/FileFieldRender.js +41 -0
- package/src/ui/components/form/fields/HiddenFieldRender.js +14 -0
- package/src/ui/components/form/fields/ImageFieldRender.js +0 -0
- package/src/ui/components/form/fields/NumberFieldRender.js +52 -0
- package/src/ui/components/form/fields/PasswordFieldRender.js +65 -0
- package/src/ui/components/form/fields/RadioFieldRender.js +77 -0
- package/src/ui/components/form/fields/RangeFieldRender.js +121 -0
- package/src/ui/components/form/fields/SelectFieldRender.js +248 -0
- package/src/ui/components/form/fields/SliderFieldRender.js +359 -0
- package/src/ui/components/form/fields/StringFieldRender.js +6 -0
- package/src/ui/components/form/fields/TelFieldRender.js +6 -0
- package/src/ui/components/form/fields/TextAreaFieldRender.js +96 -0
- package/src/ui/components/form/fields/TimeFieldRender.js +141 -0
- package/src/ui/components/form/fields/UrlFieldRender.js +6 -0
- package/src/ui/components/form/fields/date-field.css +32 -0
- package/src/ui/components/form/fields/field.css +402 -0
- package/src/ui/components/form/fields/file-field.css +79 -0
- package/src/ui/components/form/fields/password-field.css +50 -0
- package/src/ui/components/form/fields/range-field.css +120 -0
- package/src/ui/components/form/fields/slider.css +195 -0
- package/src/ui/components/form/file-upload-mode/FileAvatarModeRender.js +143 -0
- package/src/ui/components/form/file-upload-mode/FileDropzoneModeRender.js +108 -0
- package/src/ui/components/form/file-upload-mode/FileNativeModeRender.js +22 -0
- package/src/ui/components/form/file-upload-mode/FileUploadButtonModeRender.js +89 -0
- package/src/ui/components/form/file-upload-mode/FileWallModeRender.js +91 -0
- package/src/ui/components/form/file-upload-mode/file-avatar-mode.css +139 -0
- package/src/ui/components/form/file-upload-mode/file-dropzone-mode.css +88 -0
- package/src/ui/components/form/file-upload-mode/file-upload-button-mode.css +44 -0
- package/src/ui/components/form/file-upload-mode/file-wall-mode.css +88 -0
- package/src/ui/components/form/form-control.css +40 -0
- package/src/ui/components/form/helpers.js +112 -0
- package/src/ui/components/form/index.js +61 -0
- package/src/ui/components/menu/MenuDividerRender.js +12 -0
- package/src/ui/components/menu/MenuGroupRender.js +60 -0
- package/src/ui/components/menu/MenuItemRender.js +57 -0
- package/src/ui/components/menu/MenuLinkRender.js +55 -0
- package/src/ui/components/menu/MenuRender.js +21 -0
- package/src/ui/components/menu/helpers.js +121 -0
- package/src/ui/components/menu/menu.css +308 -0
- package/src/ui/components/modal/ModalRender.js +119 -0
- package/src/ui/components/modal/modal.css +156 -0
- package/src/ui/components/pagination/PaginationRender.js +112 -0
- package/src/ui/components/pagination/pagination.css +63 -0
- package/src/ui/components/popover/PopoverRender.js +234 -0
- package/src/ui/components/popover/popover.css +139 -0
- package/src/ui/components/progress/ProgressRender.js +168 -0
- package/src/ui/components/progress/progress.css +197 -0
- package/src/ui/components/skeleton/SkeletonRender.js +79 -0
- package/src/ui/components/skeleton/skeleton.css +154 -0
- package/src/ui/components/spinner/SpinnerRender.js +46 -0
- package/src/ui/components/spinner/spinner.css +152 -0
- package/src/ui/components/splitter/SplitterGutterRender.js +94 -0
- package/src/ui/components/splitter/SplitterPanelRender.js +38 -0
- package/src/ui/components/splitter/SplitterRender.js +74 -0
- package/src/ui/components/splitter/splitter.css +128 -0
- package/src/ui/components/stacks/PositionStackRender.js +38 -0
- package/src/ui/components/stacks/StackRender.js +42 -0
- package/src/ui/components/stacks/absolute-stack/AbsoluteStackRender.js +5 -0
- package/src/ui/components/stacks/fixed-stack/FixedStackRender.js +5 -0
- package/src/ui/components/stacks/h-stack/HStackRender.js +7 -0
- package/src/ui/components/stacks/h-stack/h-stack.css +4 -0
- package/src/ui/components/stacks/index.js +15 -0
- package/src/ui/components/stacks/position-stack.css +62 -0
- package/src/ui/components/stacks/relative-stack/RelativeStackRender.js +7 -0
- package/src/ui/components/stacks/relative-stack/relative-stack.css +3 -0
- package/src/ui/components/stacks/stack.css +78 -0
- package/src/ui/components/stacks/v-stack/VStackRender.js +5 -0
- package/src/ui/components/stacks/v-stack/v-stack.css +4 -0
- package/src/ui/components/stepper/StepperRender.js +70 -0
- package/src/ui/components/stepper/StepperStepRender.js +67 -0
- package/src/ui/components/stepper/stepper.css +359 -0
- package/src/ui/components/switch/SwitchRender.js +82 -0
- package/src/ui/components/switch/switch.css +143 -0
- package/src/ui/components/table/data-table/DataTableRender.js +49 -0
- package/src/ui/components/table/data-table/bulk-actions.js +35 -0
- package/src/ui/components/table/data-table/data-table.css +246 -0
- package/src/ui/components/table/data-table/pagination.js +56 -0
- package/src/ui/components/table/data-table/tables.js +363 -0
- package/src/ui/components/table/data-table/toolbar.js +67 -0
- package/src/ui/components/table/simple-table/SimpleTableRender.js +188 -0
- package/src/ui/components/table/simple-table/simple-table.css +50 -0
- package/src/ui/components/tabs/TabsRender.js +226 -0
- package/src/ui/components/tabs/tabs.css +253 -0
- package/src/ui/components/toast/ToastRender.js +98 -0
- package/src/ui/components/toast/toast.css +201 -0
- package/src/ui/components/tooltip/TooltipRender.js +8 -0
- package/src/ui/components/tooltip/tooltip.css +113 -0
- package/src/ui/index.js +82 -0
- package/src/ui/tokens/colors-dark.scss +2 -1
- package/src/ui/tokens/reset.scss +3 -0
- package/types/control-flow.d.ts +2 -2
- package/src/components/layouts/ZStack.js +0 -41
- package/src/ui/components/button/button.render.js +0 -63
- /package/src/components/{layouts → stacks}/HStack.js +0 -0
- /package/src/components/{layouts → stacks}/VStack.js +0 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import DebugManager from '../../core/utils/debug-manager';
|
|
2
|
+
|
|
3
|
+
const isMac = navigator.platform.toUpperCase().includes('MAC')
|
|
4
|
+
|| navigator.userAgent.includes('Mac');
|
|
5
|
+
|
|
6
|
+
const MAC_SYMBOLS = {
|
|
7
|
+
meta: '⌘',
|
|
8
|
+
shift: '⇧',
|
|
9
|
+
alt: '⌥',
|
|
10
|
+
ctrl: '⌃',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const WIN_LABELS = {
|
|
14
|
+
meta: 'Ctrl',
|
|
15
|
+
shift: 'Shift',
|
|
16
|
+
alt: 'Alt',
|
|
17
|
+
ctrl: 'Ctrl',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parse a shortcut string into a normalized object.
|
|
22
|
+
* Supports:
|
|
23
|
+
* Short convention : '+S', '++S', '+Shift+S'
|
|
24
|
+
* Standard : 'Ctrl+S', 'Cmd+S', 'Ctrl+Alt+S'
|
|
25
|
+
*/
|
|
26
|
+
const parse = (shortcut) => {
|
|
27
|
+
if(!shortcut) return null;
|
|
28
|
+
|
|
29
|
+
const result = { meta: false, shift: false, alt: false, ctrl: false, key: '' };
|
|
30
|
+
|
|
31
|
+
// Short convention — starts with '+'
|
|
32
|
+
if(shortcut.startsWith('+')) {
|
|
33
|
+
result.meta = true;
|
|
34
|
+
|
|
35
|
+
let rest = shortcut.slice(1);
|
|
36
|
+
|
|
37
|
+
// '++S' → alt
|
|
38
|
+
if(rest.startsWith('+')) {
|
|
39
|
+
result.alt = true;
|
|
40
|
+
rest = rest.slice(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const parts = rest.split('+').filter(Boolean);
|
|
44
|
+
|
|
45
|
+
for(const part of parts) {
|
|
46
|
+
const upper = part.toUpperCase();
|
|
47
|
+
if(upper === 'SHIFT') result.shift = true;
|
|
48
|
+
else if(upper === 'ALT') result.alt = true;
|
|
49
|
+
else if(upper === 'CTRL') result.ctrl = true;
|
|
50
|
+
else result.key = part.toUpperCase();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Standard convention — 'Ctrl+S', 'Cmd+Shift+S'
|
|
57
|
+
const parts = shortcut.split('+').filter(Boolean);
|
|
58
|
+
|
|
59
|
+
for(const part of parts) {
|
|
60
|
+
const upper = part.toUpperCase();
|
|
61
|
+
if(upper === 'CTRL' || upper === 'CMD' || upper === 'META') result.meta = true;
|
|
62
|
+
else if(upper === 'SHIFT') result.shift = true;
|
|
63
|
+
else if(upper === 'ALT' || upper === 'OPTION') result.alt = true;
|
|
64
|
+
else result.key = part.toUpperCase();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Normalize a parsed shortcut to a canonical key string
|
|
72
|
+
* used for storage and comparison.
|
|
73
|
+
*/
|
|
74
|
+
const normalize = (parsed) => {
|
|
75
|
+
const parts = [];
|
|
76
|
+
if(parsed.meta) parts.push('meta');
|
|
77
|
+
if(parsed.ctrl) parts.push('ctrl');
|
|
78
|
+
if(parsed.shift) parts.push('shift');
|
|
79
|
+
if(parsed.alt) parts.push('alt');
|
|
80
|
+
parts.push(parsed.key.toLowerCase());
|
|
81
|
+
return parts.join('+');
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const displayOnMac = (shortcut) => {
|
|
85
|
+
const parsed = parse(shortcut);
|
|
86
|
+
if(!parsed) return '';
|
|
87
|
+
|
|
88
|
+
const parts = [];
|
|
89
|
+
|
|
90
|
+
if(parsed.meta) {
|
|
91
|
+
parts.push(MAC_SYMBOLS.meta);
|
|
92
|
+
}
|
|
93
|
+
if(parsed.ctrl) {
|
|
94
|
+
parts.push(MAC_SYMBOLS.ctrl);
|
|
95
|
+
}
|
|
96
|
+
if(parsed.shift) {
|
|
97
|
+
parts.push(MAC_SYMBOLS.shift);
|
|
98
|
+
}
|
|
99
|
+
if(parsed.alt) {
|
|
100
|
+
parts.push(MAC_SYMBOLS.alt);
|
|
101
|
+
}
|
|
102
|
+
parts.push(parsed.key);
|
|
103
|
+
|
|
104
|
+
return parts.join(' ');
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const displayOnWindows = (shortcut) => {
|
|
108
|
+
const parsed = parse(shortcut);
|
|
109
|
+
if(!parsed) return '';
|
|
110
|
+
|
|
111
|
+
const parts = [];
|
|
112
|
+
if(parsed.meta || parsed.ctrl) {
|
|
113
|
+
parts.push(WIN_LABELS.meta);
|
|
114
|
+
}
|
|
115
|
+
if(parsed.shift) {
|
|
116
|
+
parts.push(WIN_LABELS.shift);
|
|
117
|
+
}
|
|
118
|
+
if(parsed.alt) {
|
|
119
|
+
parts.push(WIN_LABELS.alt);
|
|
120
|
+
}
|
|
121
|
+
parts.push(parsed.key);
|
|
122
|
+
|
|
123
|
+
return parts.join('+');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Display a shortcut string for the current OS.
|
|
128
|
+
*/
|
|
129
|
+
const display = isMac ? displayOnMac : displayOnWindows;
|
|
130
|
+
|
|
131
|
+
const $registry = new Map();
|
|
132
|
+
const $handlers = new Map();
|
|
133
|
+
|
|
134
|
+
const ShortcutManager = {
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Register a shortcut.
|
|
138
|
+
* @param {string} shortcut
|
|
139
|
+
* @param {Function} handler
|
|
140
|
+
* @param {{ context?: string, force?: boolean, source?: string }} options
|
|
141
|
+
*/
|
|
142
|
+
register(shortcut, handler, options = {}) {
|
|
143
|
+
const parsed = parse(shortcut);
|
|
144
|
+
if(!parsed || !parsed.key) {
|
|
145
|
+
DebugManager.warn(`ShortcutManager: invalid shortcut "${shortcut}"`);
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const key = normalize(parsed);
|
|
150
|
+
const context = options.context || 'global';
|
|
151
|
+
const source = options.source || 'unknown';
|
|
152
|
+
const mapKey = context + ':' + key;
|
|
153
|
+
|
|
154
|
+
if($registry.has(mapKey) && !options.force) {
|
|
155
|
+
const existing = $registry.get(mapKey);
|
|
156
|
+
DebugManager.warn(
|
|
157
|
+
`ShortcutManager: "${shortcut}" is already registered by "${existing.source}" in context "${context}". Use { force: true } to override.`
|
|
158
|
+
);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
$registry.set(mapKey, {handler, source, context, parsed});
|
|
163
|
+
return this;
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Unregister a shortcut.
|
|
168
|
+
*/
|
|
169
|
+
unregister(shortcut, context = 'global') {
|
|
170
|
+
const parsed = parse(shortcut);
|
|
171
|
+
if(!parsed) return this;
|
|
172
|
+
|
|
173
|
+
const key = normalize(parsed);
|
|
174
|
+
const mapKey = context + ':' + key;
|
|
175
|
+
|
|
176
|
+
$registry.delete(mapKey);
|
|
177
|
+
return this;
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Display a shortcut for the current OS.
|
|
182
|
+
*/
|
|
183
|
+
display,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Parse a shortcut string.
|
|
187
|
+
*/
|
|
188
|
+
parse,
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Check if a shortcut is registered.
|
|
192
|
+
*/
|
|
193
|
+
has(shortcut, context = 'global') {
|
|
194
|
+
const parsed = parse(shortcut);
|
|
195
|
+
if(!parsed) return false;
|
|
196
|
+
return $registry.has(context + ':' + normalize(parsed));
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Initialize the global keyboard listener.
|
|
201
|
+
*/
|
|
202
|
+
init() {
|
|
203
|
+
if(this.$initialized) {
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this.$initialized = true;
|
|
208
|
+
|
|
209
|
+
document.addEventListener('keydown', (e) => {
|
|
210
|
+
const key = e.key.toUpperCase();
|
|
211
|
+
|
|
212
|
+
const parts = [];
|
|
213
|
+
if(e.metaKey || e.ctrlKey) parts.push('meta');
|
|
214
|
+
if(e.ctrlKey && !e.metaKey) parts.push('ctrl');
|
|
215
|
+
if(e.shiftKey) parts.push('shift');
|
|
216
|
+
if(e.altKey) parts.push('alt');
|
|
217
|
+
parts.push(key.toLowerCase());
|
|
218
|
+
parts.push(key.toLowerCase());
|
|
219
|
+
|
|
220
|
+
const normalizedKey = parts.join('+');
|
|
221
|
+
|
|
222
|
+
const globalKey = 'global:' + normalizedKey;
|
|
223
|
+
if($registry.has(globalKey)) {
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
$registry.get(globalKey).handler(e);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for(const [mapKey, entry] of $registry.entries()) {
|
|
230
|
+
if(mapKey.endsWith(':' + normalizedKey) && entry.context !== 'global') {
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
entry.handler(e);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
return this;
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export default ShortcutManager;
|
|
@@ -19,7 +19,7 @@ VALID_TYPES[COMMON_NODE_TYPES.COMMENT] = true;
|
|
|
19
19
|
|
|
20
20
|
const Validator = {
|
|
21
21
|
isObservable(value) {
|
|
22
|
-
return value
|
|
22
|
+
return value && (value.__$isObservable || value.__$Observable);
|
|
23
23
|
},
|
|
24
24
|
isTemplateBinding(value) {
|
|
25
25
|
return value?.__$isTemplateBinding;
|
|
@@ -12,6 +12,18 @@ export const bindClassAttribute = (element, data) => {
|
|
|
12
12
|
for(const className in data) {
|
|
13
13
|
const value = data[className];
|
|
14
14
|
if(value.__$Observable) {
|
|
15
|
+
if(value.__$isObservableChecker) {
|
|
16
|
+
let lastClass = value.val();
|
|
17
|
+
if(typeof lastClass === "string") {
|
|
18
|
+
element.classes.toggle(lastClass, true);
|
|
19
|
+
value.subscribe((currentValue) => {
|
|
20
|
+
element.classes.remove(lastClass);
|
|
21
|
+
element.classes.toggle(currentValue, true);
|
|
22
|
+
lastClass = currentValue;
|
|
23
|
+
});
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
element.classes.toggle(className, value.val());
|
|
16
28
|
value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
17
29
|
continue;
|
|
@@ -32,14 +44,39 @@ export const bindClassAttribute = (element, data) => {
|
|
|
32
44
|
export const bindStyleAttribute = (element, data) => {
|
|
33
45
|
for(const styleName in data) {
|
|
34
46
|
const value = data[styleName];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
const isCustomProperty = styleName.startsWith('--');
|
|
48
|
+
|
|
49
|
+
if(value.__$Observable) {
|
|
50
|
+
if(isCustomProperty) {
|
|
51
|
+
element.style.setProperty(styleName, value.val());
|
|
52
|
+
value.subscribe((newValue) => {
|
|
53
|
+
if(newValue === false) {
|
|
54
|
+
element.style.removeProperty(styleName);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
element.style.setProperty(styleName, newValue)
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
element.style[styleName] = value.val();
|
|
61
|
+
value.subscribe((newValue) => {
|
|
62
|
+
if(newValue === false) {
|
|
63
|
+
element.style.removeProperty(styleName);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
element.style[styleName] = newValue
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if(isCustomProperty) {
|
|
73
|
+
element.style.setProperty(styleName, value);
|
|
38
74
|
continue;
|
|
39
75
|
}
|
|
76
|
+
|
|
40
77
|
element.style[styleName] = value;
|
|
41
78
|
}
|
|
42
|
-
}
|
|
79
|
+
};
|
|
43
80
|
|
|
44
81
|
/**
|
|
45
82
|
*
|
|
@@ -62,7 +62,6 @@ const DocumentObserver = {
|
|
|
62
62
|
},
|
|
63
63
|
|
|
64
64
|
checkMutation: function(mutationsList) {
|
|
65
|
-
console.log('mutationsList', mutationsList);
|
|
66
65
|
for(const mutation of mutationsList) {
|
|
67
66
|
if(DocumentObserver.mountedSupposedSize > 0) {
|
|
68
67
|
for(const node of mutation.addedNodes) {
|
|
@@ -17,7 +17,7 @@ export const createTextNode = (value) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
const createHtmlElement = (element, _attributes, _children = null) => {
|
|
20
|
+
export const createHtmlElement = (element, _attributes, _children = null) => {
|
|
21
21
|
let { props: attributes, children = null } = normalizeComponentArgs(_attributes, _children);
|
|
22
22
|
|
|
23
23
|
ElementCreator.processAttributes(element, attributes);
|
|
@@ -2,9 +2,12 @@ import DocumentObserver from "./DocumentObserver";
|
|
|
2
2
|
import PluginsManager from "../utils/plugins-manager";
|
|
3
3
|
import NativeDocumentError from "../errors/NativeDocumentError.js";
|
|
4
4
|
import DebugManager from "../utils/debug-manager.js";
|
|
5
|
+
import Anchor from "../elements/anchor/anchor";
|
|
6
|
+
import {ElementCreator} from "./ElementCreator";
|
|
5
7
|
|
|
6
8
|
export function NDElement(element) {
|
|
7
9
|
this.$element = element;
|
|
10
|
+
this.$attachements = null;
|
|
8
11
|
if(process.env.NODE_ENV === 'development') {
|
|
9
12
|
PluginsManager.emit('NDElementCreated', element, this);
|
|
10
13
|
}
|
|
@@ -12,6 +15,14 @@ export function NDElement(element) {
|
|
|
12
15
|
|
|
13
16
|
NDElement.prototype.__$isNDElement = true;
|
|
14
17
|
|
|
18
|
+
NDElement.prototype.ghostDom = function(element) {
|
|
19
|
+
if(!this.$attachements) {
|
|
20
|
+
this.$attachements = document.createDocumentFragment();
|
|
21
|
+
}
|
|
22
|
+
this.$attachements.appendChild(ElementCreator.getChild(element));
|
|
23
|
+
return this;
|
|
24
|
+
};
|
|
25
|
+
|
|
15
26
|
NDElement.prototype.valueOf = function() {
|
|
16
27
|
return this.$element;
|
|
17
28
|
};
|
|
@@ -22,7 +33,9 @@ NDElement.prototype.ref = function(target, name) {
|
|
|
22
33
|
};
|
|
23
34
|
|
|
24
35
|
NDElement.prototype.refSelf = function(target, name) {
|
|
25
|
-
target[name] =
|
|
36
|
+
target[name] = this;
|
|
37
|
+
// TODO: @DIM to check
|
|
38
|
+
// target[name] = new NDElement(this.$element);
|
|
26
39
|
return this;
|
|
27
40
|
};
|
|
28
41
|
|
|
@@ -166,7 +179,7 @@ NDElement.prototype.with = function(methods) {
|
|
|
166
179
|
const method = methods[name];
|
|
167
180
|
|
|
168
181
|
if (typeof method !== 'function') {
|
|
169
|
-
|
|
182
|
+
DebugManager.warn(`⚠️ extends(): "${name}" is not a function, skipping`);
|
|
170
183
|
continue;
|
|
171
184
|
}
|
|
172
185
|
if(process.env.NODE_ENV === 'development') {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {createHtmlElement} from "./HtmlElementWrapper";
|
|
2
|
+
|
|
3
|
+
export default function SvgElementWrapper(name) {
|
|
4
|
+
let node = null;
|
|
5
|
+
|
|
6
|
+
let createElement = (attr, children) => {
|
|
7
|
+
node = document.createElementNS('http://www.w3.org/2000/svg', name);
|
|
8
|
+
createElement = (attr, children) => {
|
|
9
|
+
return createHtmlElement(node.cloneNode(), attr, children);
|
|
10
|
+
};
|
|
11
|
+
return createHtmlElement(node.cloneNode(), attr, children);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return (attr, children) => createElement(attr, children);
|
|
15
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import ObservableItem from "../../data/ObservableItem";
|
|
6
6
|
import TemplateBinding from "../TemplateBinding";
|
|
7
7
|
import {BOOLEAN_ATTRIBUTES} from "../constants";
|
|
8
|
+
import ObservableChecker from "../../data/ObservableChecker";
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
@@ -16,6 +17,8 @@ ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
|
16
17
|
bindAttributeWithObservable(element, attributeName, this);
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
|
|
21
|
+
|
|
22
|
+
TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
|
|
20
23
|
this.$hydrate(element, attributeName);
|
|
21
24
|
};
|
|
@@ -36,7 +36,14 @@ ObservableItem.prototype.toNdElement = function () {
|
|
|
36
36
|
ObservableChecker.prototype.toNdElement = ObservableItem.prototype.toNdElement;
|
|
37
37
|
|
|
38
38
|
NDElement.prototype.toNdElement = function () {
|
|
39
|
-
|
|
39
|
+
const element = this.$element ?? this.$build?.() ?? this.build?.() ?? null;
|
|
40
|
+
if(this.$attachements) {
|
|
41
|
+
if(!this.$attachements.contains(this.$element)) {
|
|
42
|
+
this.$attachements.append(this.$element);
|
|
43
|
+
}
|
|
44
|
+
return this.$attachements;
|
|
45
|
+
}
|
|
46
|
+
return element;
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
Array.prototype.toNdElement = function () {
|
package/src/router/Router.js
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {Div, Span, ShowIf} from '../../../core/elements';
|
|
2
|
+
|
|
3
|
+
export default function AccordionItemRender($desc, instance) {
|
|
4
|
+
const props = instance.getEditableProps();
|
|
5
|
+
|
|
6
|
+
props.class.add('accordion-item');
|
|
7
|
+
props.class.add({'is-disabled': $desc.disabled});
|
|
8
|
+
|
|
9
|
+
const header = buildHeader($desc, instance);
|
|
10
|
+
const content = buildContent($desc, instance);
|
|
11
|
+
|
|
12
|
+
return Div(instance.resolveProps(), [header, content]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const buildHeader = ($desc, instance) => {
|
|
16
|
+
if($desc.renderHeader) {
|
|
17
|
+
return $desc.renderHeader($desc, instance);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const indicatorClass = $desc.expanded.transform(
|
|
21
|
+
(expanded) => 'accordion-indicator' + (expanded ? ' is-expanded' : '')
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const content = [
|
|
25
|
+
Span({class: 'accordion-header-icon'}, $desc.icon),
|
|
26
|
+
Span({class: 'accordion-header-title'}, $desc.title),
|
|
27
|
+
buildIndicator($desc),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const header = Div({class: 'accordion-header'}, content);
|
|
31
|
+
|
|
32
|
+
if(!$desc.disabled?.val()) {
|
|
33
|
+
header.nd.onClick(() => {
|
|
34
|
+
if($desc.collapsible || !$desc.expanded.val()) {
|
|
35
|
+
instance.toggle();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return header;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const buildIndicator = ($desc) => {
|
|
44
|
+
if($desc.renderIndicator) {
|
|
45
|
+
return $desc.renderIndicator($desc.expanded);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return Span({
|
|
49
|
+
class: $desc.expanded.transform((expanded) => 'accordion-indicator' + (expanded ? ' is-expanded' : '')),
|
|
50
|
+
}, '▾');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const buildContent = ($desc, instance) => {
|
|
54
|
+
if($desc.renderContent) {
|
|
55
|
+
return ShowIf($desc.expanded, () =>
|
|
56
|
+
Div({class: 'accordion-content'}, $desc.renderContent($desc, instance))
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return ShowIf($desc.expanded, () =>
|
|
61
|
+
Div({class: 'accordion-content'}, $desc.content)
|
|
62
|
+
);
|
|
63
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {Div, ForEachArray} from '../../../core/elements';
|
|
2
|
+
import './accordion.css';
|
|
3
|
+
|
|
4
|
+
export default function AccordionRender($desc, instance) {
|
|
5
|
+
const props = instance.getEditableProps();
|
|
6
|
+
|
|
7
|
+
props.class.add('accordion');
|
|
8
|
+
|
|
9
|
+
if($desc.variant) {
|
|
10
|
+
props.class.add('is-' + $desc.variant);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const addItem = (item) => {
|
|
14
|
+
if($desc.renderIndicator && !item.$description.renderIndicator) {
|
|
15
|
+
item.renderIndicator($desc.renderIndicator);
|
|
16
|
+
}
|
|
17
|
+
item.onCollapse(() => instance.emit('collapse', item));
|
|
18
|
+
item.onExpand(() => {
|
|
19
|
+
instance.emit('expand', item);
|
|
20
|
+
if($desc.multiple) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
$desc.items.forEach((other) => {
|
|
24
|
+
if(other !== item && other.isExpanded()) {
|
|
25
|
+
other.expanded(false);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return item;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return Div(instance.resolveProps(), ForEachArray($desc.items, addItem));
|
|
34
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--accordion-border: var(--gray-lite-3);
|
|
3
|
+
--accordion-radius: var(--radius-card);
|
|
4
|
+
--accordion-font-size: var(--description-size);
|
|
5
|
+
--accordion-header-padding: var(--space-comfortable);
|
|
6
|
+
--accordion-content-padding: var(--space-comfortable);
|
|
7
|
+
--accordion-header-color: var(--text-color);
|
|
8
|
+
--accordion-header-color-hover: var(--text-color);
|
|
9
|
+
--accordion-header-bg-hover: var(--gray-lite-5);
|
|
10
|
+
--accordion-indicator-color: var(--gray);
|
|
11
|
+
--accordion-transition: 0.2s ease;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.accordion {
|
|
15
|
+
width: 100%;
|
|
16
|
+
font-size: var(--accordion-font-size);
|
|
17
|
+
|
|
18
|
+
&.is-bordered {
|
|
19
|
+
border: 1px solid var(--accordion-border);
|
|
20
|
+
border-radius: var(--accordion-radius);
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
|
|
23
|
+
.accordion-item {
|
|
24
|
+
border-bottom: 1px solid var(--accordion-border);
|
|
25
|
+
|
|
26
|
+
&:last-child {
|
|
27
|
+
border-bottom: none;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&.is-separated {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
gap: var(--space-cozy);
|
|
36
|
+
|
|
37
|
+
.accordion-item {
|
|
38
|
+
border: 1px solid var(--accordion-border);
|
|
39
|
+
border-radius: var(--accordion-radius);
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.is-flush {
|
|
45
|
+
.accordion-item {
|
|
46
|
+
border-bottom: 1px solid var(--accordion-border);
|
|
47
|
+
|
|
48
|
+
&:last-child {
|
|
49
|
+
border-bottom: none;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.accordion-header {
|
|
54
|
+
padding-left: 0;
|
|
55
|
+
padding-right: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.accordion-content {
|
|
59
|
+
padding-left: 0;
|
|
60
|
+
padding-right: 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.accordion-item {
|
|
66
|
+
&.is-disabled {
|
|
67
|
+
opacity: 0.5;
|
|
68
|
+
pointer-events: none;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.accordion-header {
|
|
73
|
+
display: flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
gap: var(--space-cozy);
|
|
76
|
+
padding: var(--accordion-header-padding);
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
color: var(--accordion-header-color);
|
|
79
|
+
user-select: none;
|
|
80
|
+
transition: background var(--accordion-transition);
|
|
81
|
+
|
|
82
|
+
&:hover {
|
|
83
|
+
background: var(--accordion-header-bg-hover);
|
|
84
|
+
color: var(--accordion-header-color-hover);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.accordion-header-icon {
|
|
89
|
+
display: inline-flex;
|
|
90
|
+
align-items: center;
|
|
91
|
+
width: 16px;
|
|
92
|
+
height: 16px;
|
|
93
|
+
flex-shrink: 0;
|
|
94
|
+
|
|
95
|
+
&:empty {
|
|
96
|
+
display: none;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.accordion-header-title {
|
|
101
|
+
flex: 1;
|
|
102
|
+
font-weight: 500;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.accordion-indicator {
|
|
106
|
+
display: inline-flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
color: var(--accordion-indicator-color);
|
|
109
|
+
transition: transform var(--accordion-transition);
|
|
110
|
+
flex-shrink: 0;
|
|
111
|
+
|
|
112
|
+
&.is-expanded {
|
|
113
|
+
transform: rotate(180deg);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.accordion-content {
|
|
118
|
+
padding: var(--accordion-content-padding);
|
|
119
|
+
border-top: 1px solid var(--accordion-border);
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
}
|