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,112 @@
|
|
|
1
|
+
import {ForEachArray, ShowIf, Div, Span, Img} from "../../../../elements";
|
|
2
|
+
import {clear} from "@babel/traverse/lib/cache";
|
|
3
|
+
|
|
4
|
+
export const buildErrors = ($desc) => {
|
|
5
|
+
return ShowIf($desc.showErrors, () =>
|
|
6
|
+
ShowIf($desc.hasErrors,
|
|
7
|
+
() => Div({class: 'field-errors', ...($desc.elementsProps.error || {})},
|
|
8
|
+
ForEachArray($desc.errors, (error) =>
|
|
9
|
+
Span({class: 'field-error'}, error)
|
|
10
|
+
)
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export const formatSize = (bytes) => {
|
|
18
|
+
if(bytes < 1024) return bytes + ' B';
|
|
19
|
+
if(bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
|
20
|
+
return (bytes / 1024 / 1024).toFixed(1) + ' MB';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export const getFileThumbnail = (file, fieldInstance) => {
|
|
25
|
+
const isImage = file.type?.startsWith('image/');
|
|
26
|
+
const url = URL.createObjectURL(file);
|
|
27
|
+
if(isImage) {
|
|
28
|
+
return Img(url, {
|
|
29
|
+
class: 'file-item-img',
|
|
30
|
+
alt: file.name,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fieldDesc = fieldInstance.$description;
|
|
35
|
+
if(fieldDesc.fileIcons) {
|
|
36
|
+
for(let i = 0; i < fieldDesc.fileIcons.length; i++) {
|
|
37
|
+
const iconDesc = fieldDesc.fileIcons[i];
|
|
38
|
+
if(iconDesc.pattern && iconDesc.pattern.test(file.type)) {
|
|
39
|
+
return Span({class: 'file-item-icon'}, iconDesc.icon);
|
|
40
|
+
}
|
|
41
|
+
if(iconDesc.type && iconDesc.type === file.type) {
|
|
42
|
+
return Span({class: 'file-item-icon'}, iconDesc.icon);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return Span({ class: 'file-item-icon file-item-icon-default' });
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const buildProgress = (item) => {
|
|
51
|
+
const $status = item.$description.status;
|
|
52
|
+
const $progress = item.$description.progress;
|
|
53
|
+
|
|
54
|
+
return ShowIf($status.is(s => s === 'uploading'),
|
|
55
|
+
() => Div({class: 'file-item-progress'}, [
|
|
56
|
+
Div({class: 'file-item-progress-track'},
|
|
57
|
+
Div({
|
|
58
|
+
class: 'file-item-progress-bar',
|
|
59
|
+
style: {width: $progress.transform(v => v + '%')},
|
|
60
|
+
})
|
|
61
|
+
),
|
|
62
|
+
Span({class: 'file-item-progress-label'}, $progress.transform(v => v + '%')),
|
|
63
|
+
])
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const buildInputWithSlots = (input, $desc, instance, options = {}) => {
|
|
68
|
+
const clearable = options.clearable || $desc.clearable;
|
|
69
|
+
const $value = $desc[options.source || 'value'];
|
|
70
|
+
const onClear = options.onClear;
|
|
71
|
+
const slots = $desc.slots || {};
|
|
72
|
+
if(clearable && $value?.__$Observable) {
|
|
73
|
+
const clearBtn = Span({class: 'field-clear'}, $desc.clearButtonIcon || '×');
|
|
74
|
+
clearBtn.nd.onStopClick((e) => {
|
|
75
|
+
$value.set(null);
|
|
76
|
+
onClear?.(e);
|
|
77
|
+
});
|
|
78
|
+
instance.trailing(ShowIf($value, clearBtn));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const content = [];
|
|
82
|
+
|
|
83
|
+
if(slots.leading) {
|
|
84
|
+
content.push(Div({class: 'field-leading'}, slots.leading));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
content.push(input);
|
|
88
|
+
|
|
89
|
+
if(slots.trailing) {
|
|
90
|
+
content.push(Div({class: 'field-trailing'}, slots.trailing));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const wrapperClass = {
|
|
94
|
+
'field-input-wrapper': true,
|
|
95
|
+
'has-leading': !!slots.leading,
|
|
96
|
+
'has-trailing': !!slots.trailing,
|
|
97
|
+
'is-touched': $desc.isTouched,
|
|
98
|
+
'is-dirty': $desc.isDirty,
|
|
99
|
+
...(options.class || {})
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
input.nd.onInput((e) => {
|
|
103
|
+
const current = e.target.value;
|
|
104
|
+
$desc.isDirty.set(current !== $desc.initialValue);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
input.nd.onBlur(() => {
|
|
108
|
+
$desc.isTouched.set(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return Div({class: wrapperClass}, content);
|
|
112
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import FieldRender from "./fields/FieldRender";
|
|
2
|
+
import StringFieldRender from "./fields/StringFieldRender";
|
|
3
|
+
import TelFieldRender from "./fields/TelFieldRender";
|
|
4
|
+
import UrlFieldRender from "./fields/UrlFieldRender";
|
|
5
|
+
import EmailFieldRender from "./fields/EmailFieldRender";
|
|
6
|
+
import PasswordFieldRender from "./fields/PasswordFieldRender";
|
|
7
|
+
import NumberFieldRender from "./fields/NumberFieldRender";
|
|
8
|
+
import TextAreaFieldRender from "./fields/TextAreaFieldRender";
|
|
9
|
+
import CheckboxFieldRender from "./fields/CheckboxFieldRender";
|
|
10
|
+
import CheckboxGroupFieldRender from "./fields/CheckboxGroupFieldRender";
|
|
11
|
+
import RadioFieldRender from "./fields/RadioFieldRender";
|
|
12
|
+
import SelectFieldRender from "./fields/SelectFieldRender";
|
|
13
|
+
import AutocompleteFieldRender from "./fields/AutocompleteFieldRender";
|
|
14
|
+
import HiddenFieldRender from "./fields/HiddenFieldRender";
|
|
15
|
+
import ColorFieldRender from "./fields/ColorFieldRender";
|
|
16
|
+
import FileFieldRender from "./fields/FileFieldRender";
|
|
17
|
+
import FileNativeModeRender from "./file-upload-mode/FileNativeModeRender";
|
|
18
|
+
import FileDropzoneModeRender from "./file-upload-mode/FileDropzoneModeRender";
|
|
19
|
+
import FileWallModeRender from "./file-upload-mode/FileWallModeRender";
|
|
20
|
+
import FileUploadButtonModeRender from "./file-upload-mode/FileUploadButtonModeRender";
|
|
21
|
+
import FileAvatarModeRender from "./file-upload-mode/FileAvatarModeRender";
|
|
22
|
+
import DateFieldRender from "./fields/DateFieldRender";
|
|
23
|
+
import TimeFieldRender from "./fields/TimeFieldRender";
|
|
24
|
+
import SliderFieldRender from "./fields/SliderFieldRender";
|
|
25
|
+
import RangeFieldRender from "./fields/RangeFieldRender";
|
|
26
|
+
import FieldCollectionRender from "./FieldCollectionRender";
|
|
27
|
+
import FormControlRender from "./FormControlRender";
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
FieldRender,
|
|
33
|
+
StringFieldRender,
|
|
34
|
+
TelFieldRender,
|
|
35
|
+
UrlFieldRender,
|
|
36
|
+
EmailFieldRender,
|
|
37
|
+
PasswordFieldRender,
|
|
38
|
+
NumberFieldRender,
|
|
39
|
+
TextAreaFieldRender,
|
|
40
|
+
CheckboxFieldRender,
|
|
41
|
+
CheckboxGroupFieldRender,
|
|
42
|
+
RadioFieldRender,
|
|
43
|
+
SelectFieldRender,
|
|
44
|
+
AutocompleteFieldRender,
|
|
45
|
+
HiddenFieldRender,
|
|
46
|
+
ColorFieldRender,
|
|
47
|
+
FileFieldRender,
|
|
48
|
+
|
|
49
|
+
FileNativeModeRender,
|
|
50
|
+
FileAvatarModeRender,
|
|
51
|
+
FileDropzoneModeRender,
|
|
52
|
+
FileUploadButtonModeRender,
|
|
53
|
+
FileWallModeRender,
|
|
54
|
+
|
|
55
|
+
DateFieldRender,
|
|
56
|
+
TimeFieldRender,
|
|
57
|
+
RangeFieldRender,
|
|
58
|
+
SliderFieldRender,
|
|
59
|
+
FieldCollectionRender,
|
|
60
|
+
FormControlRender,
|
|
61
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Div, ListItem} from '../../../core/elements';
|
|
2
|
+
|
|
3
|
+
export default function MenuDividerRender($desc, instance) {
|
|
4
|
+
if($desc.render) {
|
|
5
|
+
return $desc.render($desc, instance);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const props = instance.getEditableProps();
|
|
9
|
+
props.class.add('menu-divider');
|
|
10
|
+
|
|
11
|
+
return ListItem(Div( { ...instance.resolveProps(), role: "separator" }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {Div, Span, ForEachArray, ShowIf, Switch} from '../../../core/elements';
|
|
2
|
+
import {MenuDivider} from "../../../components/menu";
|
|
3
|
+
|
|
4
|
+
export default function MenuGroupRender($desc, instance) {
|
|
5
|
+
if($desc.render) {
|
|
6
|
+
return $desc.render($desc, instance);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const props = instance.getEditableProps();
|
|
10
|
+
if($desc.collapsable) {
|
|
11
|
+
props.class.add('is-collapsable');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const content = [];
|
|
15
|
+
|
|
16
|
+
if($desc.label || $desc.icon) {
|
|
17
|
+
content.push(buildGroupHeader($desc, instance));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const items = Div({class: 'menu-group-items'}, ForEachArray($desc.items));
|
|
21
|
+
|
|
22
|
+
if($desc.collapsable && $desc.collapsed) {
|
|
23
|
+
content.push(ShowIf($desc.collapsed, () => items));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
content.push(items);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return Div(instance.resolveProps(), content);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const buildGroupHeader = ($desc, instance) => {
|
|
33
|
+
const content = [];
|
|
34
|
+
|
|
35
|
+
if($desc.icon) {
|
|
36
|
+
content.push(Span({class: 'menu-group-icon'}, $desc.icon));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if($desc.label) {
|
|
40
|
+
content.push(Span({class: 'menu-group-label'}, $desc.label));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if($desc.collapsable) {
|
|
44
|
+
const closedIcon = $desc.collapsableOpenedIcon || '▾';
|
|
45
|
+
const openedIcon = $desc.collapsableClosedIcon || '';
|
|
46
|
+
content.push(
|
|
47
|
+
Span({ class: $desc.collapsed?.transform(c => 'menu-group-chevron' + (c ? '' : ' is-open')), },
|
|
48
|
+
Switch($desc.collapsed, openedIcon, closedIcon)
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const header = Div({class: 'menu-group-header'}, content);
|
|
54
|
+
|
|
55
|
+
if($desc.collapsable && $desc.collapsed) {
|
|
56
|
+
header.nd.onStopClick(() => $desc.collapsed.toggle());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return header;
|
|
60
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {Div, ListItem, Span } from '../../../core/elements';
|
|
2
|
+
import ShortcutManager from '../../../core/utils/shortcut-manager';
|
|
3
|
+
import { $ } from '../../../../index'
|
|
4
|
+
import {buildSubmenu, setupInteraction} from "./helpers";
|
|
5
|
+
|
|
6
|
+
export default function MenuItemRender($desc, instance) {
|
|
7
|
+
if($desc.render) {
|
|
8
|
+
return $desc.render($desc, instance);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const props = instance.getEditableProps();
|
|
12
|
+
|
|
13
|
+
props.class.add('menu-item');
|
|
14
|
+
if($desc.disabled) {
|
|
15
|
+
props.class.add('is-disabled', $desc.disabled);
|
|
16
|
+
}
|
|
17
|
+
if($desc.selected) {
|
|
18
|
+
props.class.add('is-selected', $desc.selected);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const orientation = instance.$parent?.$description?.orientation || 'horizontal';
|
|
22
|
+
const interaction = $desc.interaction || instance.$parent?.$description?.interaction || 'hover';
|
|
23
|
+
const hasSubmenu = $desc.items?.length;
|
|
24
|
+
|
|
25
|
+
if(hasSubmenu) {
|
|
26
|
+
props.class.add('has-submenu');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const content = [
|
|
30
|
+
Span({class: 'menu-item-icon'}, $desc.icon),
|
|
31
|
+
Span({class: 'menu-item-label'}, $desc.label),
|
|
32
|
+
Span({class: 'menu-item-shortcut'}, ShortcutManager.display($desc.shortcut)),
|
|
33
|
+
Span({class: 'menu-group-chevron'}, hasSubmenu ? '›' : ''),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
if($desc.trailing) {
|
|
37
|
+
content.push(Span({class: 'menu-item-trailing'}, $desc.trailing));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const el = Div({class: 'menu-item-wrapper'}, content);
|
|
41
|
+
|
|
42
|
+
el.nd.onClick(() => {
|
|
43
|
+
if($desc.disabled?.val()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
$desc.action?.($desc.dataResolver?.());
|
|
47
|
+
instance.emit('click', instance);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const $isOpen = $(false);
|
|
51
|
+
const submenuEl = buildSubmenu($desc, orientation, $isOpen, instance);
|
|
52
|
+
const listItem = ListItem(instance.resolveProps(), [el, submenuEl]);
|
|
53
|
+
|
|
54
|
+
setupInteraction(listItem, el, submenuEl, orientation, interaction, $isOpen, hasSubmenu, instance);
|
|
55
|
+
|
|
56
|
+
return listItem;
|
|
57
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {Link, ListItem, Span} from "../../../core/elements";
|
|
2
|
+
import { Link as RouterLink } from '../../../../router';
|
|
3
|
+
import ShortcutManager from "../../../core/utils/shortcut-manager";
|
|
4
|
+
import { $ } from '../../../../index';
|
|
5
|
+
import {buildSubmenu, setupInteraction} from "./helpers";
|
|
6
|
+
|
|
7
|
+
export default function MenuLinkRender($desc, instance) {
|
|
8
|
+
if($desc.render) {
|
|
9
|
+
return $desc.render($desc, instance);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const props = instance.getEditableProps();
|
|
13
|
+
|
|
14
|
+
props.class.add('menu-item');
|
|
15
|
+
props.class.add({ 'is-disabled': $desc.disabled, 'is-selected': $desc.selected });
|
|
16
|
+
|
|
17
|
+
const orientation = instance.$parent?.$description?.orientation || 'horizontal';
|
|
18
|
+
const interaction = $desc.interaction || instance.$parent?.$description?.interaction || 'hover';
|
|
19
|
+
const hasSubmenu = $desc.items?.length;
|
|
20
|
+
const action = $desc.action;
|
|
21
|
+
const isRoute = action?.isRoute;
|
|
22
|
+
const targetPath = typeof action === 'string' ? action : action?.to || '#';
|
|
23
|
+
const target = $desc.target || null;
|
|
24
|
+
|
|
25
|
+
if(hasSubmenu) {
|
|
26
|
+
props.class.add('has-submenu');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const content = [
|
|
30
|
+
Span({class: 'menu-item-icon'}, $desc.icon || null),
|
|
31
|
+
Span({class: 'menu-item-label'}, $desc.label),
|
|
32
|
+
Span({class: 'menu-item-shortcut'}, ShortcutManager.display($desc.shortcut)),
|
|
33
|
+
Span({class: 'menu-group-chevron'}, hasSubmenu ? '›' : ''),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
if($desc.trailing) {
|
|
37
|
+
content.push(Span({class: 'menu-item-trailing'}, $desc.trailing));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const el = isRoute
|
|
41
|
+
? RouterLink({class: 'menu-item-wrapper', to: targetPath, target}, content)
|
|
42
|
+
: Link({class: 'menu-item-wrapper', href: targetPath, target}, content);
|
|
43
|
+
|
|
44
|
+
if(!hasSubmenu) {
|
|
45
|
+
return ListItem(instance.resolveProps(), el);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const $isOpen = $(false);
|
|
49
|
+
const submenuEl = buildSubmenu($desc, orientation, $isOpen, instance);
|
|
50
|
+
const listItem = ListItem(instance.resolveProps(), [el, submenuEl]);
|
|
51
|
+
|
|
52
|
+
setupInteraction(listItem, el, submenuEl, orientation, interaction, $isOpen, hasSubmenu, instance);
|
|
53
|
+
|
|
54
|
+
return listItem;
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Nav, ForEachArray} from '../../../core/elements';
|
|
2
|
+
import './menu.css';
|
|
3
|
+
|
|
4
|
+
export default function MenuRender($desc, instance) {
|
|
5
|
+
const props = instance.getEditableProps();
|
|
6
|
+
|
|
7
|
+
props.class.add('menu');
|
|
8
|
+
props.class.add('is-' + ($desc.orientation || 'horizontal'));
|
|
9
|
+
|
|
10
|
+
const nav = Nav(instance.resolveProps(), ForEachArray($desc.items));
|
|
11
|
+
|
|
12
|
+
if($desc.compactThreshold) {
|
|
13
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
14
|
+
$desc.compact.set(entry.contentRect.width < $desc.compactThreshold);
|
|
15
|
+
});
|
|
16
|
+
observer.observe(nav);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return nav;
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {Div, ForEachArray, UnorderedList} from "../../../core/elements";
|
|
2
|
+
import {computePosition, flip, offset, shift} from "@floating-ui/dom";
|
|
3
|
+
|
|
4
|
+
export const buildSubmenu = ($desc, orientation, $isOpen, instance) => {
|
|
5
|
+
const root = instance.getRoot();
|
|
6
|
+
const $compact = root.$description?.compact;
|
|
7
|
+
if(orientation === 'inline') {
|
|
8
|
+
const submenuEl = Div({ class: 'sub-menu', 'is-open': $isOpen, 'is-inline': $compact.is(false), 'is-vertical': $compact},
|
|
9
|
+
UnorderedList({class: 'sub-menu-container'}, ForEachArray($desc.items))
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
$compact?.subscribe((isCompact) => {
|
|
13
|
+
if(isCompact) {
|
|
14
|
+
submenuEl.style.position = 'fixed';
|
|
15
|
+
submenuEl.style.left = '0px';
|
|
16
|
+
submenuEl.style.top = '0px';
|
|
17
|
+
} else {
|
|
18
|
+
submenuEl.style.position = '';
|
|
19
|
+
submenuEl.style.left = '';
|
|
20
|
+
submenuEl.style.top = '';
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return submenuEl;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return Div({class: 'sub-menu is-' + orientation, 'is-open': $isOpen, style: {position: 'fixed', left: '0px', top: '0px'}},
|
|
28
|
+
UnorderedList({class: 'sub-menu-container'}, ForEachArray($desc.items))
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const setupInteraction = (listItem, el, submenuEl, orientation, interaction, $isOpen, hasSubmenu, instance) => {
|
|
33
|
+
const root = instance.getRoot();
|
|
34
|
+
const $compact = root.$description?.compact;
|
|
35
|
+
const $menuActive = root.$description?.menuActive;
|
|
36
|
+
const $isMenuActivated = root.$description?.isMenuActivated;
|
|
37
|
+
const $activeItem = root.$description?.activeItem;
|
|
38
|
+
const rootOrientation = root.$description?.orientation || 'horizontal';
|
|
39
|
+
const clickFirst = root.$description.clickFirst || rootOrientation === 'inline';
|
|
40
|
+
|
|
41
|
+
const isPopup = () => {
|
|
42
|
+
if(orientation === 'horizontal') return true;
|
|
43
|
+
if(orientation === 'vertical') return true;
|
|
44
|
+
return $compact?.val() || false;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const updatePosition = () => {
|
|
48
|
+
const placement = (orientation === 'horizontal' && (!root || instance.$parent === root))
|
|
49
|
+
? 'bottom-start'
|
|
50
|
+
: 'right-start';
|
|
51
|
+
requestAnimationFrame(() => {
|
|
52
|
+
computePosition(el, submenuEl, {
|
|
53
|
+
placement,
|
|
54
|
+
middleware: [offset(2), flip(), shift({padding: 4})],
|
|
55
|
+
}).then(({x, y}) => {
|
|
56
|
+
submenuEl.style.left = x + 'px';
|
|
57
|
+
submenuEl.style.top = y + 'px';
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
let closeTimer = null;
|
|
63
|
+
|
|
64
|
+
const open = () => {
|
|
65
|
+
|
|
66
|
+
$activeItem?.set(instance);
|
|
67
|
+
|
|
68
|
+
if (hasSubmenu) {
|
|
69
|
+
$isOpen.set(true);
|
|
70
|
+
if (isPopup()) {
|
|
71
|
+
updatePosition();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const close = () => {
|
|
77
|
+
closeTimer = setTimeout(() => {
|
|
78
|
+
if($activeItem?.val() === instance) {
|
|
79
|
+
$activeItem?.set(null);
|
|
80
|
+
}
|
|
81
|
+
$isOpen.set(false);
|
|
82
|
+
}, 20);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
$activeItem?.subscribe((activeInstance) => {
|
|
86
|
+
if(activeInstance !== instance
|
|
87
|
+
&& activeInstance?.$parent === instance.$parent) {
|
|
88
|
+
$isOpen.set(false);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
listItem.nd
|
|
93
|
+
.onMouseEnter((e) => {
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
clearTimeout(closeTimer);
|
|
96
|
+
if(clickFirst && !$isMenuActivated?.val()) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
open();
|
|
100
|
+
})
|
|
101
|
+
.onMouseLeave((e) => {
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
if(clickFirst && $isMenuActivated?.val()) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
close();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if(clickFirst) {
|
|
110
|
+
el.nd.onStopClick(() => {
|
|
111
|
+
$isMenuActivated?.set(true);
|
|
112
|
+
open();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
document.addEventListener('click', (e) => {
|
|
117
|
+
$isMenuActivated?.set(false);
|
|
118
|
+
$isOpen.set(false);
|
|
119
|
+
$activeItem?.set(null);
|
|
120
|
+
});
|
|
121
|
+
};
|