lupine.components 1.1.1 → 1.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lupine.components",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "license": "MIT",
5
5
  "author": "uuware.com",
6
6
  "homepage": "https://github.com/uuware/lupine.js",
@@ -1,4 +1,5 @@
1
1
  import { CssProps, RefProps, VNode, mountInnerComponent } from 'lupine.web';
2
+ import { backActionHelper } from '../lib';
2
3
 
3
4
  export type ActionSheetCloseProps = () => void;
4
5
 
@@ -125,16 +126,21 @@ export class ActionSheet {
125
126
  },
126
127
  };
127
128
  const component = (
128
- <div css={cssContainer} class='act-sheet-box' onClick={onClickContainer}>
129
+ <div
130
+ css={cssContainer}
131
+ class='act-sheet-box'
132
+ onClick={onClickContainer}
133
+ data-back-action={backActionHelper.genBackActionId()}
134
+ >
129
135
  <div ref={ref} class='act-sheet-body'>
130
136
  <div class='act-sheet-content'>
131
137
  <div class='act-sheet-title'>{title}</div>
132
138
  {children}
133
139
  {confirmButtonText && (
134
- <div class='act-sheet-bottom-item act-sheet-confirm' onClick={onConfirm}>
135
- {confirmButtonText}
136
- </div>
137
- )}
140
+ <div class='act-sheet-bottom-item act-sheet-confirm' onClick={onConfirm}>
141
+ {confirmButtonText}
142
+ </div>
143
+ )}
138
144
  </div>
139
145
  {cancelButtonText && (
140
146
  <div class='act-sheet-bottom-item' onClick={onCancel}>
@@ -210,11 +216,11 @@ export class ActionSheetMessage {
210
216
  }: ActionSheetMessageProps): Promise<ActionSheetCloseProps> {
211
217
  const handleClose = await ActionSheet.show({
212
218
  title,
213
- children: <div css={{ padding: '8px',borderTop: '1px solid var(--primary-border-color)', }}>{message}</div>,
219
+ children: <div css={{ padding: '8px', borderTop: '1px solid var(--primary-border-color)' }}>{message}</div>,
214
220
  contentMaxHeight,
215
221
  confirmButtonText,
216
222
  handleConfirmClicked,
217
- cancelButtonText,
223
+ cancelButtonText,
218
224
  closeWhenClickOutside,
219
225
  });
220
226
  return handleClose;
@@ -5,6 +5,7 @@ export type MenuItemProps = {
5
5
  js?: () => void;
6
6
  alt?: string;
7
7
  hide?: boolean;
8
+ devAdmin?: boolean;
8
9
  };
9
10
 
10
11
  export type NestMenuItemProps = MenuItemProps & {
@@ -18,6 +18,7 @@ export type MenuSidebarProps = {
18
18
  maxWidth?: string;
19
19
  color?: string;
20
20
  backgroundColor?: string;
21
+ isDevAdmin?: boolean;
21
22
  };
22
23
  export const MenuSidebar = ({
23
24
  mobileMenu,
@@ -29,6 +30,7 @@ export const MenuSidebar = ({
29
30
  backgroundColor = 'dark',
30
31
  maxWidth = '100%',
31
32
  maxWidthMobileMenu = MediaQueryMaxWidth.TabletMax,
33
+ isDevAdmin = false,
32
34
  }: MenuSidebarProps) => {
33
35
  const css: CssProps = {
34
36
  // backgroundColor,
@@ -218,7 +220,7 @@ export const MenuSidebar = ({
218
220
  const renderItems = (items: NestMenuItemProps[], className: string) => {
219
221
  return (
220
222
  <div class={className}>
221
- {items.map((item) => {
223
+ {items.filter((item) => isDevAdmin || !item.devAdmin).map((item) => {
222
224
  if (item.hide === true) {
223
225
  return null;
224
226
  }
@@ -2,11 +2,17 @@
2
2
  MobileHeaderTitleIcon can be used in MobileHeaderComponent's Center part.
3
3
  It has it's own Left and Right icons.
4
4
  */
5
- import { VNode, CssProps, HtmlVar } from 'lupine.components';
5
+ import { VNode, CssProps, HtmlVar, backActionHelper } from 'lupine.components';
6
6
 
7
7
  export const MobileHeadeIconHeight = '40px';
8
8
  export const MobileHeadeBackIcon = ({ onClick }: { onClick: (event: Event) => void }) => {
9
- return <i class='ifc-icon mg-arrow_back_ios_new_outlined mhti-back-icon' onClick={(event) => onClick(event)}></i>;
9
+ return (
10
+ <i
11
+ class={'ifc-icon mg-arrow_back_ios_new_outlined mhti-back-icon'}
12
+ data-back-action={backActionHelper.genBackActionId()}
13
+ onClick={(event) => onClick(event)}
14
+ ></i>
15
+ );
10
16
  };
11
17
 
12
18
  export const MobileHeadeCloseIcon = ({ onClick }: { onClick: (event: Event) => void }) => {
@@ -2,13 +2,17 @@
2
2
  HeaderWithBackFrame is a full page frame with header for mobile sliders.
3
3
  It has Back icon at Left and Close icon at Right.
4
4
  */
5
- import { VNode, CssProps, RefProps, HtmlVar } from 'lupine.components';
5
+ import { VNode, CssProps, RefProps, HtmlVar, backActionHelper } from 'lupine.components';
6
6
  import { MobileHeaderTitleIcon } from './mobile-header-title-icon';
7
7
 
8
8
  export const HeaderWithBackFrameHeight = '40px';
9
9
  export const HeaderWithBackFrameLeft = ({ onClick }: { onClick: (event: Event) => void }) => {
10
10
  return (
11
- <i class='ifc-icon mg-arrow_back_ios_new_outlined header-back-left-icon' onClick={(event) => onClick(event)}></i>
11
+ <i
12
+ class='ifc-icon mg-arrow_back_ios_new_outlined header-back-left-icon'
13
+ data-back-action={backActionHelper.genBackActionId()}
14
+ onClick={(event) => onClick(event)}
15
+ ></i>
12
16
  );
13
17
  };
14
18
 
@@ -1,4 +1,4 @@
1
- import { CssProps, RefProps, VNode } from 'lupine.components';
1
+ import { backActionHelper, CssProps, RefProps, VNode } from 'lupine.components';
2
2
 
3
3
  export class MobileSideMenuHelper {
4
4
  static show() {
@@ -7,10 +7,14 @@ export class MobileSideMenuHelper {
7
7
  setTimeout(() => {
8
8
  ref.classList.add('animate-show');
9
9
  }, 1);
10
+
11
+ const backActionId = backActionHelper.genBackActionId();
12
+ ref.setAttribute('data-back-action', backActionId);
10
13
  }
11
14
 
12
15
  static hide() {
13
16
  const ref = document.querySelector('.mobile-side-menu-mask') as HTMLDivElement;
17
+ ref.removeAttribute('data-back-action');
14
18
  ref.classList.remove('animate-show');
15
19
  setTimeout(() => {
16
20
  ref.classList.remove('show');
@@ -25,7 +25,7 @@ export type SliderFrameProps = {
25
25
  defaultContent?: VNode<any> | string;
26
26
  direction?: 'right' | 'bottom';
27
27
  hook?: SliderFrameHookProps;
28
- afterClose?: () => void;
28
+ afterClose?: () => void | Promise<void>;
29
29
  };
30
30
  export const SliderFrame = (props: SliderFrameProps) => {
31
31
  if (props.hook) {
@@ -39,11 +39,11 @@ export const SliderFrame = (props: SliderFrameProps) => {
39
39
  props.hook.close = (event: Event) => {
40
40
  stopPropagation(event);
41
41
  ref.current?.classList.remove('show');
42
- setTimeout(() => {
42
+ setTimeout(async () => {
43
43
  ref.current?.classList.add('d-none');
44
44
  dom.value = '';
45
45
  if (props.afterClose) {
46
- props.afterClose();
46
+ await props.afterClose();
47
47
  }
48
48
  }, 400);
49
49
  };
@@ -0,0 +1,54 @@
1
+ import { uniqueIdGenerator } from 'lupine.web';
2
+
3
+ type BackFn = () => void | Promise<void>;
4
+
5
+ export const backActionUniqueId = uniqueIdGenerator('bb-'); // bb means back button
6
+ class BackActionHelper {
7
+ private backFn?: BackFn;
8
+
9
+ genBackActionId() {
10
+ return backActionUniqueId();
11
+ }
12
+
13
+ getAllBackActionButtons() {
14
+ const nodes = document.querySelectorAll('[data-back-action^="bb-"]');
15
+ const buttons = Array.from(nodes)
16
+ .map((el) => {
17
+ const match = el.getAttribute('data-back-action')?.match(/bb-(\d+)/);
18
+ return match ? { el, num: parseInt(match[1], 10) } : null;
19
+ })
20
+ .filter(Boolean)
21
+ .sort((a, b) => b!.num - a!.num)
22
+ .map((item) => item!.el);
23
+ return buttons;
24
+ }
25
+
26
+ clear() {
27
+ this.backFn = undefined;
28
+ }
29
+ attach(back: BackFn) {
30
+ this.backFn = back;
31
+ }
32
+ async processBackAction(): Promise<boolean> {
33
+ if (this.backFn) {
34
+ try {
35
+ await this.backFn();
36
+ this.clear();
37
+ return true;
38
+ } catch (e) {
39
+ console.error('back button back failed', e);
40
+ }
41
+ return false;
42
+ }
43
+
44
+ const buttons = this.getAllBackActionButtons();
45
+ if (buttons.length) {
46
+ const button = buttons[0];
47
+ button.dispatchEvent(new Event('click'));
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ }
53
+
54
+ export const backActionHelper = /* @__PURE__ */ new BackActionHelper();
package/src/lib/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './back-button-helper';
1
2
  export * from './base62';
2
3
  export * from './blob-utils';
3
4
  export * from './calculate-text-width';