native-document 1.0.139 → 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 +11618 -8748
- 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 +82 -7
- 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,113 @@
|
|
|
1
|
+
|
|
2
|
+
import './has-resizable.css';
|
|
3
|
+
|
|
4
|
+
export default function HasResizable() {}
|
|
5
|
+
|
|
6
|
+
HasResizable.prototype.makeResizable = function(parent, options = {}) {
|
|
7
|
+
if(!this.emit) {
|
|
8
|
+
throw new Error('HasResizable requires HasEventEmitter — add it via BaseComponent.use(Component, HasEventEmitter).');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const directions = options.directions || ['right', 'bottom', 'bottom-right'];
|
|
12
|
+
const sizeConstraint = options.size || { minWidth: 200, minHeight: 200 };
|
|
13
|
+
sizeConstraint.minWidth = sizeConstraint.minWidth || 200;
|
|
14
|
+
sizeConstraint.minHeight = sizeConstraint.minHeight || 200;
|
|
15
|
+
|
|
16
|
+
parent.classList.add('is-resizable');
|
|
17
|
+
|
|
18
|
+
const handles = [];
|
|
19
|
+
|
|
20
|
+
directions.forEach((direction) => {
|
|
21
|
+
const handle = document.createElement('div');
|
|
22
|
+
handle.className = 'resize-handle is-' + direction;
|
|
23
|
+
parent.appendChild(handle);
|
|
24
|
+
handles.push(handle);
|
|
25
|
+
|
|
26
|
+
setupResizeHandle(handle, parent, direction, sizeConstraint, this);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return () => {
|
|
30
|
+
handles.forEach(h => h.remove());
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const setupResizeHandle = (handle, parent, direction, sizeConstraint, instance) => {
|
|
35
|
+
let isResizing = false;
|
|
36
|
+
let startX = 0;
|
|
37
|
+
let startY = 0;
|
|
38
|
+
let startW = 0;
|
|
39
|
+
let startH = 0;
|
|
40
|
+
let startLeft = 0;
|
|
41
|
+
let startTop = 0;
|
|
42
|
+
|
|
43
|
+
const onMouseDown = (e) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
|
|
47
|
+
isResizing = true;
|
|
48
|
+
startX = e.clientX;
|
|
49
|
+
startY = e.clientY;
|
|
50
|
+
startW = parent.offsetWidth;
|
|
51
|
+
startH = parent.offsetHeight;
|
|
52
|
+
startLeft = parent.offsetLeft;
|
|
53
|
+
startTop = parent.offsetTop;
|
|
54
|
+
|
|
55
|
+
document.body.classList.add('is-resizing');
|
|
56
|
+
instance.emit?.('onResizeStart', [e, startW, startH]);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const onMouseMove = (e) => {
|
|
60
|
+
if(!isResizing) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const dx = e.clientX - startX;
|
|
65
|
+
const dy = e.clientY - startY;
|
|
66
|
+
|
|
67
|
+
if(direction === 'right' || direction === 'top-right' || direction === 'bottom-right') {
|
|
68
|
+
const newWidth = Math.max(sizeConstraint.minWidth, startW + dx);
|
|
69
|
+
if(newWidth > sizeConstraint.minWidth && (!sizeConstraint.maxWidth || newWidth <= sizeConstraint.maxWidth)) {
|
|
70
|
+
parent.style.width = newWidth + 'px';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if(direction === 'left' || direction === 'top-left' || direction === 'bottom-left') {
|
|
75
|
+
const newWidth = Math.max(sizeConstraint.minWidth, startW - dx);
|
|
76
|
+
if(newWidth > sizeConstraint.minWidth && (!sizeConstraint.maxWidth || newWidth <= sizeConstraint.maxWidth)) {
|
|
77
|
+
parent.style.width = newWidth + 'px';
|
|
78
|
+
parent.style.left = (startLeft + dx) + 'px';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if(direction === 'bottom' || direction === 'bottom-right' || direction === 'bottom-left') {
|
|
83
|
+
const newHeight = Math.max(sizeConstraint.minHeight, startH + dy);
|
|
84
|
+
if(newHeight > sizeConstraint.minHeight && (!sizeConstraint.maxHeight || newHeight <= sizeConstraint.maxHeight)) {
|
|
85
|
+
parent.style.height = newHeight + 'px';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if(direction === 'top' || direction === 'top-right' || direction === 'top-left') {
|
|
90
|
+
const newHeight = Math.max(sizeConstraint.minHeight, startH - dy);
|
|
91
|
+
if(newHeight > sizeConstraint.minHeight && (!sizeConstraint.maxHeight || newHeight <= sizeConstraint.maxHeight)) {
|
|
92
|
+
parent.style.height = newHeight + 'px';
|
|
93
|
+
parent.style.top = (startTop + dy) + 'px';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
instance.emit?.('onResize', [e, parent.offsetWidth, parent.offsetHeight]);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const onMouseUp = () => {
|
|
101
|
+
if(!isResizing) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
isResizing = false;
|
|
106
|
+
document.body.classList.remove('is-resizing');
|
|
107
|
+
instance.emit?.('onResizeEnd', [parent.offsetWidth, parent.offsetHeight]);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
handle.addEventListener('mousedown', onMouseDown);
|
|
111
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
112
|
+
document.addEventListener('mouseup', onMouseUp);
|
|
113
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--resize-handle-size: 3px;
|
|
3
|
+
--resize-handle-color: var(--gray-lite-3);
|
|
4
|
+
--resize-handle-color-hover: var(--gray-lite-1);
|
|
5
|
+
--resize-notch-size: 6px;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.is-resizable {
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.resize-handle {
|
|
13
|
+
position: absolute;
|
|
14
|
+
z-index: 10;
|
|
15
|
+
|
|
16
|
+
&.is-right {
|
|
17
|
+
top: 0;
|
|
18
|
+
right: 0;
|
|
19
|
+
width: var(--resize-handle-size);
|
|
20
|
+
height: 100%;
|
|
21
|
+
cursor: ew-resize;
|
|
22
|
+
|
|
23
|
+
&:hover {
|
|
24
|
+
background: var(--resize-handle-color-hover);
|
|
25
|
+
opacity: 0.3;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.is-left {
|
|
30
|
+
top: 0;
|
|
31
|
+
left: 0;
|
|
32
|
+
width: var(--resize-handle-size);
|
|
33
|
+
height: 100%;
|
|
34
|
+
cursor: ew-resize;
|
|
35
|
+
|
|
36
|
+
&:hover {
|
|
37
|
+
background: var(--resize-handle-color-hover);
|
|
38
|
+
opacity: 0.3;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&.is-top {
|
|
43
|
+
top: 0;
|
|
44
|
+
left: 0;
|
|
45
|
+
width: 100%;
|
|
46
|
+
height: var(--resize-handle-size);
|
|
47
|
+
cursor: ns-resize;
|
|
48
|
+
|
|
49
|
+
&:hover {
|
|
50
|
+
background: var(--resize-handle-color-hover);
|
|
51
|
+
opacity: 0.3;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&.is-bottom {
|
|
56
|
+
bottom: 0;
|
|
57
|
+
left: 0;
|
|
58
|
+
width: 100%;
|
|
59
|
+
height: var(--resize-handle-size);
|
|
60
|
+
cursor: ns-resize;
|
|
61
|
+
|
|
62
|
+
&:hover {
|
|
63
|
+
background: var(--resize-handle-color-hover);
|
|
64
|
+
opacity: 0.3;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&.is-top-left {
|
|
69
|
+
top: 0;
|
|
70
|
+
left: 0;
|
|
71
|
+
width: var(--resize-notch-size);
|
|
72
|
+
height: var(--resize-notch-size);
|
|
73
|
+
cursor: nwse-resize;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&.is-top-right {
|
|
77
|
+
top: 0;
|
|
78
|
+
right: 0;
|
|
79
|
+
width: var(--resize-notch-size);
|
|
80
|
+
height: var(--resize-notch-size);
|
|
81
|
+
cursor: nesw-resize;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&.is-bottom-left {
|
|
85
|
+
bottom: 0;
|
|
86
|
+
left: 0;
|
|
87
|
+
width: var(--resize-notch-size);
|
|
88
|
+
height: var(--resize-notch-size);
|
|
89
|
+
cursor: nesw-resize;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&.is-bottom-right {
|
|
93
|
+
bottom: 0;
|
|
94
|
+
right: 0;
|
|
95
|
+
width: var(--resize-notch-size);
|
|
96
|
+
height: var(--resize-notch-size);
|
|
97
|
+
cursor: nwse-resize;
|
|
98
|
+
|
|
99
|
+
&::after {
|
|
100
|
+
content: '';
|
|
101
|
+
position: absolute;
|
|
102
|
+
bottom: 3px;
|
|
103
|
+
right: 3px;
|
|
104
|
+
width: 0;
|
|
105
|
+
height: 0;
|
|
106
|
+
border-style: solid;
|
|
107
|
+
border-width: 0 0 var(--resize-notch-size) var(--resize-notch-size);
|
|
108
|
+
border-color: transparent transparent var(--resize-handle-color) transparent;
|
|
109
|
+
transition: border-color 0.15s ease;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
&:hover::after {
|
|
113
|
+
border-color: transparent transparent var(--resize-handle-color-hover) transparent;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
body.is-resizing {
|
|
119
|
+
cursor: nwse-resize;
|
|
120
|
+
user-select: none;
|
|
121
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {resolveParams} from "../../form/utils";
|
|
2
|
+
import BaseComponent from "../../BaseComponent";
|
|
3
|
+
import {Validation} from "../../form/validation/Validation";
|
|
4
|
+
|
|
5
|
+
export default function HasValidation() {}
|
|
6
|
+
|
|
7
|
+
HasValidation.prototype.required = function(message) {
|
|
8
|
+
this.$description.rules.push({
|
|
9
|
+
fn: Validation.required,
|
|
10
|
+
message: message || `${this.$description.label || this.$description.name} is required`
|
|
11
|
+
});
|
|
12
|
+
return this;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
HasValidation.prototype.custom = function(validatorFn, message) {
|
|
16
|
+
this.$description.rules.push({
|
|
17
|
+
validate: validatorFn,
|
|
18
|
+
message: message || 'Validation failed'
|
|
19
|
+
});
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
HasValidation.prototype.addRule = function(validationFn, params, message) {
|
|
24
|
+
this.$description.rules.push({
|
|
25
|
+
fn: validationFn,
|
|
26
|
+
params: params || [],
|
|
27
|
+
message
|
|
28
|
+
});
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
HasValidation.prototype.requiredIf = function(condition, message) {
|
|
33
|
+
return this.addRule(Validation.requiredIf, [condition], message);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
HasValidation.prototype.clearErrorOn = function(event) {
|
|
37
|
+
this.$description.clearErrorOn = event;
|
|
38
|
+
return this;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
HasValidation.prototype.validateOn = function(event) {
|
|
42
|
+
this.$description.validateOn = event;
|
|
43
|
+
return this;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
HasValidation.prototype.showErrors = function(show = true) {
|
|
47
|
+
this.$description.showErrors = BaseComponent.obs(show);
|
|
48
|
+
return this;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
HasValidation.prototype.hideErrors = function() {
|
|
52
|
+
this.$description.showErrors.set(false);
|
|
53
|
+
return this;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
HasValidation.prototype.setError = function(error) {
|
|
57
|
+
this.$description.errors?.set?.(error);
|
|
58
|
+
return this;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
HasValidation.prototype.validate = function(allValues = {}) {
|
|
62
|
+
if(!this.$description.rules || this.$description.rules.length === 0) {
|
|
63
|
+
this.$description.errors.clear();
|
|
64
|
+
this.$description.hasErrors.set(false);
|
|
65
|
+
return {key: this.$description.key, errors: []};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const errors = [];
|
|
69
|
+
const value = this.value();
|
|
70
|
+
|
|
71
|
+
for(const rule of this.$description.rules) {
|
|
72
|
+
const paramsResolved = resolveParams(rule, allValues);
|
|
73
|
+
const validateFn = rule.validate || rule.fn;
|
|
74
|
+
const rawResult = validateFn(value, ...paramsResolved, allValues);
|
|
75
|
+
const result = typeof rawResult === 'boolean' ? {valid: rawResult} : rawResult;
|
|
76
|
+
|
|
77
|
+
if(!result.valid) {
|
|
78
|
+
errors.push(rule.message || result.message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.$description.errors.set(errors);
|
|
83
|
+
this.$description.hasErrors.set(errors.length > 0);
|
|
84
|
+
|
|
85
|
+
return {key: this.$description.key, errors};
|
|
86
|
+
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import {classPropertyAccumulator, cssPropertyAccumulator} from "../../utils";
|
|
2
|
+
import {Observable} from "../../index";
|
|
3
|
+
import {ShowIf} from "../core/elements/index";
|
|
4
|
+
import Anchor from "../core/elements/anchor/anchor";
|
|
5
|
+
import {NDElement} from "../core/wrappers/NDElement";
|
|
6
|
+
|
|
7
|
+
import './base-component.css';
|
|
8
|
+
|
|
2
9
|
|
|
3
10
|
/**
|
|
4
11
|
*
|
|
@@ -7,19 +14,27 @@ import {classPropertyAccumulator, cssPropertyAccumulator} from "../../utils";
|
|
|
7
14
|
export default function BaseComponent() {
|
|
8
15
|
this.$description = {};
|
|
9
16
|
this.$editableProps = null;
|
|
17
|
+
this.$attachements = null;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
20
|
Object.defineProperty( BaseComponent.prototype, 'nd', {
|
|
13
21
|
get: function() {
|
|
14
22
|
if(this.$element) {
|
|
15
|
-
|
|
23
|
+
const nd = this.$element.nd;
|
|
24
|
+
if(this.$attachements) {
|
|
25
|
+
nd.$attachements = this.$attachements;
|
|
26
|
+
}
|
|
27
|
+
return nd;
|
|
16
28
|
}
|
|
17
29
|
this.$storeElement(this.toNdElement());
|
|
18
|
-
|
|
30
|
+
const nd = this.$element.nd;
|
|
31
|
+
if(this.$attachements) {
|
|
32
|
+
nd.$attachements = this.$attachements;
|
|
33
|
+
}
|
|
34
|
+
return nd;
|
|
19
35
|
}
|
|
20
36
|
});
|
|
21
37
|
|
|
22
|
-
|
|
23
38
|
BaseComponent.extends = function(Component, ...parents) {
|
|
24
39
|
const MainParent = parents[0] || BaseComponent;
|
|
25
40
|
Component.prototype = Object.create(MainParent.prototype);
|
|
@@ -44,17 +59,39 @@ BaseComponent.obs = (value) => {
|
|
|
44
59
|
return value.__$Observable ? value : Observable(value);
|
|
45
60
|
};
|
|
46
61
|
|
|
62
|
+
BaseComponent.prototype.setDescription = function(description) {
|
|
63
|
+
for(const key in description) {
|
|
64
|
+
if(this.$description[key]?.__$Observable) {
|
|
65
|
+
this.$description[key].set(description[key]);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
this.$description[key] = description[key];
|
|
69
|
+
}
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
47
73
|
BaseComponent.prototype.$storeElement = function(element) {
|
|
48
74
|
this.$element = element;
|
|
49
75
|
return this;
|
|
50
76
|
};
|
|
51
77
|
|
|
78
|
+
BaseComponent.prototype.postBuild = function(callback) {
|
|
79
|
+
this.$postBuild = this.$postBuild || [];
|
|
80
|
+
this.$postBuild.push(callback);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
BaseComponent.prototype.ghostDom = NDElement.prototype.ghostDom;
|
|
85
|
+
|
|
52
86
|
BaseComponent.prototype.refSelf = function(target, name) {
|
|
53
87
|
target[name] = this;
|
|
54
88
|
return this;
|
|
55
89
|
};
|
|
56
90
|
|
|
57
91
|
BaseComponent.prototype.$build = function() {
|
|
92
|
+
if(this.$beforeRender) {
|
|
93
|
+
this.$beforeRender();
|
|
94
|
+
}
|
|
58
95
|
const ComponentClass = this.constructor;
|
|
59
96
|
const renderer = this.$description.render || ComponentClass.defaultTemplate;
|
|
60
97
|
|
|
@@ -70,9 +107,27 @@ BaseComponent.prototype.toNdElement = function() {
|
|
|
70
107
|
return this.$element;
|
|
71
108
|
}
|
|
72
109
|
this.$element = this.$build();
|
|
110
|
+
if(this.$description.showIf) {
|
|
111
|
+
this.$element = ShowIf(this.$description.showIf, this.$element);
|
|
112
|
+
}
|
|
113
|
+
if(this.$postBuild) {
|
|
114
|
+
for(let i = 0; i < this.$postBuild.length; i++) {
|
|
115
|
+
this.$postBuild[i](this.$element);
|
|
116
|
+
}
|
|
117
|
+
this.$postBuild = null;
|
|
118
|
+
}
|
|
119
|
+
if(this.$attachements) {
|
|
120
|
+
const nd = this.$element.nd;
|
|
121
|
+
nd.ghostDom(this.$attachements);
|
|
122
|
+
this.$attachements = null;
|
|
123
|
+
return nd;
|
|
124
|
+
}
|
|
125
|
+
|
|
73
126
|
return this.$element;
|
|
74
127
|
};
|
|
75
128
|
|
|
129
|
+
BaseComponent.prototype.node = BaseComponent.prototype.toNdElement;
|
|
130
|
+
|
|
76
131
|
BaseComponent.prototype.toJSON = function() {
|
|
77
132
|
if(!this.$description) {
|
|
78
133
|
return {};
|
|
@@ -93,8 +148,8 @@ BaseComponent.prototype.getEditableProps = function() {
|
|
|
93
148
|
const rawProps = this.$description.props || {};
|
|
94
149
|
this.$editableProps = {
|
|
95
150
|
...rawProps,
|
|
96
|
-
class: classPropertyAccumulator(
|
|
97
|
-
style: cssPropertyAccumulator(
|
|
151
|
+
class: classPropertyAccumulator(rawProps.class || {}),
|
|
152
|
+
style: cssPropertyAccumulator(rawProps.style || {})
|
|
98
153
|
};
|
|
99
154
|
}
|
|
100
155
|
|
|
@@ -103,7 +158,7 @@ BaseComponent.prototype.getEditableProps = function() {
|
|
|
103
158
|
|
|
104
159
|
BaseComponent.prototype.resolveProps = function() {
|
|
105
160
|
if(!this.$editableProps) {
|
|
106
|
-
return { ...this.$description.props };
|
|
161
|
+
return this.$description.props ? { ...this.$description.props } : {};
|
|
107
162
|
}
|
|
108
163
|
const props = { ...this.$editableProps };
|
|
109
164
|
if(props.class) {
|
|
@@ -112,5 +167,25 @@ BaseComponent.prototype.resolveProps = function() {
|
|
|
112
167
|
if(props.style) {
|
|
113
168
|
props.style = props.style.value();
|
|
114
169
|
}
|
|
170
|
+
|
|
115
171
|
return props;
|
|
116
|
-
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
BaseComponent.prototype.style = function(style) {
|
|
176
|
+
const props = this.getEditableProps();
|
|
177
|
+
props.style.add(style);
|
|
178
|
+
return this;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
BaseComponent.prototype.showIf = function(condition) {
|
|
182
|
+
this.$description.showIf = BaseComponent.obs(condition);
|
|
183
|
+
return this;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
BaseComponent.prototype.context = function(context) {
|
|
187
|
+
this.$description.$context = context;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
BaseComponent.prototype.visibility = BaseComponent.prototype.showIf;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BaseComponent from "../BaseComponent";
|
|
2
2
|
import HasEventEmitter from "../../core/utils/HasEventEmitter";
|
|
3
|
+
import AccordionItem from "./AccordionItem";
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -13,40 +14,51 @@ import HasEventEmitter from "../../core/utils/HasEventEmitter";
|
|
|
13
14
|
* @returns {Accordion}
|
|
14
15
|
* @class
|
|
15
16
|
*/
|
|
16
|
-
export default function Accordion(
|
|
17
|
+
export default function Accordion(props = {}) {
|
|
17
18
|
if (!(this instanceof Accordion)) {
|
|
18
|
-
return new Accordion(
|
|
19
|
+
return new Accordion(props);
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
BaseComponent.call(this, props);
|
|
23
|
+
|
|
21
24
|
this.$description = {
|
|
22
25
|
items: [],
|
|
23
26
|
multiple: null,
|
|
24
27
|
variant: null,
|
|
25
28
|
renderContent: null,
|
|
26
|
-
|
|
29
|
+
renderIndicator: null,
|
|
30
|
+
props
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
BaseComponent.extends(Accordion
|
|
34
|
+
BaseComponent.extends(Accordion);
|
|
35
|
+
BaseComponent.use(Accordion, HasEventEmitter);
|
|
31
36
|
|
|
32
37
|
Accordion.defaultTemplate = null;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Sets the default template for all Accordion instances
|
|
37
|
-
* @param {{accordion: (accordion: Accordion) => ValidChildren}} template - Template object containing accordion factory function
|
|
38
|
-
*/
|
|
39
38
|
Accordion.use = function(template) {
|
|
40
|
-
Accordion.defaultTemplate = template
|
|
39
|
+
Accordion.defaultTemplate = template;
|
|
41
40
|
};
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
|
|
43
|
+
Accordion.prototype.item = function(title, content, options) {
|
|
44
|
+
let item = null;
|
|
45
|
+
|
|
46
|
+
if(title instanceof AccordionItem) {
|
|
47
|
+
item = title;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const config = typeof options === 'object' ? options : {};
|
|
51
|
+
item = new AccordionItem(config);
|
|
52
|
+
item.title(title);
|
|
53
|
+
item.content(content);
|
|
54
|
+
item.setDescription(config);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if(typeof options === 'function') {
|
|
58
|
+
options(item);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.$description.items.push(item);
|
|
50
62
|
return this;
|
|
51
63
|
};
|
|
52
64
|
|
|
@@ -219,19 +231,13 @@ Accordion.prototype.renderContent = function(renderFn) {
|
|
|
219
231
|
return this;
|
|
220
232
|
};
|
|
221
233
|
|
|
234
|
+
|
|
222
235
|
/**
|
|
223
|
-
*
|
|
224
|
-
* @
|
|
236
|
+
* Sets the indicator render function
|
|
237
|
+
* @param {Function} renderFn - Function to render the indicator
|
|
238
|
+
* @returns {AccordionItem}
|
|
225
239
|
*/
|
|
226
|
-
Accordion.prototype
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// item.onExpand(() => {
|
|
230
|
-
// if (!this.$description.multiple) {
|
|
231
|
-
// this.$description.items
|
|
232
|
-
// .filter(i => i !== item)
|
|
233
|
-
// .forEach(i => i.expanded(false));
|
|
234
|
-
// }
|
|
235
|
-
// });
|
|
236
|
-
// });
|
|
240
|
+
Accordion.prototype.renderIndicator = function(renderFn) {
|
|
241
|
+
this.$description.renderIndicator = renderFn;
|
|
242
|
+
return this;
|
|
237
243
|
};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { $ } from '../../../index';
|
|
2
2
|
import BaseComponent from "../BaseComponent";
|
|
3
|
+
import HasEventEmitter from "../../core/utils/HasEventEmitter";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Represents an individual item within an Accordion component
|
|
6
7
|
* @param {{ id?: string|number, title?: string, icon?: string, collapsible?: boolean, content?: ValidChildren, renderHeader?: Function, renderContent?: Function, render?: Function, expanded?: Observable<boolean>, disabled?: boolean }} config - Configuration object
|
|
7
8
|
* @class
|
|
8
9
|
*/
|
|
9
|
-
export default function AccordionItem(
|
|
10
|
+
export default function AccordionItem(props = {}) {
|
|
10
11
|
if(!(this instanceof AccordionItem)){
|
|
11
12
|
return new AccordionItem()
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
BaseComponent.call(this, props);
|
|
16
|
+
|
|
14
17
|
this.$description = {
|
|
15
18
|
id: null,
|
|
16
19
|
title: null,
|
|
@@ -18,15 +21,22 @@ export default function AccordionItem(config = {}) {
|
|
|
18
21
|
collapsible: true,
|
|
19
22
|
content: null,
|
|
20
23
|
renderHeader: null,
|
|
24
|
+
renderIndicator: null,
|
|
21
25
|
renderContent: null,
|
|
22
26
|
render: null,
|
|
23
27
|
expanded: $(false),
|
|
24
|
-
disabled: false,
|
|
25
|
-
|
|
28
|
+
disabled: $(false),
|
|
29
|
+
props
|
|
26
30
|
};
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
BaseComponent.extends(AccordionItem);
|
|
34
|
+
BaseComponent.use(AccordionItem, HasEventEmitter);
|
|
35
|
+
|
|
36
|
+
AccordionItem.defaultTemplate = null;
|
|
37
|
+
AccordionItem.use = function(template) {
|
|
38
|
+
AccordionItem.defaultTemplate = template;
|
|
39
|
+
};
|
|
30
40
|
|
|
31
41
|
/**
|
|
32
42
|
* Gets the id of the accordion item
|
|
@@ -128,7 +138,7 @@ AccordionItem.prototype.toggle = function() {
|
|
|
128
138
|
* @returns {AccordionItem}
|
|
129
139
|
*/
|
|
130
140
|
AccordionItem.prototype.disabled = function(disabled = true) {
|
|
131
|
-
this.$description.disabled
|
|
141
|
+
this.$description.disabled.set(disabled);
|
|
132
142
|
return this;
|
|
133
143
|
};
|
|
134
144
|
|
|
@@ -189,20 +199,3 @@ AccordionItem.prototype.renderIndicator = function(renderFn) {
|
|
|
189
199
|
return this;
|
|
190
200
|
};
|
|
191
201
|
|
|
192
|
-
/**
|
|
193
|
-
* Sets the render function for the entire item
|
|
194
|
-
* @param {Function} renderFn - Function to render the item
|
|
195
|
-
* @returns {AccordionItem}
|
|
196
|
-
*/
|
|
197
|
-
AccordionItem.prototype.render = function(renderFn) {
|
|
198
|
-
this.$description.render = renderFn;
|
|
199
|
-
return this;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Builds the accordion item component
|
|
204
|
-
* @private
|
|
205
|
-
*/
|
|
206
|
-
AccordionItem.prototype.$build = function() {
|
|
207
|
-
|
|
208
|
-
};
|