@rpgjs/client 5.0.0-alpha.2 → 5.0.0-alpha.21
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/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/Map.d.ts +7 -1
- package/dist/Gui/Gui.d.ts +170 -5
- package/dist/Resource.d.ts +97 -0
- package/dist/RpgClient.d.ts +259 -59
- package/dist/RpgClientEngine.d.ts +379 -6
- package/dist/Sound.d.ts +199 -0
- package/dist/components/animations/index.d.ts +4 -0
- package/dist/components/dynamics/parse-value.d.ts +1 -0
- package/dist/components/gui/index.d.ts +3 -3
- package/dist/components/index.d.ts +3 -1
- package/dist/components/prebuilt/index.d.ts +18 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/index10.js +149 -4
- package/dist/index10.js.map +1 -1
- package/dist/index11.js +22 -7
- package/dist/index11.js.map +1 -1
- package/dist/index12.js +6 -4
- package/dist/index12.js.map +1 -1
- package/dist/index13.js +11 -14
- package/dist/index13.js.map +1 -1
- package/dist/index14.js +8 -40
- package/dist/index14.js.map +1 -1
- package/dist/index15.js +217 -180
- package/dist/index15.js.map +1 -1
- package/dist/index16.js +104 -7
- package/dist/index16.js.map +1 -1
- package/dist/index17.js +82 -372
- package/dist/index17.js.map +1 -1
- package/dist/index18.js +110 -27
- package/dist/index18.js.map +1 -1
- package/dist/index19.js +360 -18
- package/dist/index19.js.map +1 -1
- package/dist/index2.js +726 -32
- package/dist/index2.js.map +1 -1
- package/dist/index20.js +5 -2416
- package/dist/index20.js.map +1 -1
- package/dist/index21.js +47 -109
- package/dist/index21.js.map +1 -1
- package/dist/index22.js +7 -107
- package/dist/index22.js.map +1 -1
- package/dist/index23.js +394 -65
- package/dist/index23.js.map +1 -1
- package/dist/index24.js +40 -15
- package/dist/index24.js.map +1 -1
- package/dist/index25.js +20 -36
- package/dist/index25.js.map +1 -1
- package/dist/index26.js +2629 -1
- package/dist/index26.js.map +1 -1
- package/dist/index27.js +102 -310
- package/dist/index27.js.map +1 -1
- package/dist/index28.js +63 -17
- package/dist/index28.js.map +1 -1
- package/dist/index29.js +18 -8
- package/dist/index29.js.map +1 -1
- package/dist/index3.js +70 -8
- package/dist/index3.js.map +1 -1
- package/dist/index30.js +24 -8
- package/dist/index30.js.map +1 -1
- package/dist/index31.js +88 -167
- package/dist/index31.js.map +1 -1
- package/dist/index32.js +34 -494
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +22 -10
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +3 -4401
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +20 -1
- package/dist/index35.js.map +1 -1
- package/dist/index36.js +18 -82
- package/dist/index36.js.map +1 -1
- package/dist/index37.js +8 -58
- package/dist/index37.js.map +1 -1
- package/dist/index38.js +4 -13
- package/dist/index38.js.map +1 -1
- package/dist/index39.js +10 -18
- package/dist/index39.js.map +1 -1
- package/dist/index4.js +25 -5
- package/dist/index4.js.map +1 -1
- package/dist/index40.js +7 -0
- package/dist/index40.js.map +1 -0
- package/dist/index41.js +3690 -0
- package/dist/index41.js.map +1 -0
- package/dist/index42.js +187 -0
- package/dist/index42.js.map +1 -0
- package/dist/index43.js +504 -0
- package/dist/index43.js.map +1 -0
- package/dist/index44.js +77 -0
- package/dist/index44.js.map +1 -0
- package/dist/index45.js +6 -0
- package/dist/index45.js.map +1 -0
- package/dist/index46.js +20 -0
- package/dist/index46.js.map +1 -0
- package/dist/index47.js +146 -0
- package/dist/index47.js.map +1 -0
- package/dist/index48.js +12 -0
- package/dist/index48.js.map +1 -0
- package/dist/index49.js +113 -0
- package/dist/index49.js.map +1 -0
- package/dist/index5.js +2 -1
- package/dist/index5.js.map +1 -1
- package/dist/index50.js +136 -0
- package/dist/index50.js.map +1 -0
- package/dist/index51.js +137 -0
- package/dist/index51.js.map +1 -0
- package/dist/index52.js +112 -0
- package/dist/index52.js.map +1 -0
- package/dist/index53.js +141 -0
- package/dist/index53.js.map +1 -0
- package/dist/index54.js +9 -0
- package/dist/index54.js.map +1 -0
- package/dist/index55.js +54 -0
- package/dist/index55.js.map +1 -0
- package/dist/index6.js +1 -1
- package/dist/index6.js.map +1 -1
- package/dist/index7.js +11 -3
- package/dist/index7.js.map +1 -1
- package/dist/index8.js +68 -7
- package/dist/index8.js.map +1 -1
- package/dist/index9.js +278 -15
- package/dist/index9.js.map +1 -1
- package/dist/presets/animation.d.ts +31 -0
- package/dist/presets/faceset.d.ts +30 -0
- package/dist/presets/index.d.ts +103 -0
- package/dist/presets/lpc.d.ts +89 -0
- package/dist/services/keyboardControls.d.ts +5 -0
- package/dist/services/loadMap.d.ts +123 -2
- package/dist/services/mmorpg.d.ts +12 -4
- package/dist/services/standalone.d.ts +54 -2
- package/package.json +22 -18
- package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
- package/src/Game/Map.ts +20 -2
- package/src/Game/Object.ts +163 -9
- package/src/Gui/Gui.ts +362 -17
- package/src/Resource.ts +150 -0
- package/src/RpgClient.ts +264 -58
- package/src/RpgClientEngine.ts +848 -36
- package/src/Sound.ts +253 -0
- package/src/components/{effects → animations}/animation.ce +3 -6
- package/src/components/{effects → animations}/index.ts +1 -1
- package/src/components/character.ce +193 -36
- package/src/components/dynamics/parse-value.ts +80 -0
- package/src/components/dynamics/text.ce +183 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +73 -35
- package/src/components/gui/dialogbox/selection.ce +16 -1
- package/src/components/gui/index.ts +3 -4
- package/src/components/index.ts +5 -1
- package/src/components/prebuilt/hp-bar.ce +255 -0
- package/src/components/prebuilt/index.ts +22 -0
- package/src/components/scenes/canvas.ce +12 -10
- package/src/components/scenes/draw-map.ce +6 -23
- package/src/components/scenes/event-layer.ce +9 -3
- package/src/core/setup.ts +2 -0
- package/src/index.ts +7 -2
- package/src/module.ts +72 -6
- package/src/presets/animation.ts +46 -0
- package/src/presets/faceset.ts +60 -0
- package/src/presets/index.ts +7 -1
- package/src/presets/lpc.ts +108 -0
- package/src/services/keyboardControls.ts +8 -0
- package/src/services/loadMap.ts +132 -3
- package/src/services/mmorpg.ts +29 -5
- package/src/services/standalone.ts +70 -6
- package/tsconfig.json +1 -1
- package/vite.config.ts +1 -1
- package/dist/Game/EffectManager.d.ts +0 -5
- package/dist/components/effects/index.d.ts +0 -4
- package/src/components/scenes/element-map.ce +0 -23
- /package/src/components/{effects → animations}/hit.ce +0 -0
package/dist/index22.js
CHANGED
|
@@ -1,109 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const WebSocketToken = "websocket";
|
|
2
|
+
class AbstractWebsocket {
|
|
3
|
+
constructor(context) {
|
|
4
|
+
this.context = context;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
useProps($$props);
|
|
8
|
-
const defineProps = useDefineProps($$props);
|
|
9
|
-
var _a = defineProps(), message = _a.message, _choices = _a.choices, onFinish = _a.onFinish; _a.onInteraction;
|
|
10
|
-
var client = inject(RpgClientEngine);
|
|
11
|
-
var keyboardControls = client.globalConfig.keyboardControls;
|
|
12
|
-
client.stopProcessingInput = true;
|
|
13
|
-
var isDestroyed = false;
|
|
14
|
-
var texts = [message()];
|
|
15
|
-
var height = signal(250);
|
|
16
|
-
var isTextCompleted = signal(false);
|
|
17
|
-
var border = signal({ width: 5, color: "#595971" });
|
|
18
|
-
var shadow = signal({ color: "#000", blur: 10, offsetX: 10, offsetY: 10 });
|
|
19
|
-
var contentOpacity = animatedSignal(0, {
|
|
20
|
-
duration: 1000,
|
|
21
|
-
});
|
|
22
|
-
var scaleX = animatedSignal(0, {
|
|
23
|
-
duration: 500,
|
|
24
|
-
});
|
|
25
|
-
scaleX.set(1);
|
|
26
|
-
contentOpacity.set(1);
|
|
27
|
-
var currentTextIndex = signal(0);
|
|
28
|
-
var currentText = computed(function () { var _a; return (_a = texts === null || texts === void 0 ? void 0 : texts[currentTextIndex()]) !== null && _a !== void 0 ? _a : ''; });
|
|
29
|
-
var isChoiceDisplayed = signal(false);
|
|
30
|
-
var text = computed(function () {
|
|
31
|
-
var current = currentText();
|
|
32
|
-
return typeof current === "string" ? current : current.text;
|
|
33
|
-
});
|
|
34
|
-
var choices = computed(function () {
|
|
35
|
-
//const current = currentText();
|
|
36
|
-
//return typeof current === "string" ? null : current.choices;
|
|
37
|
-
return _choices;
|
|
38
|
-
});
|
|
39
|
-
var visibleSelection = computed(function () { return isChoiceDisplayed() && choices().length != 0; });
|
|
40
|
-
var triggerSkip = trigger();
|
|
41
|
-
var typewriter = {
|
|
42
|
-
speed: 0.3,
|
|
43
|
-
skip: triggerSkip,
|
|
44
|
-
onComplete: function () {
|
|
45
|
-
isTextCompleted.set(true);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var textStyle = {
|
|
49
|
-
wordWrap: true,
|
|
50
|
-
wordWrapWidth: 700 - 256 - 80
|
|
51
|
-
};
|
|
52
|
-
signal({ x: 0, y: 0, width: 256, height: 256 });
|
|
53
|
-
mount(function (element) {
|
|
54
|
-
var dialogbox = element.props.children[0];
|
|
55
|
-
return function () {
|
|
56
|
-
dialogbox.directives.controls.onDestroy();
|
|
57
|
-
isDestroyed = true;
|
|
58
|
-
// Wait destroy is finished before start processing input
|
|
59
|
-
setTimeout(function () {
|
|
60
|
-
client.stopProcessingInput = false;
|
|
61
|
-
}, 500);
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
var controls = signal({
|
|
65
|
-
next: {
|
|
66
|
-
bind: keyboardControls.action,
|
|
67
|
-
keyDown: function (e) {
|
|
68
|
-
if (isDestroyed)
|
|
69
|
-
return;
|
|
70
|
-
if (isChoiceDisplayed()) {
|
|
71
|
-
// If choices are displayed, do nothing (wait for selection)
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
// If text is still typing, just skip (fast forward) the animation
|
|
75
|
-
if (!isTextCompleted()) {
|
|
76
|
-
triggerSkip.start();
|
|
77
|
-
isTextCompleted.set(true);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
var isFinished = currentTextIndex() === texts.length - 1;
|
|
81
|
-
currentTextIndex.update(function (index) {
|
|
82
|
-
if (index < texts.length - 1) {
|
|
83
|
-
return index + 1;
|
|
84
|
-
}
|
|
85
|
-
return index;
|
|
86
|
-
});
|
|
87
|
-
isChoiceDisplayed.set(false);
|
|
88
|
-
isTextCompleted.set(false);
|
|
89
|
-
if (isFinished && onFinish) {
|
|
90
|
-
onFinish();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
var onSelect = function (index) {
|
|
97
|
-
onFinish(index);
|
|
98
|
-
};
|
|
99
|
-
effect(function () {
|
|
100
|
-
if (choices().length != 0) {
|
|
101
|
-
isChoiceDisplayed.set(true);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
let $this = h(Container, { justifyContent: 'center', alignItems: 'center', width: '100%', height: '100%' }, h(Container, { ref: 'dialogbox', scale: { x: scaleX }, anchor: [0.5, 0.5], width: 700, height, controls, positionType: 'absolute', bottom: 10 }, [h(Rect, { width: 700, height: 250, color: '#1a1a2e' }), h(Rect, { x: 0, y: 0, width: 700, height, color: '#1a1a2e', alpha: 0.9, borderRadius: 10, border, shadow }), h(Container, { flexDirection: 'row', width: 700, height, alpha: contentOpacity }, h(Container, { flexDirection: 'column' }, [h(Text, { text, color: '#fff', fontSize: 18, margin: 40, typewriter, style: textStyle }), cond(visibleSelection, () => h(component$1, { selectedIndex: 0, items: choices, onSelect }))]))]));
|
|
105
|
-
return $this
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export { component as default };
|
|
8
|
+
export { AbstractWebsocket, WebSocketToken };
|
|
109
9
|
//# sourceMappingURL=index22.js.map
|
package/dist/index22.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index22.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index22.js","sources":["../src/services/AbstractSocket.ts"],"sourcesContent":["import { Context } from \"@signe/di\";\n\nexport const WebSocketToken = \"websocket\";\n\nexport abstract class AbstractWebsocket {\n constructor(protected context: Context) {}\n\n abstract connection(listeners?: (data: any) => void): Promise<void>;\n abstract emit(event: string, data: any): void;\n abstract on(event: string, callback: (data: any) => void): void;\n abstract off(event: string, callback: (data: any) => void): void;\n abstract updateProperties(params: { room: string, host?: string }): void;\n abstract reconnect(listeners?: (data: any) => void): void;\n}\n"],"names":[],"mappings":"AAEO,MAAM,cAAA,GAAiB;AAEvB,MAAe,iBAAA,CAAkB;AAAA,EACtC,YAAsB,OAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA,EAAmB;AAQ3C;;;;"}
|
package/dist/index23.js
CHANGED
|
@@ -1,71 +1,400 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { __name } from './index34.js';
|
|
2
|
+
import { isSignal, isComputed, isObjectSubject, isArraySubject } from './index35.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
4
|
+
// src/utils.ts
|
|
5
|
+
function isFunction(val) {
|
|
6
|
+
return {}.toString.call(val) === "[object Function]";
|
|
7
|
+
}
|
|
8
|
+
__name(isFunction, "isFunction");
|
|
9
|
+
function isClass(obj) {
|
|
10
|
+
return typeof obj === "function" && obj.prototype && obj.prototype.constructor === obj;
|
|
11
|
+
}
|
|
12
|
+
__name(isClass, "isClass");
|
|
13
|
+
var isObject = /* @__PURE__ */ __name((item) => item && typeof item === "object" && !Array.isArray(item) && item !== null, "isObject");
|
|
14
|
+
function isInstanceOfClass(value) {
|
|
15
|
+
if (value === null || typeof value !== "object" || value === void 0 || Array.isArray(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return Object.getPrototypeOf(value) !== Object.prototype;
|
|
19
|
+
}
|
|
20
|
+
__name(isInstanceOfClass, "isInstanceOfClass");
|
|
21
|
+
function generateShortUUID() {
|
|
22
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
23
|
+
let uuid = "";
|
|
24
|
+
for (let i = 0; i < 8; i++) {
|
|
25
|
+
const randomIndex = Math.floor(Math.random() * chars.length);
|
|
26
|
+
uuid += chars[randomIndex];
|
|
27
|
+
}
|
|
28
|
+
return uuid;
|
|
29
|
+
}
|
|
30
|
+
__name(generateShortUUID, "generateShortUUID");
|
|
31
|
+
|
|
32
|
+
// src/core.ts
|
|
33
|
+
var DELETE_TOKEN = "$delete";
|
|
34
|
+
var syncClass = /* @__PURE__ */ __name((instance, options = {}) => {
|
|
35
|
+
const cacheSync = /* @__PURE__ */ new Map();
|
|
36
|
+
const cachePersist = /* @__PURE__ */ new Map();
|
|
37
|
+
instance.$valuesChanges = {
|
|
38
|
+
set: /* @__PURE__ */ __name((path, value) => {
|
|
39
|
+
cacheSync.set(path, value);
|
|
40
|
+
options.onSync?.(cacheSync);
|
|
41
|
+
}, "set"),
|
|
42
|
+
setPersist: /* @__PURE__ */ __name((path, value) => {
|
|
43
|
+
if (path == "") path = ".";
|
|
44
|
+
cachePersist.set(path, value);
|
|
45
|
+
options.onPersist?.(cachePersist);
|
|
46
|
+
}, "setPersist"),
|
|
47
|
+
has: /* @__PURE__ */ __name((path) => {
|
|
48
|
+
return cacheSync.has(path);
|
|
49
|
+
}, "has"),
|
|
50
|
+
get: /* @__PURE__ */ __name((path) => {
|
|
51
|
+
return cacheSync.get(path);
|
|
52
|
+
}, "get")
|
|
53
|
+
};
|
|
54
|
+
createSyncClass(instance);
|
|
55
|
+
}, "syncClass");
|
|
56
|
+
function createStatesSnapshot(instance) {
|
|
57
|
+
let persistObject = {};
|
|
58
|
+
if (instance?.$snapshot) {
|
|
59
|
+
for (const key of instance.$snapshot.keys()) {
|
|
60
|
+
const signal = instance.$snapshot.get(key);
|
|
61
|
+
const persist2 = signal.options.persist ?? true;
|
|
62
|
+
let value = signal();
|
|
63
|
+
if (isObject(value) || Array.isArray(value)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (persist2) {
|
|
67
|
+
persistObject[key] = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return persistObject;
|
|
72
|
+
}
|
|
73
|
+
__name(createStatesSnapshot, "createStatesSnapshot");
|
|
74
|
+
function setMetadata(target, key, value) {
|
|
75
|
+
const meta = target.constructor._propertyMetadata;
|
|
76
|
+
const propId = meta?.get(key);
|
|
77
|
+
if (propId) {
|
|
78
|
+
if (isSignal(target[propId])) {
|
|
79
|
+
target[propId].set(value);
|
|
80
|
+
} else {
|
|
81
|
+
target[propId] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
__name(setMetadata, "setMetadata");
|
|
86
|
+
var createSyncClass = /* @__PURE__ */ __name((currentClass, parentKey = null, parentClass = null, path = "") => {
|
|
87
|
+
currentClass.$path = path;
|
|
88
|
+
if (parentClass) {
|
|
89
|
+
currentClass.$valuesChanges = parentClass.$valuesChanges;
|
|
90
|
+
}
|
|
91
|
+
if (parentKey) {
|
|
92
|
+
setMetadata(currentClass, "id", parentKey);
|
|
93
|
+
}
|
|
94
|
+
if (currentClass.$snapshot) {
|
|
95
|
+
for (const key of currentClass.$snapshot.keys()) {
|
|
96
|
+
const signal = currentClass.$snapshot.get(key);
|
|
97
|
+
const syncToClient = signal.options?.syncToClient ?? true;
|
|
98
|
+
const persist2 = signal.options?.persist ?? true;
|
|
99
|
+
const transform = signal.options?.transform;
|
|
100
|
+
let signalValue = signal();
|
|
101
|
+
if (transform) {
|
|
102
|
+
signalValue = transform(signalValue);
|
|
103
|
+
}
|
|
104
|
+
if (isObject(signalValue) || Array.isArray(signalValue)) {
|
|
105
|
+
signalValue = {
|
|
106
|
+
...signalValue
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const transformedValue = signalValue;
|
|
110
|
+
const newPath = (path ? path + "." : "") + key;
|
|
111
|
+
if (syncToClient) {
|
|
112
|
+
currentClass.$valuesChanges.set(newPath, transformedValue);
|
|
113
|
+
}
|
|
114
|
+
if (persist2) {
|
|
115
|
+
if (parentClass) currentClass.$valuesChanges.setPersist(path, transformedValue);
|
|
116
|
+
}
|
|
117
|
+
if (isComputed(signal)) {
|
|
118
|
+
signal.observable.subscribe((newValue) => {
|
|
119
|
+
if (syncToClient) {
|
|
120
|
+
const transformedNewValue = transform ? transform(newValue) : newValue;
|
|
121
|
+
currentClass.$valuesChanges.set(newPath, transformedNewValue);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}, "createSyncClass");
|
|
128
|
+
var type = /* @__PURE__ */ __name((_signal, path, options = {}, currentInstance) => {
|
|
129
|
+
const { syncToClient = true, persist: persist2 = true, transform } = options;
|
|
130
|
+
let init = true;
|
|
131
|
+
const handleObjectSubject = /* @__PURE__ */ __name((value, propPath) => {
|
|
132
|
+
const newPath = `${propPath}${value.key ? `.${value.key}` : ""}`;
|
|
133
|
+
if ([
|
|
134
|
+
"add",
|
|
135
|
+
"reset",
|
|
136
|
+
"update"
|
|
137
|
+
].includes(value.type)) {
|
|
138
|
+
if (isInstanceOfClass(value.value)) {
|
|
139
|
+
createSyncClass(value.value, value.key, currentInstance, newPath);
|
|
140
|
+
} else if (value.type === "update" && (isObject(value.value) || Array.isArray(value.value))) {
|
|
141
|
+
createSyncClass(value.value, value.key, currentInstance, newPath);
|
|
142
|
+
} else {
|
|
143
|
+
savePath(newPath, value.value);
|
|
144
|
+
}
|
|
145
|
+
} else if (value.type === "remove") {
|
|
146
|
+
savePath(newPath, DELETE_TOKEN);
|
|
147
|
+
}
|
|
148
|
+
}, "handleObjectSubject");
|
|
149
|
+
const handleArraySubject = /* @__PURE__ */ __name((value, propPath) => {
|
|
150
|
+
if (value.type === "reset" && Array.isArray(value.items)) {
|
|
151
|
+
value.items.forEach((item, index) => {
|
|
152
|
+
const newPath2 = `${propPath}.${index}`;
|
|
153
|
+
if (isInstanceOfClass(item)) {
|
|
154
|
+
createSyncClass(item, value.key, currentInstance, newPath2);
|
|
155
|
+
} else {
|
|
156
|
+
savePath(newPath2, item);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const newPath = `${propPath}.${value.index}`;
|
|
162
|
+
const firstItem = value.items?.[0];
|
|
163
|
+
if ([
|
|
164
|
+
"add",
|
|
165
|
+
"update"
|
|
166
|
+
].includes(value.type) && firstItem !== void 0) {
|
|
167
|
+
if (isInstanceOfClass(firstItem)) {
|
|
168
|
+
createSyncClass(firstItem, value.key, currentInstance, newPath);
|
|
169
|
+
} else if (value.type === "update" && (isObject(firstItem) || Array.isArray(firstItem))) {
|
|
170
|
+
createSyncClass(firstItem, value.key, currentInstance, newPath);
|
|
171
|
+
} else {
|
|
172
|
+
savePath(newPath, firstItem);
|
|
173
|
+
}
|
|
174
|
+
} else if (value.type === "remove") {
|
|
175
|
+
savePath(newPath, DELETE_TOKEN);
|
|
176
|
+
}
|
|
177
|
+
}, "handleArraySubject");
|
|
178
|
+
const savePath = /* @__PURE__ */ __name((propPath, value) => {
|
|
179
|
+
const transformedValue = transform && value !== DELETE_TOKEN ? transform(value) : value;
|
|
180
|
+
if (syncToClient) {
|
|
181
|
+
currentInstance.$valuesChanges.set(propPath, transformedValue);
|
|
182
|
+
}
|
|
183
|
+
if (persist2 && currentInstance.$path !== void 0) {
|
|
184
|
+
currentInstance.$valuesChanges.setPersist(transformedValue == DELETE_TOKEN ? propPath : currentInstance.$path, transformedValue);
|
|
185
|
+
}
|
|
186
|
+
}, "savePath");
|
|
187
|
+
const setupSubscription = /* @__PURE__ */ __name((signal, signalPath) => {
|
|
188
|
+
if (!isSignal(signal)) return;
|
|
189
|
+
if (syncToClient && currentInstance.$valuesChanges) {
|
|
190
|
+
const initialValue = signal();
|
|
191
|
+
const transformedInitialValue = transform ? transform(initialValue) : initialValue;
|
|
192
|
+
currentInstance.$valuesChanges.set(signalPath, transformedInitialValue);
|
|
193
|
+
}
|
|
194
|
+
signal.options = options;
|
|
195
|
+
signal.observable.subscribe((value) => {
|
|
196
|
+
if (init) return;
|
|
197
|
+
if (currentInstance.$path !== void 0) {
|
|
198
|
+
const fullPath = `${currentInstance.$path ? currentInstance.$path + "." : ""}${signalPath}`;
|
|
199
|
+
if (isComputed(signal)) {
|
|
200
|
+
savePath(fullPath, value);
|
|
201
|
+
} else if (isObjectSubject(signal._subject)) {
|
|
202
|
+
handleObjectSubject(value, fullPath);
|
|
203
|
+
} else if (isArraySubject(signal._subject)) {
|
|
204
|
+
handleArraySubject(value, fullPath);
|
|
205
|
+
} else {
|
|
206
|
+
savePath(fullPath, value);
|
|
63
207
|
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
if (!currentInstance.$snapshot) {
|
|
211
|
+
currentInstance.$snapshot = /* @__PURE__ */ new Map();
|
|
64
212
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
213
|
+
currentInstance.$snapshot.set(path, signal);
|
|
214
|
+
}, "setupSubscription");
|
|
215
|
+
if (!isSignal(_signal)) {
|
|
216
|
+
if (_signal && typeof _signal === "object" && !Array.isArray(_signal)) {
|
|
217
|
+
for (const key in _signal) {
|
|
218
|
+
if (Object.prototype.hasOwnProperty.call(_signal, key)) {
|
|
219
|
+
const value = _signal[key];
|
|
220
|
+
const propertyPath = `${path}.${key}`;
|
|
221
|
+
if (isSignal(value)) {
|
|
222
|
+
setupSubscription(value, propertyPath);
|
|
223
|
+
} else if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
224
|
+
type(value, propertyPath, options, currentInstance);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
68
227
|
}
|
|
228
|
+
init = false;
|
|
229
|
+
}
|
|
230
|
+
return _signal;
|
|
231
|
+
}
|
|
232
|
+
setupSubscription(_signal, path);
|
|
233
|
+
init = false;
|
|
234
|
+
return _signal;
|
|
235
|
+
}, "type");
|
|
236
|
+
|
|
237
|
+
// src/decorators.ts
|
|
238
|
+
function sync(options) {
|
|
239
|
+
let classType;
|
|
240
|
+
let persist2 = true;
|
|
241
|
+
let syncToClient = true;
|
|
242
|
+
let transform;
|
|
243
|
+
if (typeof options === "function") {
|
|
244
|
+
classType = options;
|
|
245
|
+
} else if (typeof options === "object") {
|
|
246
|
+
classType = options.classType;
|
|
247
|
+
if (options.hasOwnProperty("persist")) {
|
|
248
|
+
persist2 = options.persist;
|
|
249
|
+
}
|
|
250
|
+
if (options.hasOwnProperty("syncToClient")) {
|
|
251
|
+
syncToClient = options.syncToClient;
|
|
252
|
+
}
|
|
253
|
+
if (options.hasOwnProperty("transform")) {
|
|
254
|
+
transform = options.transform;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return function(target, propertyKey) {
|
|
258
|
+
const privatePropertyKey = `__${propertyKey}`;
|
|
259
|
+
const getter = /* @__PURE__ */ __name(function() {
|
|
260
|
+
return this[privatePropertyKey];
|
|
261
|
+
}, "getter");
|
|
262
|
+
const setter = /* @__PURE__ */ __name(function(newVal) {
|
|
263
|
+
this[privatePropertyKey] = type(newVal, propertyKey, {
|
|
264
|
+
classType,
|
|
265
|
+
persist: persist2,
|
|
266
|
+
syncToClient,
|
|
267
|
+
transform
|
|
268
|
+
}, this);
|
|
269
|
+
}, "setter");
|
|
270
|
+
Object.defineProperty(target, propertyKey, {
|
|
271
|
+
get: getter,
|
|
272
|
+
set: setter,
|
|
273
|
+
enumerable: true,
|
|
274
|
+
configurable: true
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
__name(sync, "sync");
|
|
279
|
+
function id() {
|
|
280
|
+
return function(target, propertyKey) {
|
|
281
|
+
if (!target.constructor._propertyMetadata) {
|
|
282
|
+
target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
|
|
283
|
+
}
|
|
284
|
+
target.constructor._propertyMetadata.set("id", propertyKey);
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
__name(id, "id");
|
|
288
|
+
function users(options) {
|
|
289
|
+
return function(target, propertyKey) {
|
|
290
|
+
if (!target.constructor._propertyMetadata) {
|
|
291
|
+
target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
|
|
292
|
+
}
|
|
293
|
+
target.constructor._propertyMetadata.set("users", propertyKey);
|
|
294
|
+
sync(options)(target, propertyKey);
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
__name(users, "users");
|
|
298
|
+
function persist() {
|
|
299
|
+
return sync({
|
|
300
|
+
persist: true,
|
|
301
|
+
syncToClient: false
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
__name(persist, "persist");
|
|
305
|
+
function connected() {
|
|
306
|
+
return function(target, propertyKey) {
|
|
307
|
+
if (!target.constructor._propertyMetadata) {
|
|
308
|
+
target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
|
|
309
|
+
}
|
|
310
|
+
target.constructor._propertyMetadata.set("connected", propertyKey);
|
|
311
|
+
sync({
|
|
312
|
+
persist: false
|
|
313
|
+
})(target, propertyKey);
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
__name(connected, "connected");
|
|
317
|
+
function load(rootInstance, values, valueIsObject) {
|
|
318
|
+
if (valueIsObject) {
|
|
319
|
+
loadFromObject(rootInstance, values);
|
|
320
|
+
} else {
|
|
321
|
+
loadFromPaths(rootInstance, values);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
__name(load, "load");
|
|
325
|
+
function loadFromPaths(rootInstance, values) {
|
|
326
|
+
for (const [path, value] of Object.entries(values)) {
|
|
327
|
+
const parts = path.split(".");
|
|
328
|
+
loadValue(rootInstance, parts, value);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
__name(loadFromPaths, "loadFromPaths");
|
|
332
|
+
function loadFromObject(rootInstance, values, currentPath = "") {
|
|
333
|
+
for (let key in values) {
|
|
334
|
+
const value = values[key];
|
|
335
|
+
const newPath = currentPath ? `${currentPath}.${key}` : key;
|
|
336
|
+
if (typeof value === "object" && !Array.isArray(value) && value !== null) {
|
|
337
|
+
loadFromObject(rootInstance, value, newPath);
|
|
338
|
+
} else {
|
|
339
|
+
const parts = newPath.split(".");
|
|
340
|
+
loadValue(rootInstance, parts, value);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
__name(loadFromObject, "loadFromObject");
|
|
345
|
+
function loadValue(rootInstance, parts, value) {
|
|
346
|
+
let current = rootInstance;
|
|
347
|
+
for (let i = 0; i < parts.length; i++) {
|
|
348
|
+
const part = parts[i];
|
|
349
|
+
if (i === parts.length - 1) {
|
|
350
|
+
if (value == DELETE_TOKEN) {
|
|
351
|
+
if (isSignal(current)) {
|
|
352
|
+
current = current();
|
|
353
|
+
}
|
|
354
|
+
Reflect.deleteProperty(current, part);
|
|
355
|
+
} else if (current[part]?._subject) {
|
|
356
|
+
current[part].set(value);
|
|
357
|
+
} else if (isSignal(current) && Array.isArray(current()) && !isNaN(Number(part))) {
|
|
358
|
+
current()[Number(part)] = value;
|
|
359
|
+
} else {
|
|
360
|
+
current[part] = value;
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
if (isSignal(current)) {
|
|
364
|
+
current = current();
|
|
365
|
+
}
|
|
366
|
+
const currentValue = current[part];
|
|
367
|
+
if (currentValue === void 0) {
|
|
368
|
+
const parentInstance = getByPath(rootInstance, parts.slice(0, i).join("."));
|
|
369
|
+
const classType = parentInstance?.options?.classType;
|
|
370
|
+
if (classType) {
|
|
371
|
+
current[part] = !isClass(classType) ? classType(part) : new classType();
|
|
372
|
+
setMetadata(current[part], "id", part);
|
|
373
|
+
} else {
|
|
374
|
+
current[part] = {};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
current = current[part];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
__name(loadValue, "loadValue");
|
|
382
|
+
function getByPath(root, path) {
|
|
383
|
+
const parts = path.split(".");
|
|
384
|
+
let current = root;
|
|
385
|
+
for (const part of parts) {
|
|
386
|
+
if (isSignal(current)) {
|
|
387
|
+
current = current();
|
|
388
|
+
}
|
|
389
|
+
if (current[part]) {
|
|
390
|
+
current = current[part];
|
|
391
|
+
} else {
|
|
392
|
+
return void 0;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return current;
|
|
396
|
+
}
|
|
397
|
+
__name(getByPath, "getByPath");
|
|
69
398
|
|
|
70
|
-
export {
|
|
399
|
+
export { DELETE_TOKEN, connected, createStatesSnapshot, createSyncClass, generateShortUUID, getByPath, id, isClass, isFunction, isInstanceOfClass, isObject, load, persist, setMetadata, sync, syncClass, type, users };
|
|
71
400
|
//# sourceMappingURL=index23.js.map
|