bobe 0.0.17 → 0.0.19
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/dist/bobe.cjs.js +41 -59
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.esm.js +42 -60
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +13 -4
- package/dist/index.umd.js +41 -59
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -96,7 +96,6 @@ declare class Interpreter {
|
|
|
96
96
|
* */
|
|
97
97
|
declaration(ctx: ProgramCtx): any;
|
|
98
98
|
getData(): any;
|
|
99
|
-
fragmentDeclaration(renderFragment: BobeUI, ctx: ProgramCtx): FragmentNode;
|
|
100
99
|
/**
|
|
101
100
|
* key 元素,组件的 key
|
|
102
101
|
* value
|
|
@@ -106,7 +105,8 @@ declare class Interpreter {
|
|
|
106
105
|
* mapKey 映射, 对应子组件的属性
|
|
107
106
|
* */
|
|
108
107
|
onePropParsed(data: Store, node: any, key: string, value: any, valueIsMapKey: boolean, isFn: boolean, hookI?: number): void;
|
|
109
|
-
|
|
108
|
+
oneRealPropParsed: Interpreter['onePropParsed'];
|
|
109
|
+
componentOrFragmentDeclaration(ComponentOrRender: BobeUI | typeof Store | string, ctx: ProgramCtx): ComponentNode;
|
|
110
110
|
condDeclaration(ctx: ProgramCtx): IfNode;
|
|
111
111
|
/**
|
|
112
112
|
* <extensionLines> ::= PIPE <attributeList> NEWLINE <extensionLines>
|
|
@@ -153,10 +153,15 @@ declare class Interpreter {
|
|
|
153
153
|
setProp(node: any, key: string, value: any, hookI?: number): void;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
interface StackNode<T> {
|
|
157
|
+
value: T;
|
|
158
|
+
types: NodeSortBit;
|
|
159
|
+
prevByType: Partial<Record<number, StackNode<T>>>;
|
|
160
|
+
}
|
|
156
161
|
declare class MultiTypeStack<T> {
|
|
157
|
-
private top;
|
|
158
162
|
private typeTops;
|
|
159
163
|
length: number;
|
|
164
|
+
stack: StackNode<T>[];
|
|
160
165
|
/**
|
|
161
166
|
* 入栈操作
|
|
162
167
|
* @param value 数据
|
|
@@ -224,7 +229,11 @@ type ProgramCtx = {
|
|
|
224
229
|
before: any;
|
|
225
230
|
};
|
|
226
231
|
/** 返回值是用户自定义的节点 */
|
|
227
|
-
type BobeUI =
|
|
232
|
+
type BobeUI = {
|
|
233
|
+
/** 在哪个 Store 声明的 */
|
|
234
|
+
boundStore: Store;
|
|
235
|
+
(isSub: boolean): Tokenizer;
|
|
236
|
+
};
|
|
228
237
|
type LogicNode = {
|
|
229
238
|
__logicType: FakeType;
|
|
230
239
|
realParent: any;
|
package/dist/index.umd.js
CHANGED
|
@@ -36,20 +36,16 @@
|
|
|
36
36
|
NodeSort2[NodeSort2["TokenizerSwitcher"] = 16] = "TokenizerSwitcher";
|
|
37
37
|
return NodeSort2;
|
|
38
38
|
})(NodeSort || {});
|
|
39
|
-
var TerpEvt = /* @__PURE__ */ ((TerpEvt2) => {
|
|
40
|
-
TerpEvt2["AllAttrGot"] = "all-attr-got";
|
|
41
|
-
TerpEvt2["HandledComponentNode"] = "handled-component-node";
|
|
42
|
-
return TerpEvt2;
|
|
43
|
-
})(TerpEvt || {});
|
|
44
39
|
const IsAnchor = /* @__PURE__ */ Symbol("is-anchor");
|
|
45
40
|
|
|
46
41
|
class MultiTypeStack {
|
|
47
42
|
constructor() {
|
|
48
43
|
// 记录全局栈顶
|
|
49
|
-
|
|
44
|
+
// private top: StackNode<T> | null = null;
|
|
50
45
|
// 记录每个类别的当前最新节点(各分类的“栈顶”)
|
|
51
46
|
this.typeTops = {};
|
|
52
47
|
this.length = 0;
|
|
48
|
+
this.stack = [];
|
|
53
49
|
}
|
|
54
50
|
/**
|
|
55
51
|
* 入栈操作
|
|
@@ -60,7 +56,6 @@
|
|
|
60
56
|
const newNode = {
|
|
61
57
|
value,
|
|
62
58
|
types: bits,
|
|
63
|
-
prevGlobal: this.top,
|
|
64
59
|
prevByType: {}
|
|
65
60
|
};
|
|
66
61
|
let bit;
|
|
@@ -71,15 +66,15 @@
|
|
|
71
66
|
newNode.prevByType[bit] = this.typeTops[bit] || void 0;
|
|
72
67
|
this.typeTops[bit] = newNode;
|
|
73
68
|
}
|
|
74
|
-
this.
|
|
75
|
-
this.length++;
|
|
69
|
+
this.stack[this.length++] = newNode;
|
|
76
70
|
}
|
|
77
71
|
/**
|
|
78
72
|
* 出栈操作
|
|
79
73
|
*/
|
|
80
74
|
pop() {
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
const poppedNode = this.stack[this.length - 1];
|
|
76
|
+
this.stack[--this.length] = null;
|
|
77
|
+
if (!poppedNode) return void 0;
|
|
83
78
|
let { types: bits } = poppedNode;
|
|
84
79
|
let bit;
|
|
85
80
|
while (1) {
|
|
@@ -88,8 +83,6 @@
|
|
|
88
83
|
bits &= ~bit;
|
|
89
84
|
this.typeTops[bit] = poppedNode.prevByType[bit];
|
|
90
85
|
}
|
|
91
|
-
this.top = poppedNode.prevGlobal;
|
|
92
|
-
this.length--;
|
|
93
86
|
return [poppedNode.value, poppedNode.types];
|
|
94
87
|
}
|
|
95
88
|
/**
|
|
@@ -100,15 +93,13 @@
|
|
|
100
93
|
return (_a = this.typeTops[cat]) == null ? void 0 : _a.value;
|
|
101
94
|
}
|
|
102
95
|
peekType() {
|
|
103
|
-
|
|
104
|
-
return (_a = this.top) == null ? void 0 : _a.types;
|
|
96
|
+
return this.stack.at(-1).types;
|
|
105
97
|
}
|
|
106
98
|
/**
|
|
107
99
|
* 获取全局栈顶
|
|
108
100
|
*/
|
|
109
101
|
peek() {
|
|
110
|
-
|
|
111
|
-
return (_a = this.top) == null ? void 0 : _a.value;
|
|
102
|
+
return this.stack.at(-1).value;
|
|
112
103
|
}
|
|
113
104
|
// /**
|
|
114
105
|
// * 1. 全局向前遍历 (不分类)
|
|
@@ -140,11 +131,12 @@
|
|
|
140
131
|
// }
|
|
141
132
|
}
|
|
142
133
|
|
|
143
|
-
|
|
134
|
+
new bobeShared.BaseEvent();
|
|
144
135
|
class Interpreter {
|
|
145
136
|
constructor(tokenizer) {
|
|
146
137
|
this.tokenizer = tokenizer;
|
|
147
138
|
this.rootComponent = null;
|
|
139
|
+
this.oneRealPropParsed = this.onePropParsed.bind(this);
|
|
148
140
|
}
|
|
149
141
|
isLogicNode(node) {
|
|
150
142
|
return node && node.__logicType & LogicalBit;
|
|
@@ -293,18 +285,13 @@
|
|
|
293
285
|
return this.condDeclaration(ctx);
|
|
294
286
|
} else if (hookType) {
|
|
295
287
|
if (hookType === "static") {
|
|
296
|
-
if (typeof value === "function"
|
|
297
|
-
_node = this.
|
|
298
|
-
} else if (typeof value === "function") {
|
|
299
|
-
_node = this.fragmentDeclaration(value, ctx);
|
|
288
|
+
if (typeof value === "function") {
|
|
289
|
+
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
300
290
|
} else {
|
|
301
291
|
throw new SyntaxError(`declaration \u4E0D\u652F\u6301 ${value} \u7C7B\u578B\u7684\u9759\u6001\u63D2\u503C`);
|
|
302
292
|
}
|
|
303
293
|
} else {
|
|
304
|
-
|
|
305
|
-
Boolean(data[aoye.Keys.Raw][value]);
|
|
306
|
-
new Function("data", `let v;with(data){v=(${value})};return v`);
|
|
307
|
-
_node = this.createNode(value);
|
|
294
|
+
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
308
295
|
}
|
|
309
296
|
} else {
|
|
310
297
|
_node = this.createNode(value);
|
|
@@ -312,9 +299,9 @@
|
|
|
312
299
|
this.tokenizer.nextToken();
|
|
313
300
|
this.headerLine(_node);
|
|
314
301
|
this.extensionLines(_node);
|
|
315
|
-
if (_node.__logicType
|
|
316
|
-
|
|
317
|
-
|
|
302
|
+
if (_node.__logicType & TokenizerSwitcherBit) {
|
|
303
|
+
this.onePropParsed = this.oneRealPropParsed;
|
|
304
|
+
this.tokenizer = _node.tokenizer;
|
|
318
305
|
}
|
|
319
306
|
return _node;
|
|
320
307
|
}
|
|
@@ -322,18 +309,6 @@
|
|
|
322
309
|
const { node } = this.ctx.stack.peekByType(NodeSort.CtxProvider);
|
|
323
310
|
return node.data || node.owner.data;
|
|
324
311
|
}
|
|
325
|
-
// TODO: 指定挂载位置
|
|
326
|
-
fragmentDeclaration(renderFragment, ctx) {
|
|
327
|
-
const data = this.getData();
|
|
328
|
-
const tokenizer = renderFragment.call(data, this.opt, { data, root: "", anchor: "" });
|
|
329
|
-
const fragmentNode = {
|
|
330
|
-
__logicType: FakeType.Fragment,
|
|
331
|
-
realParent: null,
|
|
332
|
-
tokenizer,
|
|
333
|
-
data: null
|
|
334
|
-
};
|
|
335
|
-
return fragmentNode;
|
|
336
|
-
}
|
|
337
312
|
/**
|
|
338
313
|
* key 元素,组件的 key
|
|
339
314
|
* value
|
|
@@ -359,39 +334,45 @@
|
|
|
359
334
|
this.setProp(node, key, value, hookI);
|
|
360
335
|
}
|
|
361
336
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
|
|
337
|
+
componentOrFragmentDeclaration(ComponentOrRender, ctx) {
|
|
338
|
+
let Component, render, child;
|
|
339
|
+
const data = this.getData();
|
|
340
|
+
if (typeof ComponentOrRender === "string") {
|
|
341
|
+
ComponentOrRender = data[ComponentOrRender];
|
|
342
|
+
}
|
|
343
|
+
const isCC = ComponentOrRender.prototype instanceof aoye.Store;
|
|
344
|
+
if (isCC) {
|
|
345
|
+
Component = ComponentOrRender;
|
|
346
|
+
child = Component.new();
|
|
347
|
+
} else {
|
|
348
|
+
render = ComponentOrRender;
|
|
349
|
+
const boundStore = render.boundStore;
|
|
350
|
+
child = aoye.deepSignal({}, aoye.getPulling(), true);
|
|
351
|
+
Object.setPrototypeOf(child, boundStore);
|
|
352
|
+
}
|
|
353
|
+
const node = {
|
|
354
|
+
__logicType: isCC ? FakeType.Component : FakeType.Fragment,
|
|
366
355
|
realParent: ctx.realParent,
|
|
367
356
|
data: child,
|
|
368
|
-
tokenizer:
|
|
357
|
+
tokenizer: render ? render(true) : child["ui"](true)
|
|
369
358
|
};
|
|
370
|
-
|
|
371
|
-
this.onePropParsed = (data, node, key, value, valueIsMapKey, isFn, hookI) => {
|
|
359
|
+
this.onePropParsed = (data2, _, key, value, valueIsMapKey, isFn, hookI) => {
|
|
372
360
|
if (isFn) {
|
|
373
361
|
child[aoye.Keys.Raw][key] = value;
|
|
374
362
|
} else if (valueIsMapKey) {
|
|
375
|
-
aoye.shareSignal(
|
|
363
|
+
aoye.shareSignal(data2, value, child, key);
|
|
376
364
|
} else if (typeof value === "function") {
|
|
377
365
|
const meta = child[aoye.Keys.Meta];
|
|
378
366
|
const cells = meta.cells;
|
|
379
367
|
const computed = aoye.$(value);
|
|
380
368
|
cells.set(key, computed);
|
|
369
|
+
child[aoye.Keys.Raw][key] = void 0;
|
|
381
370
|
} else {
|
|
382
371
|
child[aoye.Keys.Raw][key] = value;
|
|
383
372
|
}
|
|
384
373
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
tap.once(TerpEvt.AllAttrGot, () => {
|
|
388
|
-
this.onePropParsed = prevOnePropParsed;
|
|
389
|
-
const subTkr = child["ui"](true);
|
|
390
|
-
componentNode.tokenizer = subTkr;
|
|
391
|
-
this.tokenizer = subTkr;
|
|
392
|
-
tap.emit(TerpEvt.HandledComponentNode, componentNode);
|
|
393
|
-
});
|
|
394
|
-
return componentNode;
|
|
374
|
+
node.realAfter = this.insertAfterAnchor(ctx);
|
|
375
|
+
return node;
|
|
395
376
|
}
|
|
396
377
|
// TODO: 优化代码逻辑,拆分 if elseif else
|
|
397
378
|
condDeclaration(ctx) {
|
|
@@ -1140,6 +1121,7 @@ ${_Tokenizer.EofId}`;
|
|
|
1140
1121
|
tokenizer.init(Array.from(fragments));
|
|
1141
1122
|
return tokenizer;
|
|
1142
1123
|
};
|
|
1124
|
+
ui.boundStore = aoye.Store.Current;
|
|
1143
1125
|
return ui;
|
|
1144
1126
|
}
|
|
1145
1127
|
function customRender(option) {
|