repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
uniapp-vue3-template
github_2023
oyjt
typescript
repeatSubmit
const repeatSubmit = (config: HttpRequestConfig) => { const requestObj = { url: config.url, data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data, time: new Date().getTime(), }; const sessionObj = storage.getJSON('sessionObj'); if (!sessionObj) { storage.setJSON('sess...
// 防止重复提交
https://github.com/oyjt/uniapp-vue3-template/blob/455dee33b8dfd71f82f4fdd910eeceda492fb554/src/utils/request/interceptors.ts#L16-L40
455dee33b8dfd71f82f4fdd910eeceda492fb554
uniapp-vue3-template
github_2023
oyjt
typescript
refreshToken
const refreshToken = async (http: HttpRequestAbstract, config: HttpRequestConfig) => { // 是否在获取token中,防止重复获取 if (!isRefreshing) { // 修改登录状态为true isRefreshing = true; // 等待登录完成 await useUserStore().authLogin(); // 登录完成之后,开始执行队列请求 requestQueue.forEach(cb => cb()); // 重试完了清空这个队列 request...
// 刷新token
https://github.com/oyjt/uniapp-vue3-template/blob/455dee33b8dfd71f82f4fdd910eeceda492fb554/src/utils/request/interceptors.ts#L46-L68
455dee33b8dfd71f82f4fdd910eeceda492fb554
browser-extension
github_2023
linkwarden
typescript
logBookmarks
function logBookmarks(bookmarks: BookmarkTreeNode[], accumulator: bookmarkMetadata[]) { for (const bookmark of bookmarks) { if (bookmark.url) { accumulator.push({ id: parseInt(bookmark.id), // Convert string id to number collectionId: 0, // Define how to determine collectionId name: ...
// Helper function to collect all bookmarks recursively
https://github.com/linkwarden/browser-extension/blob/986b30f508d05ad768f2c457aab245868e4389d9/src/@/lib/cache.ts#L181-L198
986b30f508d05ad768f2c457aab245868e4389d9
browser-extension
github_2023
linkwarden
typescript
genericOnClick
async function genericOnClick( info: OnClickData, tab: chrome.tabs.Tab | undefined ) { const { syncBookmarks, baseUrl } = await getConfig(); const configured = await isConfigured(); if (!tab?.url || !tab?.title || !configured) { return; } switch (info.menuItemId) { case 'save-all-tabs': { co...
// A generic onclick callback function.
https://github.com/linkwarden/browser-extension/blob/986b30f508d05ad768f2c457aab245868e4389d9/src/pages/Background/index.ts#L195-L273
986b30f508d05ad768f2c457aab245868e4389d9
lowcoder_CN
github_2023
mousheng
typescript
EChartsReactCore.componentDidUpdate
componentDidUpdate(prevProps: EChartsReactProps) { /** * if shouldSetOption return false, then return, not update echarts options * default is true */ const { shouldSetOption } = this.props; if (shouldSetOption && isFunction(shouldSetOption) && !shouldSetOption(prevProps, this.props)) { ...
// update
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-comps/src/comps/chartComp/reactEcharts/core.tsx#L42-L74
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EChartsReactCore.getEchartsInstance
public getEchartsInstance(): ECharts { return ( this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts) ); }
/** * return the echart object * 1. if exist, return the existed instance * 2. or new one instance */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-comps/src/comps/chartComp/reactEcharts/core.tsx#L85-L90
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EChartsReactCore.dispose
private dispose() { if (this.ele) { // dispose echarts instance this.echarts.dispose(this.ele); } }
/** * dispose echarts and clear size-sensor */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-comps/src/comps/chartComp/reactEcharts/core.tsx#L95-L100
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EChartsReactCore.renderNewEcharts
private renderNewEcharts() { const { onEvents, onChartReady } = this.props; // 1. new echarts instance const echartsInstance = this.updateEChartsOption(); // 2. bind events this.bindEvents(echartsInstance, onEvents || {}); // 3. on chart ready if (onChartReady && isFunction(onChartReady))...
/** * render a new echarts instance */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-comps/src/comps/chartComp/reactEcharts/core.tsx#L105-L116
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EChartsReactCore.bindEvents
private bindEvents(instance: any, events: EChartsReactProps["onEvents"]) { function _bindEvent(eventName: string, func: Function) { // ignore the event config which not satisfy if (isString(eventName) && isFunction(func)) { // binding event instance.on(eventName, (param: any) => { ...
// bind the events
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-comps/src/comps/chartComp/reactEcharts/core.tsx#L119-L136
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EChartsReactCore.updateEChartsOption
private updateEChartsOption(): EChartsInstance { const { option, notMerge = false, lazyUpdate = false, showLoading, loadingOption = null, } = this.props; // 1. get or initial the echarts object const echartInstance = this.getEchartsInstance(); // 2. set the echarts opti...
/** * render the echarts */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-comps/src/comps/chartComp/reactEcharts/core.tsx#L141-L170
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
CodeNode.convertedValue
private convertedValue(): string { if (this.codeType === "Function") { return `{{function(){${this.unevaledValue}}}}`; } return this.unevaledValue; }
// FIXME: optimize later
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-core/src/eval/codeNode.tsx#L47-L52
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
unWrapDependingNodeMap
function unWrapDependingNodeMap(depMap: Map<Node<unknown>, Set<string>>) { const nextMap = new Map<Node<unknown>, Set<string>>(); depMap.forEach((p, n) => { if (n.type === "wrap") { nextMap.set((n as InstanceType<typeof WrapNode>).delegate, p); } else { nextMap.set(n, p); } }); return ne...
/** * transform WrapNode in dependingNodeMap to actual node. * since WrapNode is dynamically constructed in eval process, its reference always changes. */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-core/src/eval/node.tsx#L147-L157
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
ValueAndMsg.constructor
constructor(value: T, msg?: string, extra?: ValueExtra, midValue?: any) { this.value = value; this.msg = msg; this.extra = extra; this.midValue = midValue; }
// a middle value after eval and before transform
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-core/src/eval/types/valueAndMsg.tsx#L13-L18
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
RelaxedJsonParser.evalIndexedSnippet
evalIndexedSnippet(snippet: string) { const index = parseInt(snippet.startsWith("{{") ? snippet.slice(2, -2) : snippet.slice(4, -4)); if (index >= 0 && index < this.segments.length) { const segment = this.segments[index]; if (isDynamicSegment(segment)) { return this.evalDynamicSegment(segmen...
// eval {{ + ${index} + }} or \{\{ + ${index} + \}\}
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-core/src/eval/utils/string2Fn.tsx#L146-L155
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
brightnessCompare
const brightnessCompare = (colorStr: string, intensity: number) => { const color = colord(colorStr); return color.brightness() < intensity; };
// judge color is bright
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder-design/src/components/colorSelect/colorUtils.ts#L52-L55
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
getErrorMessage
const getErrorMessage = (code: number) => { switch (code) { case 401: return createMessage(ERROR_401); case 500: return createMessage(ERROR_500); case 0: return createMessage(ERROR_0); } };
/** * transforn server errors to client error codes */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/api/apiUtils.ts#L172-L181
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
ApplicationApi.publicToAll
static publicToAll(appId: string, publicToAll: boolean) { return Api.put(ApplicationApi.publicToAllURL(appId), { publicToAll: publicToAll, }); }
/** * set app as public */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/api/applicationApi.ts#L215-L219
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
DatasourceApi.fetchJsDatasourceByApp
static fetchJsDatasourceByApp( appId: string ): AxiosPromise<GenericApiResponse<NodePluginDatasourceInfo[]>> { return Api.get(DatasourceApi.url + `/jsDatasourcePlugins?appId=${appId}`); }
// this api can be accessed by anonymous users when app is public.
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/api/datasourceApi.ts#L162-L166
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
InviteApi.getInvite
static getInvite(request: GetInviteRequest): AxiosPromise<GenericApiResponse<InviteInfo>> { return Api.post(InviteApi.getInviteURL, undefined, request); }
// generate invitation
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/api/inviteApi.ts#L25-L27
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
InviteApi.getInviteInfo
static getInviteInfo(request: InviteRequest): AxiosPromise<GenericApiResponse<InviteInfo>> { return Api.get(InviteApi.getInviteURL + "/" + request.invitationId); }
// get invitation info
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/api/inviteApi.ts#L30-L32
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
InviteApi.acceptInvite
static acceptInvite(request: InviteRequest): AxiosPromise<GenericApiResponse<InviteInfo>> { // the same api as getInviteInfo, method is by post return Api.get(InviteApi.acceptInviteURL(request.invitationId)); }
// accept invitation
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/api/inviteApi.ts#L35-L38
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EditorState.changeStateFn
private changeStateFn(fn: (editorState: EditorState) => ChangeableProps) { this.setEditorState((oldState) => { const stateChanges = fn(oldState); return setFields(oldState, stateChanges); }); }
/** * use changeState most of the time, and you can use this method to get the latest editorState. (similar to react's setState method) */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/editorState.tsx#L80-L85
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EditorState.getUICompByName
getUICompByName(name: string) { const compMap = this.getAllUICompMap(); return Object.values(compMap).find( (item) => item.children.name.getView() === name ); }
/** * Get the comp variable by name. * FIXME: currently only the ui comp can be obtained, and in the future all comps should be obtained */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/editorState.tsx#L118-L123
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EditorState.queryCompInfoList
queryCompInfoList(): Array<CompInfo> { const exposingInfo = this.getQueriesComp().nameAndExposingInfo(); return this.getQueriesComp() .getView() .map((item) => { const name = item.children.name.getView(); return this.getCompInfo(exposingInfo, name, BottomResTypeEnum.Query); });...
// All queries here uniformly use type === 'query'
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/editorState.tsx#L211-L219
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EditorState.selectedComp
selectedComp(): OptionalComp { // temporary glue code const compType = this.getUIComp().children.compType.getView(); if (compType !== "normal" && compType !== "module") { return this.getUIComp().children.comp; } const compMap = this.getAllCompMap(); if (this.selectedCompNames.size > 1) { ...
/** * @deprecated */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/editorState.tsx#L280-L293
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EditorState.canvasPositionParams
canvasPositionParams(): PositionParams | undefined { return this.getUIComp().getComp()?.getPositionParams(); }
// positional parameters of the global canvas
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/editorState.tsx#L296-L298
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
EditorState.isCompSelected
isCompSelected(compName: string): OptionalComp { const compMap = this.getAllCompMap(); return Object.values(compMap).find( (item) => item.children.name.getView() === compName && this.selectedCompNames.has(compName) ); }
/** * @param compName comp name * @returns the comp corresponding to the current component name regardless of whether it is a multi-select state */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/editorState.tsx#L343-L350
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
setStyle
const setStyle = (height: string, width: string) => { // console.log(width, height); const img = imgRef.current; const imgDiv = img?.getElementsByTagName("div")[0]; const imgCurrent = img?.getElementsByTagName("img")[0]; img!.style.height = height; img!.style.width = width; imgDiv!.style.he...
// on safari
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/imageComp.tsx#L104-L116
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
whyEvalChanged
function whyEvalChanged(comp: Comp) { if (comp.node() !== comp.node()) { return "same comp bad node"; } if (comp.node()?.evaluate() !== comp.node()?.evaluate()) { return "same node bad eval"; } const comp2 = evalAndReduce(comp); if (comp.node() !== comp2.node()) { return "equal comp bad node"; ...
/** * debug tool * The reason why comp's reference was changed after eval. * 1. comp of the same value, but the return value of node has changed * 2. the node reference has not changed, but the reference of the eval value has changed * 3, the eval value's reference has not changed, but changed when reducing * */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/rootComp.test.tsx#L18-L30
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
isEvalEqual
function isEvalEqual(comp: Comp) { const newComp = evalAndReduce(comp); return comp === newComp; }
/** * eval invariance, an important feature of comp */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/rootComp.test.tsx#L35-L38
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
RootComp.findCompByName
private findCompByName(name: string) { // internal comp if (name.startsWith("@")) { return this.findInternalComp(name); } // ui comp const compMap = this.children.ui.getAllCompItems(); const uiComp = Object.values(compMap).find((item) => item.children.name.getView() === name); if (uiC...
/** * find comp by name */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/rootComp.tsx#L169-L230
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
UICompTmp2.getComp
getComp() { const compType = this.children.compType.getView(); if (!Object.keys(LayoutMap).includes(compType)) { return undefined; } return this.children.comp; }
/** * this method is here due to historical reasons. * outside code should not use this method. */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/uiComp.tsx#L56-L62
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
fixOldData
function fixOldData(oldData: any) { if ( oldData && (oldData.hasOwnProperty("backgroundColor") || oldData.hasOwnProperty("borderColor") || oldData.hasOwnProperty("color")) ) { return { background: oldData.backgroundColor, border: oldData.borderColor, text: oldData.color, ...
/** * Compatible with old data 2022-08-05 */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/buttonComp/buttonCompConstants.tsx#L87-L101
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
weekHeadContent
const weekHeadContent = (info: DayHeaderContentArg) => { const text = info.text.split(" "); text[0] = FirstDayOptions.filter((x) => (x.value.toString() === text[0]) || (x.value === '0' && text[0] === '7'))[0].label return { html: `<span class="week-head ${info.isPast && "past"} ${info.isToday && "today"}"> ...
// 周标题渲染
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/calendarComp/calendarConstants.tsx#L864-L873
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
ContainerCompBuilder.constructor
constructor( childrenMap: ToConstructor<ChildrenCompMap>, viewFn: ViewFnTypeForComp<ViewReturn, ContainerChildren<ChildrenCompMap>> ) { this.childrenMap = childrenMap; this.viewFn = viewFn; }
/** * If viewFn is not placed in the constructor, the type of ViewReturn cannot be inferred */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/containerBase/containerCompBuilder.tsx#L40-L46
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
singleSelectComps
function singleSelectComps(exposingValueJs?: (compName: string) => string): CompConfig[] { return [ { type: "select", exposingValueJs, }, { type: "radio", exposingValueJs, }, { type: "segmentedControl", exposingValueJs, }, ]; }
// single selection, return type varies
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/formComp/generate/comp.tsx#L53-L68
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
joinString
function joinString(compName: string) { return compName + '.value.join(",")'; }
// return value is of type string[]
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/formComp/generate/comp.tsx#L70-L72
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
calculateSummaryProgress
function calculateSummaryProgress(task: any) { if (task.type != gantt.config.types.project) return task.progress; var totalToDo = 0; var totalDone = 0; gantt.eachTask(function (child) { if (child.type != gantt.config.types.project) { totalToDo += child.duration; totalDone += ...
// 计算总进度
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/gantee/ganttComp.tsx#L213-L226
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
refreshSummaryProgress
function refreshSummaryProgress(id: taskType, submit: any) { if (!gantt.isTaskExists(id)) return; var task = gantt.getTask(id); var newProgress = calculateSummaryProgress(task); if (newProgress !== task.progress) { task.progress = newProgress; if (!submit) { gantt.refreshTas...
// 刷新总进度
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/gantee/ganttComp.tsx#L228-L248
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
setAutoCalculateCallBack
function setAutoCalculateCallBack() { gantt.attachEvent("onParse", function () { gantt.eachTask(function (task) { props.AutoCalculateProgress && (task.progress = calculateSummaryProgress(task)) }); }, { id: 'handleParseRef' }) gantt.attachEvent("onAfterTaskUpdate", function (id) { ...
// 添加、删除回调事件
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/gantee/ganttComp.tsx#L295-L323
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
ListViewImplComp.itemsNode
itemsNode(): Node<Record<string, unknown>[]> { const { itemCount } = getData(this.children.noOfRows.getView()); const itemIndexName = this.children.itemIndexName.getView(); const itemDataName = this.children.itemDataName.getView(); const dataExposingNode = this.children.noOfRows.exposingNode(); cons...
/** expose the data from inner comps */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/listViewComp/listViewComp.tsx#L107-L151
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
getKey
function getKey(record: RecordType) { return record[OB_ROW_ORI_INDEX]; }
/** * Currently use index as key */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/tableComp/selectionControl.tsx#L28-L30
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
DebugContainer
function DebugContainer(props: any) { return ( <MemoryRouter initialEntries={[{ pathname: "/", search: "?value=teresa_teng" }]}> {props.comp.getView()} </MemoryRouter> ); }
// FIXME: add a single test for the click action of the table
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.test.tsx#L98-L104
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
TableImplComp.getProps
getProps() { return childrenToProps(_.omit(this.children, "style")) as TableChildrenView; }
// only for test?
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx#L121-L123
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
TableImplComp.sortDataNode
sortDataNode() { const nodes = { data: this.children.data.exposingNode(), sort: this.children.sort.node(), dataIndexes: this.children.columns.getColumnsNode("dataIndex"), sortables: this.children.columns.getColumnsNode("sortable"), }; const sortedDataNode = withFunction(fromRecord(no...
// handle sort: data -> sortedData
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx#L292-L312
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
TableImplComp.filterNode
filterNode() { const nodes = { data: this.sortDataNode(), searchValue: this.children.searchText.node(), filter: this.children.toolbar.children.filter.node(), showFilter: this.children.toolbar.children.showFilter.node(), }; let context = this; const filteredDataNode = withFunction...
// handle hide/search/filter: sortedData->filteredData
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx#L315-L339
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
ColumnListComp.dataChangedAction
dataChangedAction(param: { rowExample: JSONObject; doGeneColumn: boolean; dynamicColumn: boolean; data: Array<JSONObject>; }) { return customAction<ActionDataType>( { type: "dataChanged", ...param, }, false ); }
/** * If the table data changes, call this method to trigger the action */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/tableComp/column/tableColumnListComp.tsx#L98-L111
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
ColumnListComp.geneColumnsAction
private geneColumnsAction(rowExample: RowExampleType, data: Array<JSONObject>) { // If no data, return directly if (rowExample === undefined || rowExample === null) { return []; } const dataKeys = Object.keys(rowExample); if (dataKeys.length === 0) { return []; } const columnsVie...
/** * According to the data, adjust the column */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/tableComp/column/tableColumnListComp.tsx#L116-L153
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
ContainerCompBuilder.constructor
constructor( childrenMap: ToConstructor<ChildrenCompMap>, viewFn: ViewFnTypeForComp<ViewReturn, ContainerChildren<ChildrenCompMap>> ) { this.childrenMap = childrenMap; this.viewFn = viewFn; }
/** * If viewFn is not placed in the constructor, the type of ViewReturn cannot be inferred */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/comps/triContainerComp/triContainerCompBuilder.tsx#L40-L46
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
withTmpState
function withTmpState<T extends CodeControlJSONType>( control: T, initialValue: ConstructorToView<T> ) { const childrenMap = { value: stateComp<ConstructorToView<T>>(initialValue), defaultValue: control, }; const MultiComp = new MultiCompBuilder(childrenMap, (props) => { // here's just type declar...
/** * In order to implement default value logic. * for example, in input components such as Input and Switch, the value of which can be edited by the user, but the default value can also be specified in the property panel. * When the default value is changed, the user-input value is replaced with the new default val...
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/codeStateControl.tsx#L69-L160
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
stateControlMethodExposing
function stateControlMethodExposing<T extends ExposeMethodCompConstructor<AbstractComp>>( VariantComp: T, param: ParamConfig, transformer?: (value: unknown) => JSONValue ) { return withMethodExposingBase(VariantComp, [ { method: { name: trans("eventHandler.set") + _.upperFirst(param.name), ...
// expose set***, clear***, reset*** methods
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/codeStateControl.tsx#L205-L243
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
toSelf
function toSelf(color: string) { return color; }
// return dependent color
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx#L149-L151
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleToUnchecked
function handleToUnchecked(color: string) { if (toHex(color) === SURFACE_COLOR) { return SECOND_SURFACE_COLOR; } return contrastBackground(color); }
// return switch unchecked color
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx#L170-L175
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleToSegmentBackground
function handleToSegmentBackground(color: string) { if (toHex(color) === SURFACE_COLOR) { return "#E1E3EB"; } return contrastBackground(color); }
// return segmented background
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx#L178-L183
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleToDividerText
function handleToDividerText(color: string) { return darkenColor(color, 0.4); }
// return divider text color
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx#L221-L223
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleCalendarSelectColor
function handleCalendarSelectColor(color: string) { return lightenColor(color, 0.3) + "4C"; }
// return calendar select background color
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx#L226-L228
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleLightenColor
function handleLightenColor(color: string) { return lightenColor(color, 0.1); }
// return lighten color
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx#L231-L233
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleCalendarText
function handleCalendarText(color: string, textDark: string, textLight: string) { return isDarkColor(color) ? textLight : lightenColor(textDark, 0.1); }
// return calendar text
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx#L253-L255
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
expectToJsonPass
function expectToJsonPass(comp: ConstructorToComp<typeof ListTestComp>) { let comp2 = new ListTestComp({ value: comp.toJsonValue() }); expect(comp2.getView().length).toEqual(comp.getView().length); for (let i = 0; i < comp2.getView().length; i++) { expect(comp2.getView()[i].getView()).toEqual(comp.getView()[i...
/** * The result of deserialization after serialization is the same */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/list.test.tsx#L25-L31
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
LIST_CLASS.genKey
private genKey() { // assert that nextKey is always greater than all current keys while (this.__nextKey > 0 && !this.children.hasOwnProperty(this.__nextKey - 1)) --this.__nextKey; return this.__nextKey++; }
/** use this function to generate keys, which can reproduce the same key sequence when rebuilding */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/list.tsx#L110-L115
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
LIST_CLASS.getChildrenArray
private getChildrenArray() { return this.childrenOrder.map((key) => this.children[key]); }
/** * The reason for not using getView directly is that getView may be overridden by subclasses */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/list.tsx#L119-L121
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
LIST_CLASS.multiAction
multiAction(actions: Array<CustomListAction<ChildCompCtor>>) { const editDSL = actions.some((action) => !!action.editDSL); console.assert( actions.every((action) => !_.isNil(action.editDSL) && action.editDSL === editDSL), `list's multiAction: all actions should have the same editDSL. editDSL...
/** * Multiple actions are executed by order */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/list.tsx#L291-L305
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
MultiCompBuilder.constructor
constructor( childrenMap: ToConstructor<ChildrenCompMap>, viewFn: ViewFnTypeForComp<ViewReturn, ChildrenCompMap> ) { this.childrenMap = childrenMap; this.viewFn = viewFn; }
/** * If viewFn is not placed in the constructor, the type of ViewReturn cannot be inferred */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/multi.tsx#L96-L102
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
TEMP_CLASS.addAction
addAction(key: string, value: ConstructorToDataType<ChildComp>) { return customAction<MapAction>( { type: "add", key: key, value: value, }, true ); }
// with type checking
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/sameTypeMap.tsx#L135-L144
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
TMP_CLASS.updateChildContextData
private updateChildContextData(input: ContextDataType): this { return super.reduce(updateNodesV2Action(this.getContextValue(input))); }
/** * Update the value of the child node */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withContext.tsx#L95-L97
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
TMP_CLASS.refreshChildContextData
private refreshChildContextData(): this { if (this.contextData && this.valueV2) { const newValue = this.getContextValue(this.contextData); if (!_.isEqual(this.prevContextVal, newValue)) { this.prevContextVal = newValue; return this.updateChildContextData(this.contextData); ...
/** * Update the value of the child node to display the result prompt */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withContext.tsx#L102-L111
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
DepsConfig.constructor
constructor( name: string, depNodesFn: (children: ChildrenType) => T, func: (input: RecordNodeToValue<T>) => any, desc?: ReactNode ) { this.name = name; this.desc = desc ?? ""; this.depNodesFn = depNodesFn; this.func = func; }
/** * a complex configuration of exposed data, simple can use NameConfig * @param name exposing name * @param depNodesFn Return the dependent node, note that a cached version is need (currently the node function has a cache). * @param func Calculate the new value by the dependent node * @param desc descr...
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withExposing.tsx#L287-L297
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
CompDepsConfig.constructor
constructor( name: string, depNodesFn: (comp: Comp) => T, func: (input: RecordNodeToValue<T>) => any, desc?: ReactNode ) { this.name = name; this.desc = desc ?? ""; this.depNodesFn = depNodesFn; this.func = func; }
/** * a complex configuration of exposed data, simple can use NameConfig * @param name exposing name * @param depNodesFn Return the dependent node, note that a cached version is need (currently the node function has a cache). * @param func Calculate the new value by the dependent node * @param desc descr...
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withExposing.tsx#L324-L334
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
CacheParamsMap.set
set(key: string, params: ParamValues) { if (!paramsEqual(this.cacheParamsMap[key], params)) { // console.info("withMultiContext CacheParamsMap set. key: ", key, "params: ", params); // this.changedKeys.add(key); this.cacheParamsMap[key] = params; } }
// private readonly changedKeys = new Set<string>();
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withMultiContext.tsx#L58-L64
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
WithMultiContextComp.parseChildrenFromValue
override parseChildrenFromValue(params: CompParams): ChildrenType { const dispatch = params.dispatch ?? _.noop; const newParams = { ...params, dispatch: wrapDispatch(dispatch, COMP_KEY) }; const comp: WithParamComp = new WithParamCompCtor(newParams) as unknown as WithParamComp; const mapComp = ...
// WARNING: this is designed to be not pure functional
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withMultiContext.tsx#L87-L94
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
WithMultiContextComp.getView
override getView(): ViewReturn { // don't provide _key_ parameter if no storage no interaction needed return (params: ParamValues, key: string) => { this.cacheParamsMap.set(key, params); return this.getComp(key)!.getComp(); }; }
/** return a function to generate view by params */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withMultiContext.tsx#L101-L107
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
WithMultiContextComp.getCachedComp
getCachedComp(key: string) { const params = this.cacheParamsMap.get(key); if (_.isNil(params)) return undefined; const mapComps = this.getMap(); if (mapComps.hasOwnProperty(key) && paramsEqual(params, mapComps[key].getParams())) { return mapComps[key]; } return undefined; ...
/** interactive comps may be cached */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withMultiContext.tsx#L110-L118
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
WithParamComp.setPartialParamDataAction
static setPartialParamDataAction(paramData: Partial<ParamValues>) { return customAction( { type: "setPartialParamData", data: paramData, }, false ); }
/** * this action requires eval to be valid, don't use it directly with reduce */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/generators/withParams.tsx#L94-L102
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
arrayMoveIndex
const arrayMoveIndex = (fromIndex: number, toIndex: number, currentIndex: number): number => { if (fromIndex === currentIndex) { return toIndex; } if (currentIndex < fromIndex && currentIndex < toIndex) { return currentIndex; } if (currentIndex > fromIndex && currentIndex > toIndex) { return curre...
/** * An array element is to be moved from the fromIndex position to the toIndex position. * Returns the new position of the element originally at the currentIndex position after the move */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/utils/index.tsx#L60-L74
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
NameGenerator.genItemName
genItemName(typeName: string): string { let name; do { name = this.genDefaultItemName(typeName); } while (!this.isDistinct(name)); return name; }
/** * Automatically generate itemName * * @remarks * Has side effects, will change the state of the generator * * @param typeName typeName to get itemName * @returns the generated itemName result corresponding to typeName */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/utils/nameGenerator.ts#L30-L36
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
CompContainer.addChangeListener
addChangeListener(handler: CompContainerChangeHandler) { this.changeListeners.push(handler); }
/** * Add comp change event listener */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/utils/useCompInstance.tsx#L249-L251
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
CompContainer.removeChangeListener
removeChangeListener(handler: CompContainerChangeHandler) { this.changeListeners = this.changeListeners.filter((i) => i !== handler); }
/** * Remove comp change event listener */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/utils/useCompInstance.tsx#L256-L258
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
CompContainer.setComp
setComp(tmpComp: InstanceType<T>, actions?: CompAction[]) { if (!this.initialized) { throw new Error("comp container is not initialized, setComp of container can't be called"); } if (tmpComp === this.comp) { return; } // 1ms const evaluatedComp = showCost("eval", () =...
/** * Set up a new comp instance */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/comps/utils/useCompInstance.tsx#L263-L278
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
mergeOp
function mergeOp(op1: LayoutOp, op2: LayoutOp): LayoutOp | undefined { if (op2.type === LayoutOpTypes.CHANGE_ITEM) { if (op1.type === LayoutOpTypes.CHANGE_ITEM && op1.key === op2.key) { return changeItemOp(op1.key, { ...op1.item, ...op2.item }); } } if (op2.type === LayoutOpTypes.DELETE_...
// try to reduce two adjacent ops to one
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/layout/layoutOpUtils.tsx#L17-L39
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
shrinkLayoutByMinY
function shrinkLayoutByMinY(items: LayoutItem[], y: number): LayoutItem[] { return items.filter((item) => item.y + item.h > y); }
// ignore items already iterated
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/layout/utils.ts#L323-L325
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
moveToSolveCollisions
function moveToSolveCollisions( itemToMove: LayoutItem, items: LayoutItem[] ): [LayoutItem, LayoutItem] { const newItem = cloneLayoutItem(itemToMove); let collisionArea = newItem; for (const item of items) { if (newItem.y + newItem.h < item.y) { break; } const deltaY = deltaYToSolveCollision...
/** * move itemToMove to solve collision, a collision area will be created afterwords * * @return [@movedItem, @collisionArea] * @movedItem moved item * @collisionArea this area should not be occupied within latter collision solving * * FIXME: add unittest */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/layout/utils.ts#L336-L354
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
deltaYToSolveCollision
function deltaYToSolveCollision(itemToMove: LayoutItem, staticItem: LayoutItem): number { if (!collides(itemToMove, staticItem)) { return 0; } return staticItem.y + staticItem.h - itemToMove.y; }
// move itemToMove to solve the collision
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/layout/utils.ts#L357-L362
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
useSaveComp
function useSaveComp( applicationId: string, readOnly: boolean, rootCompInstance: RootCompInstanceType | undefined ) { const originalComp = rootCompInstance?.comp; // throttle comp change const comp = useThrottle(originalComp, 1000); const dispatch = useDispatch(); const [prevComp, setPrevComp] = useSta...
/** * FIXME: optimize the logic of saving comps * compose debounce + throttle * make sure savingComps succeed before executing */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/pages/editor/appEditorInternal.tsx#L31-L69
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleGlobalKeyDown
function handleGlobalKeyDown( e: KeyboardEvent, editorState: EditorState, editorHistory: EditorHistory | undefined, togglePanel: TogglePanel, toggleShortcutList: () => void, applicationId: string ) { switch (getShortcutAction(e, "global")) { case "toggleLeftPanel": togglePanel("left"); bre...
// global hotkeys
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/pages/editor/editorHotKeys.tsx#L31-L82
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
handleEditorKeyDown
function handleEditorKeyDown(e: React.KeyboardEvent, editorState: EditorState) { switch (getShortcutAction(e, "editor")) { case "selectAllComps": editorState.setSelectedCompNames( new Set( Object.values(editorState.getUIComp().getTopCompItems()).map((item) => item.children.name...
// local hotkeys
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/pages/editor/editorHotKeys.tsx#L161-L187
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
addListener
const addListener = () => { window.addEventListener("mousedown", preventDefault); };
// prevent the editor window slide when resize
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx#L34-L36
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
getSnapshotOperations
function getSnapshotOperations(comp: Comp, action: CompAction) { let operations: AppSnapshotContext["operations"] = []; if (action.extraInfo?.compInfos) { // comp info exists when adding, layout change or deleting operations = action.extraInfo.compInfos.map((e) => ({ compName: e.compName, compTy...
/** * get detailed history by action */
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/util/editoryHistory.ts#L50-L94
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
normalizeShortcut
function normalizeShortcut( mod: boolean, metaKey?: boolean, ctrlKey?: boolean, altKey?: boolean, shiftKey?: boolean, key = "" ): string { return [ ...(mod ? ["Mod"] : [metaKey ? "Meta" : "", ctrlKey ? "Ctrl" : ""]), altKey ? "Alt" : "", // If press only shift+(single character), shift is igno...
// store shortcut in DSL, not change it
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/client/packages/lowcoder/src/util/keyUtils.tsx#L97-L114
66af24c4ed339d5fcf6852ceea5e19ad83a14746
lowcoder_CN
github_2023
mousheng
typescript
getFileSignedUrl
async function getFileSignedUrl(bucket: string, fileName: string, client: SupabaseClient) { const ret = await client.storage.from(bucket).createSignedUrl(fileName, expiresIn); if (ret.error) { throw ret.error; } return ret.data.signedUrl; }
// 5 minutes
https://github.com/mousheng/lowcoder_CN/blob/66af24c4ed339d5fcf6852ceea5e19ad83a14746/server/node-service/src/plugins/supabase/run.ts#L25-L31
66af24c4ed339d5fcf6852ceea5e19ad83a14746
opencast
github_2023
stephancill
typescript
handleCopy
const handleCopy = (closeMenu: () => void) => async (): Promise<void> => { closeMenu(); await navigator.clipboard.writeText(`${siteURL}/tweet/${tweetId}`); toast.success('Copied to clipboard'); };
// const handleBookmark =
https://github.com/stephancill/opencast/blob/c163bd00cfc0e79912f4834ebebd71ad7bb15c34/src/components/tweet/tweet-share.tsx#L50-L54
c163bd00cfc0e79912f4834ebebd71ad7bb15c34
opencast
github_2023
stephancill
typescript
fetchUserForKey
const fetchUserForKey = async ( keyPair: KeyPair ): Promise<UserFull | null> => { const { result: user } = await fetchJSON<UserFullResponse>( `/api/signer/${keyPair.publicKey}/user` ); return (user as UserFull) || null; };
/** * Key storage explainer: * 'keyPair' storage is used to store the key pair of the currently signed in user. * 'keyPairs' storage is used to store all key pairs that have been used to sign in. */
https://github.com/stephancill/opencast/blob/c163bd00cfc0e79912f4834ebebd71ad7bb15c34/src/lib/context/auth-context.tsx#L73-L80
c163bd00cfc0e79912f4834ebebd71ad7bb15c34
opencast
github_2023
stephancill
typescript
handleUserAuth
const handleUserAuth = async (forceKeyPair?: KeyPair): Promise<void> => { setLoading(true); // Get signer from local storage if (forceKeyPair) { setKeyPair(forceKeyPair); } let keyPair = forceKeyPair || (await getActiveKeyPair()); const keyPairs = await getKeyPairs(); if (keyPair) {...
/** * Updates users and current user * @param forceKeyPair Force a key pair to be set as the current user */
https://github.com/stephancill/opencast/blob/c163bd00cfc0e79912f4834ebebd71ad7bb15c34/src/lib/context/auth-context.tsx#L106-L141
c163bd00cfc0e79912f4834ebebd71ad7bb15c34
opencast
github_2023
stephancill
typescript
_resolveTopic
async function _resolveTopic(url: string): Promise<TopicType | null> { const farcasterChannel = await getChannel(url); if (farcasterChannel) { return { name: farcasterChannel.name, description: farcasterChannel.description, image: farcasterChannel.imageUrl, url }; } if (url.sta...
// CAIP-19 URL
https://github.com/stephancill/opencast/blob/c163bd00cfc0e79912f4834ebebd71ad7bb15c34/src/lib/topics/resolve-topic.ts#L89-L256
c163bd00cfc0e79912f4834ebebd71ad7bb15c34
obsidian-spreadsheets
github_2023
divamgupta
typescript
SpreadsheetView.setViewData
setViewData(data: string, clear: boolean) { if(data.trim()){ this.sheet_data_in = JSON.parse(data) } else { this.sheet_data_in = [{ name: "Sheet1" }]; } this.refresh(); }
// If clear is set, then it means we're opening a completely different file.
https://github.com/divamgupta/obsidian-spreadsheets/blob/5ce73d64dc3bcd03e1326b45ea79bc730181a533/view.tsx#L98-L107
5ce73d64dc3bcd03e1326b45ea79bc730181a533
buildel
github_2023
elpassion
typescript
PipelineObject.fireBlockOnClick
async fireBlockOnClick(element: Element) { fireEvent( element, new MouseEvent('click', { bubbles: true, cancelable: true, }), ); return this; }
//to avoid issue with d3.drag lib (document = null).
https://github.com/elpassion/buildel/blob/1eb24ead3278fe6aa5df681cf8eab8130bb4d4cf/apps/web-remix/app/tests/__tests__/pipelines/build.test.tsx#L616-L626
1eb24ead3278fe6aa5df681cf8eab8130bb4d4cf
dpp.vim
github_2023
Shougo
typescript
checkIf
const checkIf = async (plugin: Plugin) => { if (!("if" in plugin)) { return true; } if (is.Boolean(plugin.if)) { return plugin.if; } // Eval plugin-option-if string. return await denops.call("eval", plugin.if) as boolean; };
// Check plugin-option-if is enabled
https://github.com/Shougo/dpp.vim/blob/ed3f27904e1f109f6212f98acaacd6e9b94d873f/denops/dpp/dpp.ts#L117-L128
ed3f27904e1f109f6212f98acaacd6e9b94d873f
devops-journey
github_2023
ismoilovdevml
typescript
setValue
const setValue = (value: T) => { try { // Allow value to be a function so we have same API as useState const valueToStore = value instanceof Function ? value(storedValue) : value; // Save state setStoredValue(valueToStore); // Save to local storage if (typeof window !== '...
// Return a wrapped version of useState's setter function that ...
https://github.com/ismoilovdevml/devops-journey/blob/ed81d29f4142957c146f94739ae701cf15f0a58c/hooks/useLocalStorage.ts#L23-L37
ed81d29f4142957c146f94739ae701cf15f0a58c
oisy-wallet
github_2023
dfinity
typescript
readLocalCanisterIds
const readLocalCanisterIds = ({ prefix }: { prefix?: string }): Record<string, string> => { const dfxCanisterIdsJsonFile = join(process.cwd(), '.dfx', 'local', 'canister_ids.json'); const e2eCanisterIdsJsonFile = join(process.cwd(), 'canister_e2e_ids.json'); return readIds({ filePath: existsSync(dfxCanisterIdsJson...
/** * Read all the locally deployed canister IDs. For example Oisy backend, ckBTC|ETH, ICP etc. * @param prefix */
https://github.com/dfinity/oisy-wallet/blob/4e02d674d47e70be19097c8b6fedcaa2f8f8e19f/vite.utils.ts#L11-L18
4e02d674d47e70be19097c8b6fedcaa2f8f8e19f
oisy-wallet
github_2023
dfinity
typescript
readOisyCanisterIds
const readOisyCanisterIds = ({ prefix }: { prefix?: string }): Record<string, string> => { const canisterIdsJsonFile = join(process.cwd(), 'canister_ids.json'); return readIds({ filePath: canisterIdsJsonFile, prefix }); };
/** * Read Oisy staging and production canister IDs * @param prefix */
https://github.com/dfinity/oisy-wallet/blob/4e02d674d47e70be19097c8b6fedcaa2f8f8e19f/vite.utils.ts#L24-L27
4e02d674d47e70be19097c8b6fedcaa2f8f8e19f
oisy-wallet
github_2023
dfinity
typescript
readRemoteCanisterIds
const readRemoteCanisterIds = ({ prefix }: { prefix?: string }): Record<string, string> => { const dfxJsonFile = join(process.cwd(), 'dfx.json'); try { interface DetailsId { ic: string; staging?: string; } interface Details { remote?: { id: DetailsId; }; } interface DfxJson { canisters...
/** * Read IC staging and production canister IDs. For example ckBTC staging and production but, also ICP ledger production * @param prefix */
https://github.com/dfinity/oisy-wallet/blob/4e02d674d47e70be19097c8b6fedcaa2f8f8e19f/vite.utils.ts#L33-L81
4e02d674d47e70be19097c8b6fedcaa2f8f8e19f