js:add lib and .d.ts
This commit is contained in:
9
doric-js/lib/src/native/animate.d.ts
vendored
Normal file
9
doric-js/lib/src/native/animate.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
/**
|
||||
* Only supports x,y,width,height,corner(just for four corners),rotation,bgColor,
|
||||
* @param panel @see Panel
|
||||
*/
|
||||
export declare function animate(context: BridgeContext): (args: {
|
||||
animations: () => void;
|
||||
duration: number;
|
||||
}) => Promise<any>;
|
57
doric-js/lib/src/native/animate.js
Normal file
57
doric-js/lib/src/native/animate.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Panel } from "../ui/panel";
|
||||
import { takeLet } from "../pattern/candies";
|
||||
/**
|
||||
* Only supports x,y,width,height,corner(just for four corners),rotation,bgColor,
|
||||
* @param panel @see Panel
|
||||
*/
|
||||
export function animate(context) {
|
||||
const entity = context.entity;
|
||||
if (entity instanceof Panel) {
|
||||
let panel = entity;
|
||||
return (args) => {
|
||||
return takeLet(panel.context.animate)(it => {
|
||||
return it.submit().then(() => {
|
||||
args.animations();
|
||||
return takeLet(panel.getRootView())(root => {
|
||||
if (root.isDirty()) {
|
||||
const model = root.toModel();
|
||||
model.duration = args.duration;
|
||||
const ret = it.animateRender(model);
|
||||
root.clean();
|
||||
return ret;
|
||||
}
|
||||
for (let v of panel.allHeadViews()) {
|
||||
if (v.isDirty()) {
|
||||
const model = v.toModel();
|
||||
const ret = it.animateRender(model);
|
||||
it.clean();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
throw new Error('Cannot find any animated elements');
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
else {
|
||||
return (args) => {
|
||||
return Promise.reject(`Cannot find panel in Context:${context.id}`);
|
||||
};
|
||||
}
|
||||
}
|
7
doric-js/lib/src/native/index.native.d.ts
vendored
Normal file
7
doric-js/lib/src/native/index.native.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from './modal';
|
||||
export * from './navbar';
|
||||
export * from './navigator';
|
||||
export * from './network';
|
||||
export * from './storage';
|
||||
export * from './popover';
|
||||
export * from './animate';
|
22
doric-js/lib/src/native/index.native.js
Normal file
22
doric-js/lib/src/native/index.native.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export * from './modal';
|
||||
export * from './navbar';
|
||||
export * from './navigator';
|
||||
export * from './network';
|
||||
export * from './storage';
|
||||
export * from './popover';
|
||||
export * from './animate';
|
24
doric-js/lib/src/native/modal.d.ts
vendored
Normal file
24
doric-js/lib/src/native/modal.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { Gravity } from "../util/gravity";
|
||||
export declare function modal(context: BridgeContext): {
|
||||
toast: (msg: string, gravity?: Gravity) => void;
|
||||
alert: (arg: string | {
|
||||
title: string;
|
||||
msg: string;
|
||||
okLabel?: string | undefined;
|
||||
}) => Promise<any>;
|
||||
confirm: (arg: string | {
|
||||
title: string;
|
||||
msg: string;
|
||||
okLabel?: string | undefined;
|
||||
cancelLabel?: string | undefined;
|
||||
}) => Promise<any>;
|
||||
prompt: (arg: {
|
||||
title?: string | undefined;
|
||||
msg?: string | undefined;
|
||||
okLabel?: string | undefined;
|
||||
cancelLabel?: string | undefined;
|
||||
text?: string | undefined;
|
||||
defaultText?: string | undefined;
|
||||
}) => Promise<string>;
|
||||
};
|
30
doric-js/lib/src/native/modal.js
Normal file
30
doric-js/lib/src/native/modal.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Gravity } from "../util/gravity";
|
||||
export function modal(context) {
|
||||
return {
|
||||
toast: (msg, gravity = Gravity.Bottom) => {
|
||||
context.modal.toast({
|
||||
msg,
|
||||
gravity: gravity.toModel(),
|
||||
});
|
||||
},
|
||||
alert: (arg) => {
|
||||
if (typeof arg === 'string') {
|
||||
return context.modal.alert({ msg: arg });
|
||||
}
|
||||
else {
|
||||
return context.modal.alert(arg);
|
||||
}
|
||||
},
|
||||
confirm: (arg) => {
|
||||
if (typeof arg === 'string') {
|
||||
return context.modal.confirm({ msg: arg });
|
||||
}
|
||||
else {
|
||||
return context.modal.confirm(arg);
|
||||
}
|
||||
},
|
||||
prompt: (arg) => {
|
||||
return context.modal.prompt(arg);
|
||||
},
|
||||
};
|
||||
}
|
8
doric-js/lib/src/native/navbar.d.ts
vendored
Normal file
8
doric-js/lib/src/native/navbar.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { Color } from "../util/color";
|
||||
export declare function navbar(context: BridgeContext): {
|
||||
isHidden: () => Promise<boolean>;
|
||||
setHidden: (hidden: boolean) => Promise<any>;
|
||||
setTitle: (title: string) => Promise<any>;
|
||||
setBgColor: (color: Color) => Promise<any>;
|
||||
};
|
28
doric-js/lib/src/native/navbar.js
Normal file
28
doric-js/lib/src/native/navbar.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Panel } from "../ui/panel";
|
||||
export function navbar(context) {
|
||||
const entity = context.entity;
|
||||
let panel = undefined;
|
||||
if (entity instanceof Panel) {
|
||||
panel = entity;
|
||||
}
|
||||
return {
|
||||
isHidden: () => {
|
||||
return context.navbar.isHidden();
|
||||
},
|
||||
setHidden: (hidden) => {
|
||||
return context.navbar.setHidden({
|
||||
hidden,
|
||||
});
|
||||
},
|
||||
setTitle: (title) => {
|
||||
return context.navbar.setTitle({
|
||||
title,
|
||||
});
|
||||
},
|
||||
setBgColor: (color) => {
|
||||
return context.navbar.setBgColor({
|
||||
color: color.toModel(),
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
9
doric-js/lib/src/native/navigator.d.ts
vendored
Normal file
9
doric-js/lib/src/native/navigator.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function navigator(context: BridgeContext): {
|
||||
push: (scheme: string, config?: {
|
||||
alias?: string | undefined;
|
||||
animated?: boolean | undefined;
|
||||
extra?: object | undefined;
|
||||
} | undefined) => Promise<any>;
|
||||
pop: (animated?: boolean) => Promise<any>;
|
||||
};
|
15
doric-js/lib/src/native/navigator.js
Normal file
15
doric-js/lib/src/native/navigator.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export function navigator(context) {
|
||||
return {
|
||||
push: (scheme, config) => {
|
||||
if (config && config.extra) {
|
||||
config.extra = JSON.stringify(config.extra);
|
||||
}
|
||||
return context.navigator.push({
|
||||
scheme, config
|
||||
});
|
||||
},
|
||||
pop: (animated = true) => {
|
||||
return context.navigator.pop({ animated });
|
||||
},
|
||||
};
|
||||
}
|
27
doric-js/lib/src/native/network.d.ts
vendored
Normal file
27
doric-js/lib/src/native/network.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export interface IRequest {
|
||||
url?: string;
|
||||
method?: "get" | "post" | "put" | "delete";
|
||||
headers?: {
|
||||
[index: string]: string;
|
||||
};
|
||||
params?: {
|
||||
[index: string]: string;
|
||||
};
|
||||
data?: object | string;
|
||||
timeout?: number;
|
||||
}
|
||||
export interface IResponse {
|
||||
data: any;
|
||||
status: number;
|
||||
headers?: {
|
||||
[index: string]: string;
|
||||
};
|
||||
}
|
||||
export declare function network(context: BridgeContext): {
|
||||
request: (config: IRequest) => Promise<IResponse>;
|
||||
get: (url: string, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
post: (url: string, data?: string | object | undefined, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
put: (url: string, data?: string | object | undefined, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
delete: (url: string, data?: string | object | undefined, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
};
|
63
doric-js/lib/src/native/network.js
Normal file
63
doric-js/lib/src/native/network.js
Normal file
@@ -0,0 +1,63 @@
|
||||
function transformRequest(request) {
|
||||
let url = request.url || "";
|
||||
if (request.params !== undefined) {
|
||||
const queryStrings = [];
|
||||
for (let key in request.params) {
|
||||
queryStrings.push(`${key}=${encodeURIComponent(request.params[key])}`);
|
||||
}
|
||||
request.url = `${request.url}${url.indexOf('?') >= 0 ? '&' : '?'}${queryStrings.join('&')}`;
|
||||
}
|
||||
if (typeof request.data === 'object') {
|
||||
request.data = JSON.stringify(request.data);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
export function network(context) {
|
||||
return {
|
||||
request: (config) => {
|
||||
return context.network.request(transformRequest(config));
|
||||
},
|
||||
get: (url, config) => {
|
||||
let finalConfig = config;
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {};
|
||||
}
|
||||
finalConfig.url = url;
|
||||
finalConfig.method = "get";
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
},
|
||||
post: (url, data, config) => {
|
||||
let finalConfig = config;
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {};
|
||||
}
|
||||
finalConfig.url = url;
|
||||
finalConfig.method = "post";
|
||||
if (data !== undefined) {
|
||||
finalConfig.data = data;
|
||||
}
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
},
|
||||
put: (url, data, config) => {
|
||||
let finalConfig = config;
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {};
|
||||
}
|
||||
finalConfig.url = url;
|
||||
finalConfig.method = "put";
|
||||
if (data !== undefined) {
|
||||
finalConfig.data = data;
|
||||
}
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
},
|
||||
delete: (url, data, config) => {
|
||||
let finalConfig = config;
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {};
|
||||
}
|
||||
finalConfig.url = url;
|
||||
finalConfig.method = "delete";
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
},
|
||||
};
|
||||
}
|
6
doric-js/lib/src/native/popover.d.ts
vendored
Normal file
6
doric-js/lib/src/native/popover.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { View } from "../ui/view";
|
||||
export declare function popover(context: BridgeContext): {
|
||||
show: (view: View) => Promise<any>;
|
||||
dismiss: (view?: View | undefined) => Promise<any>;
|
||||
};
|
27
doric-js/lib/src/native/popover.js
Normal file
27
doric-js/lib/src/native/popover.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Panel } from "../ui/panel";
|
||||
export function popover(context) {
|
||||
const entity = context.entity;
|
||||
let panel = undefined;
|
||||
if (entity instanceof Panel) {
|
||||
panel = entity;
|
||||
}
|
||||
return {
|
||||
show: (view) => {
|
||||
if (panel) {
|
||||
panel.addHeadView(view);
|
||||
}
|
||||
return context.popover.show(view.toModel());
|
||||
},
|
||||
dismiss: (view = undefined) => {
|
||||
if (panel) {
|
||||
if (view) {
|
||||
panel.removeHeadView(view);
|
||||
}
|
||||
else {
|
||||
panel.clearHeadViews();
|
||||
}
|
||||
}
|
||||
return context.popover.dismiss(view ? { id: view.viewId } : undefined);
|
||||
},
|
||||
};
|
||||
}
|
7
doric-js/lib/src/native/storage.d.ts
vendored
Normal file
7
doric-js/lib/src/native/storage.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function storage(context: BridgeContext): {
|
||||
setItem: (key: string, value: string, zone?: string | undefined) => Promise<any>;
|
||||
getItem: (key: string, zone?: string | undefined) => Promise<string>;
|
||||
remove: (key: string, zone?: string | undefined) => Promise<any>;
|
||||
clear: (zone: string) => Promise<any>;
|
||||
};
|
16
doric-js/lib/src/native/storage.js
Normal file
16
doric-js/lib/src/native/storage.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export function storage(context) {
|
||||
return {
|
||||
setItem: (key, value, zone) => {
|
||||
return context.storage.setItem({ key, value, zone });
|
||||
},
|
||||
getItem: (key, zone) => {
|
||||
return context.storage.getItem({ key, zone });
|
||||
},
|
||||
remove: (key, zone) => {
|
||||
return context.storage.remove({ key, zone });
|
||||
},
|
||||
clear: (zone) => {
|
||||
return context.storage.clear({ zone });
|
||||
},
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user