Skip to content

Commit ee5651d

Browse files
committed
Synced and resolved merge conflicts.
2 parents 8b1b6f3 + 76d0357 commit ee5651d

File tree

859 files changed

+22458
-1686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

859 files changed

+22458
-1686
lines changed

client/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.3
1+
1.1.4

client/config/test/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default {
1313
testEnvironment: "jsdom",
1414
moduleNameMapper: {
1515
"react-markdown": path.resolve(dirname, "./mocks/react-markdown.js"),
16+
"\\.md\\?url$": path.resolve(dirname, "./mocks/markdown-url-module.js"),
1617
"^@openblocks-ee(.*)$": path.resolve(
1718
dirname,
1819
isEE ? "../../packages/openblocks/src/ee/$1" : "../../packages/openblocks/src/$1"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "";

client/packages/openblocks-core/lib/index.cjs

Lines changed: 7574 additions & 0 deletions
Large diffs are not rendered by default.

client/packages/openblocks-core/lib/index.d.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,27 +309,26 @@ declare function transformWrapper<T>(
309309
defaultValue?: T
310310
): (valueAndMsg: ValueAndMsg<unknown>) => ValueAndMsg<T>;
311311

312-
interface RecursivePerfUtilParams {
313-
name: string;
314-
}
315312
interface PerfInfo {
316313
obj: any;
314+
name: string;
317315
childrenPerfInfo: PerfInfo[];
318316
costMs: number;
319317
depth: number;
320-
info?: string;
318+
info: Record<string, any>;
321319
}
320+
declare type Log = (key: string, log: any) => void;
322321
declare class RecursivePerfUtil {
323322
root: symbol;
324-
name: string;
325323
record: PerfInfo;
326324
stack: number[];
327-
constructor(params: RecursivePerfUtilParams);
325+
constructor();
328326
private initRecord;
329327
private getRecordByStack;
330-
perf<T>(obj: any, info: string, fn: () => T): T;
328+
log(info: Record<string, any>, key: string, log: any): void;
329+
perf<T>(obj: any, name: string, fn: (log: Log) => T): T;
331330
clear: () => void;
332-
print: (...stack: number[]) => void;
331+
print: (stack: number[], cost_ms_print_thr?: number) => void;
333332
}
334333
declare const evalPerfUtil: RecursivePerfUtil;
335334

@@ -742,7 +741,7 @@ declare type VariableValue = string | number | boolean | Date;
742741
declare class Translator<Messages extends object> {
743742
private readonly messages;
744743
readonly language: string;
745-
constructor(fileData: object, filterLocales?: string);
744+
constructor(fileData: object, filterLocales?: string, locales?: string[]);
746745
trans(
747746
key: NestedKey<Messages> | GlobalMessageKey,
748747
variables?: Record<string, VariableValue>

client/packages/openblocks-core/lib/index.js

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,15 @@ function createCache(obj, fnName, args) {
106106
if (!obj.__cache) {
107107
obj.__cache = {};
108108
}
109-
if (!obj.__cache[fnName]) {
110-
obj.__cache[fnName] = {
111-
id: Symbol("id"),
112-
args: args,
113-
isInProgress: true,
114-
time: Date.now(),
115-
};
116-
}
109+
obj.__cache[fnName] = {
110+
id: Symbol("id"),
111+
args: args,
112+
isInProgress: true,
113+
time: Date.now(),
114+
};
117115
return getCache(obj, fnName);
118116
}
119-
function populate(fn, args, thisObj, fnName) {
120-
if (args === void 0) { args = []; }
117+
function genCache(fn, args, thisObj, fnName) {
121118
var cache = createCache(thisObj, fnName, args);
122119
var value = fn.apply(thisObj, args);
123120
cache.isInProgress = false;
@@ -127,25 +124,21 @@ function read(thisObj, fnName) {
127124
var cache = getCache(thisObj, fnName);
128125
return cache && cache.value;
129126
}
130-
function isValid(args, thisObj, fnName, equals) {
131-
if (args === void 0) { args = []; }
127+
function hitCache(args, thisObj, fnName, equals) {
132128
var cache = getCache(thisObj, fnName);
133129
if (!cache || !cache.args)
134130
return false;
135131
if (args.length === 0 && cache.args.length === 0)
136132
return true;
137-
return cache.args.reduce(function (result, arg, index) {
138-
return result && ((equals === null || equals === void 0 ? void 0 : equals[index]) ? equals[index](arg, args[index]) : arg === args[index]);
139-
}, true);
133+
return cache.args.every(function (arg, index) { var _a, _b; return (_b = (_a = equals === null || equals === void 0 ? void 0 : equals[index]) === null || _a === void 0 ? void 0 : _a.call(equals, arg, args[index])) !== null && _b !== void 0 ? _b : arg === args[index]; });
140134
}
141-
function isInProgress(thisObj, fnName) {
135+
function isCyclic(thisObj, fnName) {
142136
var cache = getCache(thisObj, fnName);
143137
return cache && cache.isInProgress;
144138
}
145139
function cache(fn, args, thisObj, fnName, equals) {
146-
if (args === void 0) { args = []; }
147-
if (!isValid(args, thisObj, fnName, equals) && !isInProgress(thisObj, fnName)) {
148-
populate(fn, args, thisObj, fnName);
140+
if (!hitCache(args, thisObj, fnName, equals) && !isCyclic(thisObj, fnName)) {
141+
genCache(fn, args, thisObj, fnName);
149142
}
150143
return read(thisObj, fnName);
151144
}
@@ -163,13 +156,14 @@ function memoized(equals) {
163156
};
164157
}
165158

159+
var COST_MS_PRINT_THR = 0;
166160
var RecursivePerfUtil = /** @class */ (function () {
167-
function RecursivePerfUtil(params) {
161+
function RecursivePerfUtil() {
168162
var _this = this;
169163
this.root = Symbol("root");
170164
this.stack = [];
171165
this.initRecord = function () {
172-
return { obj: _this.root, childrenPerfInfo: [], costMs: 0, depth: 0 };
166+
return { obj: _this.root, name: "@root", childrenPerfInfo: [], costMs: 0, depth: 0, info: {} };
173167
};
174168
this.getRecordByStack = function (stack) {
175169
var curRecord = _this.record;
@@ -181,28 +175,29 @@ var RecursivePerfUtil = /** @class */ (function () {
181175
this.clear = function () {
182176
_this.record = _this.initRecord();
183177
};
184-
this.print = function () {
185-
var stack = [];
186-
for (var _i = 0; _i < arguments.length; _i++) {
187-
stack[_i] = arguments[_i];
188-
}
178+
this.print = function (stack, cost_ms_print_thr) {
179+
if (cost_ms_print_thr === void 0) { cost_ms_print_thr = COST_MS_PRINT_THR; }
189180
var record = _this.getRecordByStack(stack);
190-
console.info("PerfInfo. stack: ".concat(stack, ", [info] ").concat(record.info, ", obj: "), record.obj, ", costMs: ".concat(record.costMs, ", depth: ").concat(record.depth, ", size: ").concat(_.size(record.childrenPerfInfo)));
181+
console.info("~~ PerfInfo. costMs: ".concat(record.costMs.toFixed(3), ", stack: ").concat(stack, ", [name]").concat(record.name, ", [info]"), record.info, ", obj: ", record.obj, ", depth: ".concat(record.depth, ", size: ").concat(_.size(record.childrenPerfInfo)));
191182
record.childrenPerfInfo.forEach(function (subRecord, idx) {
192-
console.info(" [".concat(idx, "]").concat(subRecord.info, ". obj: "), subRecord.obj, " costMs: ", subRecord.costMs);
183+
if (subRecord.costMs >= cost_ms_print_thr) {
184+
console.info(" costMs: ".concat(subRecord.costMs.toFixed(3), " [").concat(idx, "]").concat(subRecord.name, " [info]"), subRecord.info, ". obj: ", subRecord.obj, "");
185+
}
193186
});
194187
};
195-
this.name = params.name;
196188
this.record = this.initRecord();
197189
}
198-
RecursivePerfUtil.prototype.perf = function (obj, info, fn) {
190+
RecursivePerfUtil.prototype.log = function (info, key, log) {
191+
info[key] = log;
192+
};
193+
RecursivePerfUtil.prototype.perf = function (obj, name, fn) {
199194
{
200-
return fn();
195+
return fn(_.noop);
201196
}
202197
};
203198
return RecursivePerfUtil;
204199
}());
205-
var evalPerfUtil = new RecursivePerfUtil({ name: "evaluate" });
200+
var evalPerfUtil = new RecursivePerfUtil();
206201
// @ts-ignore
207202
globalThis.evalPerfUtil = evalPerfUtil;
208203

@@ -365,8 +360,9 @@ var RecordNode = /** @class */ (function (_super) {
365360
});
366361
};
367362
RecordNode.prototype.justEval = function (exposingNodes, methods) {
368-
return _.mapValues(this.children, function (v) {
369-
return v.evaluate(exposingNodes, methods);
363+
var _this = this;
364+
return _.mapValues(this.children, function (v, key) {
365+
return evalPerfUtil.perf(_this, "eval-".concat(key), function () { return v.evaluate(exposingNodes, methods); });
370366
});
371367
};
372368
RecordNode.prototype.getChildren = function () {
@@ -7396,8 +7392,15 @@ See the accompanying LICENSE file for terms.
73967392
var IntlMessageFormat = IntlMessageFormat$1;
73977393

73987394
var defaultLocale = "en";
7399-
var locales = navigator.languages && navigator.languages.length > 0
7400-
? __spreadArray([], navigator.languages, true) : [navigator.language || navigator.userLanguage || defaultLocale];
7395+
var locales = [defaultLocale];
7396+
if (globalThis.navigator) {
7397+
if (navigator.languages && navigator.languages.length > 0) {
7398+
locales = __spreadArray([], navigator.languages, true);
7399+
}
7400+
else {
7401+
locales = [navigator.language || navigator.userLanguage || defaultLocale];
7402+
}
7403+
}
74017404
function parseLocale(s) {
74027405
var locale = s.trim();
74037406
if (!locale) {
@@ -7431,11 +7434,16 @@ function getValueByLocale(defaultValue, func) {
74317434
}
74327435
return defaultValue;
74337436
}
7434-
function getDataByLocale(fileData, suffix, filterLocales) {
7437+
function getDataByLocale(fileData, suffix, filterLocales, targetLocales) {
7438+
var localeInfos = __spreadArray([], fallbackLocaleInfos, true);
7439+
var targetLocaleInfo = parseLocales(targetLocales || []);
7440+
if (targetLocaleInfo.length > 0) {
7441+
localeInfos = __spreadArray(__spreadArray([], targetLocaleInfo, true), localeInfos, true);
7442+
}
74357443
var filterNames = parseLocales((filterLocales !== null && filterLocales !== void 0 ? filterLocales : "").split(","))
74367444
.map(function (l) { var _a; return l.language + ((_a = l.region) !== null && _a !== void 0 ? _a : ""); })
74377445
.filter(function (s) { return fileData[s + suffix] !== undefined; });
7438-
var names = __spreadArray(__spreadArray([], fallbackLocaleInfos
7446+
var names = __spreadArray(__spreadArray([], localeInfos
74397447
.flatMap(function (_a) {
74407448
var language = _a.language, region = _a.region;
74417449
return [
@@ -7463,8 +7471,8 @@ var globalMessages = Object.fromEntries(Object.entries(getDataByLocale(localeDat
74637471
];
74647472
}));
74657473
var Translator = /** @class */ (function () {
7466-
function Translator(fileData, filterLocales) {
7467-
var _a = getDataByLocale(fileData, "", filterLocales), data = _a.data, language = _a.language;
7474+
function Translator(fileData, filterLocales, locales) {
7475+
var _a = getDataByLocale(fileData, "", filterLocales, locales), data = _a.data, language = _a.language;
74687476
this.messages = Object.assign({}, data, globalMessages);
74697477
this.language = language;
74707478
this.trans = this.trans.bind(this);

client/packages/openblocks-core/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openblocks-core",
3-
"version": "0.0.1",
3+
"version": "0.0.5",
44
"type": "module",
55
"scripts": {
66
"start": "rollup -c rollup.config.js --watch",
@@ -26,11 +26,13 @@
2626
"openblocks",
2727
"components"
2828
],
29-
"main": "lib/index.js",
3029
"types": "lib/index.d.ts",
3130
"files": [
32-
"lib/index.js",
33-
"lib/index.d.ts"
31+
"lib"
3432
],
35-
"author": "ioc"
33+
"exports": {
34+
"import": "./lib/index.js",
35+
"require": "./lib/index.cjs"
36+
},
37+
"author": "Openblocks"
3638
}

client/packages/openblocks-core/rollup.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ const config = [
1313
},
1414
external: ["lodash", "stylis"],
1515
},
16+
{
17+
input: "src/index.ts",
18+
plugins: [
19+
resolve({ browser: true }),
20+
commonjs(),
21+
typescript({ declaration: false, declarationDir: undefined }),
22+
],
23+
output: {
24+
format: "cjs",
25+
file: "lib/index.cjs",
26+
},
27+
external: ["lodash", "stylis"],
28+
},
1629
{
1730
input: "lib/dts/index.d.ts",
1831
plugins: [

client/packages/openblocks-core/src/eval/recordNode.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _ from "lodash";
2+
import { shallowEqual } from "util/objectUtils";
23
import { memoized } from "../util/memoize";
34
import { AbstractNode, Node, NodeToValue } from "./node";
45
import { EvalMethods } from "./types/evalTypes";
@@ -31,8 +32,8 @@ export class RecordNode<T extends Record<string, Node<unknown>>> extends Abstrac
3132
exposingNodes: Record<string, Node<unknown>>,
3233
methods?: EvalMethods
3334
): RecordNodeToValue<T> {
34-
return _.mapValues(this.children, (v) =>
35-
v.evaluate(exposingNodes, methods)
35+
return _.mapValues(this.children, (v, key) =>
36+
evalPerfUtil.perf(this, `eval-${key}`, () => v.evaluate(exposingNodes, methods))
3637
) as RecordNodeToValue<T>;
3738
}
3839
override getChildren(): Node<unknown>[] {

0 commit comments

Comments
 (0)