@razaman2/reactive-view 0.0.34-beta.1 → 0.0.34-beta.11
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/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +79 -35
- package/dist/index.mjs +79 -36
- package/package.json +47 -46
package/dist/index.d.mts
CHANGED
|
@@ -53,7 +53,9 @@ declare const _default: {
|
|
|
53
53
|
notifications: ObjectConstructor;
|
|
54
54
|
subscriptions: ObjectConstructor;
|
|
55
55
|
beforeSetData: FunctionConstructor;
|
|
56
|
-
data: {
|
|
56
|
+
data: {
|
|
57
|
+
default: () => {};
|
|
58
|
+
};
|
|
57
59
|
defaultData: {};
|
|
58
60
|
getDefaultData: {
|
|
59
61
|
type: FunctionConstructor;
|
|
@@ -72,6 +74,7 @@ declare const _default: {
|
|
|
72
74
|
type: BooleanConstructor;
|
|
73
75
|
default: boolean;
|
|
74
76
|
};
|
|
77
|
+
state: {};
|
|
75
78
|
};
|
|
76
79
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
77
80
|
};
|
|
@@ -115,5 +118,8 @@ declare function useSubscription(): {
|
|
|
115
118
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
116
119
|
declare function MergeStyles(...params: any): any;
|
|
117
120
|
declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
|
|
121
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
122
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
123
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
118
124
|
|
|
119
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
125
|
+
export { MergeStyles, StyleParser, access, dataPath, _default as default, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, useSubscription };
|
package/dist/index.d.ts
CHANGED
|
@@ -53,7 +53,9 @@ declare const _default: {
|
|
|
53
53
|
notifications: ObjectConstructor;
|
|
54
54
|
subscriptions: ObjectConstructor;
|
|
55
55
|
beforeSetData: FunctionConstructor;
|
|
56
|
-
data: {
|
|
56
|
+
data: {
|
|
57
|
+
default: () => {};
|
|
58
|
+
};
|
|
57
59
|
defaultData: {};
|
|
58
60
|
getDefaultData: {
|
|
59
61
|
type: FunctionConstructor;
|
|
@@ -72,6 +74,7 @@ declare const _default: {
|
|
|
72
74
|
type: BooleanConstructor;
|
|
73
75
|
default: boolean;
|
|
74
76
|
};
|
|
77
|
+
state: {};
|
|
75
78
|
};
|
|
76
79
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
77
80
|
};
|
|
@@ -115,5 +118,8 @@ declare function useSubscription(): {
|
|
|
115
118
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
116
119
|
declare function MergeStyles(...params: any): any;
|
|
117
120
|
declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
|
|
121
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
122
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
123
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
118
124
|
|
|
119
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
125
|
+
export { MergeStyles, StyleParser, access, dataPath, _default as default, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, useSubscription };
|
package/dist/index.js
CHANGED
|
@@ -59,16 +59,20 @@ __export(index_exports, {
|
|
|
59
59
|
MergeStyles: () => MergeStyles,
|
|
60
60
|
StyleParser: () => StyleParser,
|
|
61
61
|
access: () => access,
|
|
62
|
+
dataPath: () => dataPath,
|
|
62
63
|
default: () => index_default,
|
|
63
64
|
extendVnode: () => extendVnode,
|
|
65
|
+
getData: () => getData,
|
|
64
66
|
getDate: () => getDate,
|
|
65
67
|
getProps: () => getProps,
|
|
66
68
|
getReactiveViewComponent: () => getReactiveViewComponent,
|
|
67
69
|
safeRequest: () => safeRequest,
|
|
70
|
+
setData: () => setData,
|
|
68
71
|
setup: () => setup,
|
|
69
72
|
useSubscription: () => useSubscription
|
|
70
73
|
});
|
|
71
74
|
module.exports = __toCommonJS(index_exports);
|
|
75
|
+
var import_object_manager2 = __toESM(require("@razaman2/object-manager"));
|
|
72
76
|
|
|
73
77
|
// src/Subscription.ts
|
|
74
78
|
var Subscription = class _Subscription {
|
|
@@ -168,7 +172,7 @@ var import_vue = require("vue");
|
|
|
168
172
|
|
|
169
173
|
// package.json
|
|
170
174
|
var name = "@razaman2/reactive-view";
|
|
171
|
-
var version = "0.0.34-beta.
|
|
175
|
+
var version = "0.0.34-beta.11";
|
|
172
176
|
|
|
173
177
|
// src/ReactiveView.ts
|
|
174
178
|
var setup = {
|
|
@@ -189,7 +193,9 @@ var ReactiveView_default = {
|
|
|
189
193
|
notifications: Object,
|
|
190
194
|
subscriptions: Object,
|
|
191
195
|
beforeSetData: Function,
|
|
192
|
-
data: {
|
|
196
|
+
data: {
|
|
197
|
+
default: () => ({})
|
|
198
|
+
},
|
|
193
199
|
defaultData: {},
|
|
194
200
|
getDefaultData: {
|
|
195
201
|
type: Function,
|
|
@@ -209,10 +215,27 @@ var ReactiveView_default = {
|
|
|
209
215
|
debug: {
|
|
210
216
|
type: Boolean,
|
|
211
217
|
default: false
|
|
212
|
-
}
|
|
218
|
+
},
|
|
219
|
+
state: {}
|
|
213
220
|
},
|
|
214
221
|
setup(props, context) {
|
|
215
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
222
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
223
|
+
const diff = (before, after) => {
|
|
224
|
+
const change = after.paths().reduce((change2, path) => {
|
|
225
|
+
if (before.get(path) !== after.get(path)) {
|
|
226
|
+
change2.set(path, after.get(path));
|
|
227
|
+
}
|
|
228
|
+
return change2;
|
|
229
|
+
}, import_object_manager.default.on({}));
|
|
230
|
+
return { before: before.get(), after: after.get(), change: change.get() };
|
|
231
|
+
};
|
|
232
|
+
const dataPath2 = (path) => {
|
|
233
|
+
try {
|
|
234
|
+
return context.attrs["data:path"](path);
|
|
235
|
+
} catch (e) {
|
|
236
|
+
return path;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
216
239
|
const template = (component2, vue2) => {
|
|
217
240
|
return (0, import_vue.createVNode)(
|
|
218
241
|
"div",
|
|
@@ -224,14 +247,11 @@ var ReactiveView_default = {
|
|
|
224
247
|
};
|
|
225
248
|
const isValid = (0, import_vue.ref)(false);
|
|
226
249
|
const isReady = (0, import_vue.ref)(false);
|
|
227
|
-
const isFunctionData = ["Function"].includes((
|
|
228
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes((
|
|
229
|
-
const isPromiseData = ["Promise"].includes((
|
|
250
|
+
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
251
|
+
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
252
|
+
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
230
253
|
const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
231
254
|
const vue = (0, import_vue.getCurrentInstance)();
|
|
232
|
-
if (props.debug) {
|
|
233
|
-
console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
234
|
-
}
|
|
235
255
|
if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
|
|
236
256
|
console.error("[ReactiveView]: defaultData is required for promise or async function data.");
|
|
237
257
|
}
|
|
@@ -256,9 +276,11 @@ var ReactiveView_default = {
|
|
|
256
276
|
var _a2;
|
|
257
277
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
258
278
|
if (typeof beforeSetData === "function") {
|
|
259
|
-
const after = import_object_manager.default.on(datatype).set(...params.length ? params : [defaultData]).get();
|
|
260
279
|
const before = target.getData();
|
|
261
|
-
|
|
280
|
+
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
281
|
+
if (beforeSetData(diff(import_object_manager.default.on(before), after), target)) {
|
|
282
|
+
target[key](...params);
|
|
283
|
+
}
|
|
262
284
|
} else {
|
|
263
285
|
target[key](...params);
|
|
264
286
|
}
|
|
@@ -269,21 +291,25 @@ var ReactiveView_default = {
|
|
|
269
291
|
}
|
|
270
292
|
}
|
|
271
293
|
});
|
|
272
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
294
|
+
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, dataPath: dataPath2, isValid } });
|
|
295
|
+
if (props.debug) {
|
|
296
|
+
console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
297
|
+
}
|
|
273
298
|
const watchDataProp = (dataProp) => {
|
|
274
|
-
var _a2, _b2, _c2;
|
|
299
|
+
var _a2, _b2, _c2, _d2;
|
|
275
300
|
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
276
301
|
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
277
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
302
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
303
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
|
|
304
|
+
}, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_d2 = context.attrs["onUpdate:data"]) != null ? _d2 : {}).options)
|
|
278
305
|
};
|
|
279
306
|
if (context.attrs["data:log"]) {
|
|
280
307
|
console.log(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
281
308
|
}
|
|
282
309
|
(0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
283
310
|
var _a3;
|
|
284
|
-
const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
|
|
285
311
|
if (typeof config2.callback === "function") {
|
|
286
|
-
model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
|
|
312
|
+
model.replaceData((_a3 = config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a3 : after);
|
|
287
313
|
} else {
|
|
288
314
|
model.replaceData(after);
|
|
289
315
|
}
|
|
@@ -292,14 +318,15 @@ var ReactiveView_default = {
|
|
|
292
318
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
293
319
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
294
320
|
callback: context.attrs["onUpdate:model"],
|
|
295
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
296
|
-
|
|
321
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
322
|
+
deep: (_g = context.attrs["model:deep"]) != null ? _g : true
|
|
323
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_h = context.attrs["onUpdate:model"]) != null ? _h : {}).options)
|
|
324
|
+
} : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
|
|
297
325
|
if (context.attrs["model:log"]) {
|
|
298
326
|
console.log(`[ReactiveView]:model`, { config: config2 });
|
|
299
327
|
}
|
|
300
328
|
(0, import_vue.watch)(() => model.getData(), (after, before) => {
|
|
301
|
-
|
|
302
|
-
config2.callback(diff, { component });
|
|
329
|
+
config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
303
330
|
}, config2.options);
|
|
304
331
|
}
|
|
305
332
|
setTimeout(async () => {
|
|
@@ -342,6 +369,8 @@ var ReactiveView_default = {
|
|
|
342
369
|
// src/index.ts
|
|
343
370
|
var import_vue2 = require("vue");
|
|
344
371
|
var import_date_fns_tz = require("date-fns-tz");
|
|
372
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
373
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
345
374
|
var index_default = ReactiveView_default;
|
|
346
375
|
function safeRequest(request) {
|
|
347
376
|
return new Promise(async (resolve) => {
|
|
@@ -371,7 +400,7 @@ function safeRequest(request) {
|
|
|
371
400
|
}
|
|
372
401
|
});
|
|
373
402
|
}
|
|
374
|
-
function getProps(props, param2) {
|
|
403
|
+
function getProps(props = {}, param2) {
|
|
375
404
|
var _a;
|
|
376
405
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
377
406
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -416,7 +445,7 @@ function getDate(param1, param2) {
|
|
|
416
445
|
}
|
|
417
446
|
function access(view = {}, alternative) {
|
|
418
447
|
const resolve = (target) => {
|
|
419
|
-
return new Proxy(target, {
|
|
448
|
+
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
420
449
|
get(target2, key) {
|
|
421
450
|
const component = { tree: target2 };
|
|
422
451
|
do {
|
|
@@ -523,36 +552,51 @@ var extendVnode = (component, element) => {
|
|
|
523
552
|
return (props = {}, slots) => {
|
|
524
553
|
var _a;
|
|
525
554
|
const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
526
|
-
const finalClasses =
|
|
555
|
+
const finalClasses = (0, import_tailwind_merge.twMerge)(MergeStyles(typeof props.class === "function" ? props.class(classes) : props.class).string);
|
|
556
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
527
557
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
].includes(key2) && typeof value === "function") {
|
|
532
|
-
props2[key2] = value(vnode.props[key2]);
|
|
558
|
+
var _a2;
|
|
559
|
+
if (!["class", "style"].includes(key2) && typeof value === "function") {
|
|
560
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
533
561
|
}
|
|
534
562
|
return props2;
|
|
535
563
|
}, props);
|
|
536
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
});
|
|
540
|
-
const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
|
|
541
|
-
return (0, import_vue2.h)(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
|
|
564
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
565
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
566
|
+
return (0, import_vue2.h)(["undefined"].includes(typeof element) ? vnode.type : element, finalProps, finalSlots);
|
|
542
567
|
};
|
|
543
568
|
}
|
|
544
569
|
});
|
|
545
570
|
};
|
|
571
|
+
var getData = (component, path, alternative) => {
|
|
572
|
+
if (path) {
|
|
573
|
+
return import_object_manager2.default.on((0, import_vue2.unref)(component.state)).get(dataPath(component, path), alternative);
|
|
574
|
+
} else {
|
|
575
|
+
return import_object_manager2.default.on((0, import_vue2.unref)(component.state)).get();
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
var setData = (component, data, path) => {
|
|
579
|
+
return component.$emit("update:state", {
|
|
580
|
+
before: import_object_manager2.default.on((0, import_vue2.unref)(component.state)).clone(),
|
|
581
|
+
after: path ? import_object_manager2.default.on({}).set(dataPath(component, path), data).get() : data
|
|
582
|
+
});
|
|
583
|
+
};
|
|
584
|
+
var dataPath = (component, path) => {
|
|
585
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
586
|
+
};
|
|
546
587
|
// Annotate the CommonJS export names for ESM import in node:
|
|
547
588
|
0 && (module.exports = {
|
|
548
589
|
MergeStyles,
|
|
549
590
|
StyleParser,
|
|
550
591
|
access,
|
|
592
|
+
dataPath,
|
|
551
593
|
extendVnode,
|
|
594
|
+
getData,
|
|
552
595
|
getDate,
|
|
553
596
|
getProps,
|
|
554
597
|
getReactiveViewComponent,
|
|
555
598
|
safeRequest,
|
|
599
|
+
setData,
|
|
556
600
|
setup,
|
|
557
601
|
useSubscription
|
|
558
602
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -27,6 +27,9 @@ var __objRest = (source, exclude) => {
|
|
|
27
27
|
return target;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
// src/index.ts
|
|
31
|
+
import ObjectManager2 from "@razaman2/object-manager";
|
|
32
|
+
|
|
30
33
|
// src/Subscription.ts
|
|
31
34
|
var Subscription = class _Subscription {
|
|
32
35
|
constructor() {
|
|
@@ -125,7 +128,7 @@ import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstanc
|
|
|
125
128
|
|
|
126
129
|
// package.json
|
|
127
130
|
var name = "@razaman2/reactive-view";
|
|
128
|
-
var version = "0.0.34-beta.
|
|
131
|
+
var version = "0.0.34-beta.11";
|
|
129
132
|
|
|
130
133
|
// src/ReactiveView.ts
|
|
131
134
|
var setup = {
|
|
@@ -146,7 +149,9 @@ var ReactiveView_default = {
|
|
|
146
149
|
notifications: Object,
|
|
147
150
|
subscriptions: Object,
|
|
148
151
|
beforeSetData: Function,
|
|
149
|
-
data: {
|
|
152
|
+
data: {
|
|
153
|
+
default: () => ({})
|
|
154
|
+
},
|
|
150
155
|
defaultData: {},
|
|
151
156
|
getDefaultData: {
|
|
152
157
|
type: Function,
|
|
@@ -166,10 +171,27 @@ var ReactiveView_default = {
|
|
|
166
171
|
debug: {
|
|
167
172
|
type: Boolean,
|
|
168
173
|
default: false
|
|
169
|
-
}
|
|
174
|
+
},
|
|
175
|
+
state: {}
|
|
170
176
|
},
|
|
171
177
|
setup(props, context) {
|
|
172
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
178
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
179
|
+
const diff = (before, after) => {
|
|
180
|
+
const change = after.paths().reduce((change2, path) => {
|
|
181
|
+
if (before.get(path) !== after.get(path)) {
|
|
182
|
+
change2.set(path, after.get(path));
|
|
183
|
+
}
|
|
184
|
+
return change2;
|
|
185
|
+
}, ObjectManager.on({}));
|
|
186
|
+
return { before: before.get(), after: after.get(), change: change.get() };
|
|
187
|
+
};
|
|
188
|
+
const dataPath2 = (path) => {
|
|
189
|
+
try {
|
|
190
|
+
return context.attrs["data:path"](path);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
return path;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
173
195
|
const template = (component2, vue2) => {
|
|
174
196
|
return createVNode(
|
|
175
197
|
"div",
|
|
@@ -181,14 +203,11 @@ var ReactiveView_default = {
|
|
|
181
203
|
};
|
|
182
204
|
const isValid = ref(false);
|
|
183
205
|
const isReady = ref(false);
|
|
184
|
-
const isFunctionData = ["Function"].includes((
|
|
185
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes((
|
|
186
|
-
const isPromiseData = ["Promise"].includes((
|
|
206
|
+
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
207
|
+
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
208
|
+
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
187
209
|
const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
188
210
|
const vue = getCurrentInstance();
|
|
189
|
-
if (props.debug) {
|
|
190
|
-
console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
191
|
-
}
|
|
192
211
|
if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
|
|
193
212
|
console.error("[ReactiveView]: defaultData is required for promise or async function data.");
|
|
194
213
|
}
|
|
@@ -213,9 +232,11 @@ var ReactiveView_default = {
|
|
|
213
232
|
var _a2;
|
|
214
233
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
215
234
|
if (typeof beforeSetData === "function") {
|
|
216
|
-
const after = ObjectManager.on(datatype).set(...params.length ? params : [defaultData]).get();
|
|
217
235
|
const before = target.getData();
|
|
218
|
-
|
|
236
|
+
const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
|
|
237
|
+
if (beforeSetData(diff(ObjectManager.on(before), after), target)) {
|
|
238
|
+
target[key](...params);
|
|
239
|
+
}
|
|
219
240
|
} else {
|
|
220
241
|
target[key](...params);
|
|
221
242
|
}
|
|
@@ -226,21 +247,25 @@ var ReactiveView_default = {
|
|
|
226
247
|
}
|
|
227
248
|
}
|
|
228
249
|
});
|
|
229
|
-
const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
250
|
+
const component = ref({ parent: { self: vue.proxy }, self: { template, model, dataPath: dataPath2, isValid } });
|
|
251
|
+
if (props.debug) {
|
|
252
|
+
console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
253
|
+
}
|
|
230
254
|
const watchDataProp = (dataProp) => {
|
|
231
|
-
var _a2, _b2, _c2;
|
|
255
|
+
var _a2, _b2, _c2, _d2;
|
|
232
256
|
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
233
257
|
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
234
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
258
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
259
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
|
|
260
|
+
}, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_d2 = context.attrs["onUpdate:data"]) != null ? _d2 : {}).options)
|
|
235
261
|
};
|
|
236
262
|
if (context.attrs["data:log"]) {
|
|
237
263
|
console.log(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
238
264
|
}
|
|
239
265
|
watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
240
266
|
var _a3;
|
|
241
|
-
const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
|
|
242
267
|
if (typeof config2.callback === "function") {
|
|
243
|
-
model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
|
|
268
|
+
model.replaceData((_a3 = config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a3 : after);
|
|
244
269
|
} else {
|
|
245
270
|
model.replaceData(after);
|
|
246
271
|
}
|
|
@@ -249,14 +274,15 @@ var ReactiveView_default = {
|
|
|
249
274
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
250
275
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
251
276
|
callback: context.attrs["onUpdate:model"],
|
|
252
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
253
|
-
|
|
277
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
278
|
+
deep: (_g = context.attrs["model:deep"]) != null ? _g : true
|
|
279
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_h = context.attrs["onUpdate:model"]) != null ? _h : {}).options)
|
|
280
|
+
} : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
|
|
254
281
|
if (context.attrs["model:log"]) {
|
|
255
282
|
console.log(`[ReactiveView]:model`, { config: config2 });
|
|
256
283
|
}
|
|
257
284
|
watch(() => model.getData(), (after, before) => {
|
|
258
|
-
|
|
259
|
-
config2.callback(diff, { component });
|
|
285
|
+
config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
|
|
260
286
|
}, config2.options);
|
|
261
287
|
}
|
|
262
288
|
setTimeout(async () => {
|
|
@@ -297,8 +323,10 @@ var ReactiveView_default = {
|
|
|
297
323
|
};
|
|
298
324
|
|
|
299
325
|
// src/index.ts
|
|
300
|
-
import {
|
|
326
|
+
import { h, unref as unref2, isRef as isRef2, toRaw, createVNode as createVNode2 } from "vue";
|
|
301
327
|
import { formatInTimeZone } from "date-fns-tz";
|
|
328
|
+
import { twMerge } from "tailwind-merge";
|
|
329
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
302
330
|
var index_default = ReactiveView_default;
|
|
303
331
|
function safeRequest(request) {
|
|
304
332
|
return new Promise(async (resolve) => {
|
|
@@ -328,7 +356,7 @@ function safeRequest(request) {
|
|
|
328
356
|
}
|
|
329
357
|
});
|
|
330
358
|
}
|
|
331
|
-
function getProps(props, param2) {
|
|
359
|
+
function getProps(props = {}, param2) {
|
|
332
360
|
var _a;
|
|
333
361
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
334
362
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -373,7 +401,7 @@ function getDate(param1, param2) {
|
|
|
373
401
|
}
|
|
374
402
|
function access(view = {}, alternative) {
|
|
375
403
|
const resolve = (target) => {
|
|
376
|
-
return new Proxy(target, {
|
|
404
|
+
return new Proxy(toRaw(target), {
|
|
377
405
|
get(target2, key) {
|
|
378
406
|
const component = { tree: target2 };
|
|
379
407
|
do {
|
|
@@ -480,36 +508,51 @@ var extendVnode = (component, element) => {
|
|
|
480
508
|
return (props = {}, slots) => {
|
|
481
509
|
var _a;
|
|
482
510
|
const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
483
|
-
const finalClasses = MergeStyles(
|
|
511
|
+
const finalClasses = twMerge(MergeStyles(typeof props.class === "function" ? props.class(classes) : props.class).string);
|
|
512
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
484
513
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
].includes(key2) && typeof value === "function") {
|
|
489
|
-
props2[key2] = value(vnode.props[key2]);
|
|
514
|
+
var _a2;
|
|
515
|
+
if (!["class", "style"].includes(key2) && typeof value === "function") {
|
|
516
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
490
517
|
}
|
|
491
518
|
return props2;
|
|
492
519
|
}, props);
|
|
493
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
});
|
|
497
|
-
const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
|
|
498
|
-
return h(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
|
|
520
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
521
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
522
|
+
return h(["undefined"].includes(typeof element) ? vnode.type : element, finalProps, finalSlots);
|
|
499
523
|
};
|
|
500
524
|
}
|
|
501
525
|
});
|
|
502
526
|
};
|
|
527
|
+
var getData = (component, path, alternative) => {
|
|
528
|
+
if (path) {
|
|
529
|
+
return ObjectManager2.on(unref2(component.state)).get(dataPath(component, path), alternative);
|
|
530
|
+
} else {
|
|
531
|
+
return ObjectManager2.on(unref2(component.state)).get();
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
var setData = (component, data, path) => {
|
|
535
|
+
return component.$emit("update:state", {
|
|
536
|
+
before: ObjectManager2.on(unref2(component.state)).clone(),
|
|
537
|
+
after: path ? ObjectManager2.on({}).set(dataPath(component, path), data).get() : data
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
var dataPath = (component, path) => {
|
|
541
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
542
|
+
};
|
|
503
543
|
export {
|
|
504
544
|
MergeStyles,
|
|
505
545
|
StyleParser,
|
|
506
546
|
access,
|
|
547
|
+
dataPath,
|
|
507
548
|
index_default as default,
|
|
508
549
|
extendVnode,
|
|
550
|
+
getData,
|
|
509
551
|
getDate,
|
|
510
552
|
getProps,
|
|
511
553
|
getReactiveViewComponent,
|
|
512
554
|
safeRequest,
|
|
555
|
+
setData,
|
|
513
556
|
setup,
|
|
514
557
|
useSubscription
|
|
515
558
|
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@razaman2/reactive-view",
|
|
3
|
-
"version": "0.0.34-beta.
|
|
4
|
-
"description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"prepublishOnly": "npm run build",
|
|
10
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
11
|
-
"lint": "tsc",
|
|
12
|
-
"test": "cd tests/vue-ts && npm run dev"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"vue",
|
|
16
|
-
"vue-helper",
|
|
17
|
-
"reactive-view",
|
|
18
|
-
"vue-class-component",
|
|
19
|
-
"reactive-ui"
|
|
20
|
-
],
|
|
21
|
-
"author": "razaman2",
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@razaman2/data-manager": "^3.2.12",
|
|
25
|
-
"@razaman2/event-emitter": "^2.1.1",
|
|
26
|
-
"@razaman2/object-manager": "^3.4.
|
|
27
|
-
"date-fns": "^4.1.0",
|
|
28
|
-
"date-fns-tz": "^3.2.0",
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@razaman2/reactive-view",
|
|
3
|
+
"version": "0.0.34-beta.11",
|
|
4
|
+
"description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
11
|
+
"lint": "tsc",
|
|
12
|
+
"test": "cd tests/vue-ts && npm run dev"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"vue",
|
|
16
|
+
"vue-helper",
|
|
17
|
+
"reactive-view",
|
|
18
|
+
"vue-class-component",
|
|
19
|
+
"reactive-ui"
|
|
20
|
+
],
|
|
21
|
+
"author": "razaman2",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@razaman2/data-manager": "^3.2.12",
|
|
25
|
+
"@razaman2/event-emitter": "^2.1.1",
|
|
26
|
+
"@razaman2/object-manager": "^3.4.5",
|
|
27
|
+
"date-fns": "^4.1.0",
|
|
28
|
+
"date-fns-tz": "^3.2.0",
|
|
29
|
+
"tailwind-merge": "^3.3.1",
|
|
30
|
+
"uuid": "^11.1.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"vue": "^3.5.20"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/uuid": "^10.0.0",
|
|
37
|
+
"tsup": "^8.5.0",
|
|
38
|
+
"typescript": "^5.9.2",
|
|
39
|
+
"vitest": "^3.2.4"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
]
|
|
47
|
+
}
|