@razaman2/reactive-view 0.0.33 → 0.0.34-beta.10
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 +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +96 -58
- package/dist/index.mjs +96 -59
- package/package.json +47 -46
package/dist/index.d.mts
CHANGED
|
@@ -48,13 +48,13 @@ declare const _default: {
|
|
|
48
48
|
default: boolean;
|
|
49
49
|
};
|
|
50
50
|
instance: {
|
|
51
|
-
default: vue.Ref<any, any>;
|
|
51
|
+
default: () => vue.Ref<any, any>;
|
|
52
52
|
};
|
|
53
53
|
notifications: ObjectConstructor;
|
|
54
54
|
subscriptions: ObjectConstructor;
|
|
55
55
|
beforeSetData: FunctionConstructor;
|
|
56
56
|
data: {
|
|
57
|
-
default: {};
|
|
57
|
+
default: () => {};
|
|
58
58
|
};
|
|
59
59
|
defaultData: {};
|
|
60
60
|
getDefaultData: {
|
|
@@ -74,6 +74,7 @@ declare const _default: {
|
|
|
74
74
|
type: BooleanConstructor;
|
|
75
75
|
default: boolean;
|
|
76
76
|
};
|
|
77
|
+
state: {};
|
|
77
78
|
};
|
|
78
79
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
79
80
|
};
|
|
@@ -117,5 +118,8 @@ declare function useSubscription(): {
|
|
|
117
118
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
118
119
|
declare function MergeStyles(...params: any): any;
|
|
119
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;
|
|
120
124
|
|
|
121
|
-
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
|
@@ -48,13 +48,13 @@ declare const _default: {
|
|
|
48
48
|
default: boolean;
|
|
49
49
|
};
|
|
50
50
|
instance: {
|
|
51
|
-
default: vue.Ref<any, any>;
|
|
51
|
+
default: () => vue.Ref<any, any>;
|
|
52
52
|
};
|
|
53
53
|
notifications: ObjectConstructor;
|
|
54
54
|
subscriptions: ObjectConstructor;
|
|
55
55
|
beforeSetData: FunctionConstructor;
|
|
56
56
|
data: {
|
|
57
|
-
default: {};
|
|
57
|
+
default: () => {};
|
|
58
58
|
};
|
|
59
59
|
defaultData: {};
|
|
60
60
|
getDefaultData: {
|
|
@@ -74,6 +74,7 @@ declare const _default: {
|
|
|
74
74
|
type: BooleanConstructor;
|
|
75
75
|
default: boolean;
|
|
76
76
|
};
|
|
77
|
+
state: {};
|
|
77
78
|
};
|
|
78
79
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
79
80
|
};
|
|
@@ -117,5 +118,8 @@ declare function useSubscription(): {
|
|
|
117
118
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
118
119
|
declare function MergeStyles(...params: any): any;
|
|
119
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;
|
|
120
124
|
|
|
121
|
-
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.
|
|
175
|
+
var version = "0.0.34-beta.10";
|
|
172
176
|
|
|
173
177
|
// src/ReactiveView.ts
|
|
174
178
|
var setup = {
|
|
@@ -184,13 +188,13 @@ var ReactiveView_default = {
|
|
|
184
188
|
default: true
|
|
185
189
|
},
|
|
186
190
|
instance: {
|
|
187
|
-
default: (0, import_vue.ref)()
|
|
191
|
+
default: () => (0, import_vue.ref)()
|
|
188
192
|
},
|
|
189
193
|
notifications: Object,
|
|
190
194
|
subscriptions: Object,
|
|
191
195
|
beforeSetData: Function,
|
|
192
196
|
data: {
|
|
193
|
-
default: {}
|
|
197
|
+
default: () => ({})
|
|
194
198
|
},
|
|
195
199
|
defaultData: {},
|
|
196
200
|
getDefaultData: {
|
|
@@ -211,10 +215,27 @@ var ReactiveView_default = {
|
|
|
211
215
|
debug: {
|
|
212
216
|
type: Boolean,
|
|
213
217
|
default: false
|
|
214
|
-
}
|
|
218
|
+
},
|
|
219
|
+
state: {}
|
|
215
220
|
},
|
|
216
221
|
setup(props, context) {
|
|
217
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
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
|
+
};
|
|
218
239
|
const template = (component2, vue2) => {
|
|
219
240
|
return (0, import_vue.createVNode)(
|
|
220
241
|
"div",
|
|
@@ -225,25 +246,23 @@ var ReactiveView_default = {
|
|
|
225
246
|
);
|
|
226
247
|
};
|
|
227
248
|
const isValid = (0, import_vue.ref)(false);
|
|
228
|
-
const
|
|
229
|
-
const
|
|
249
|
+
const isReady = (0, import_vue.ref)(false);
|
|
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
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
|
|
235
|
-
}
|
|
236
|
-
if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
|
|
237
|
-
console.error("[ReactiveView]: defaultData is required for async data.");
|
|
254
|
+
const vue = (0, import_vue.getCurrentInstance)();
|
|
255
|
+
if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
|
|
256
|
+
console.error("[ReactiveView]: defaultData is required for promise or async function data.");
|
|
238
257
|
}
|
|
239
258
|
const defaultData = props.getDefaultData(
|
|
240
|
-
((
|
|
259
|
+
((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_e = vue.vnode.props) == null ? void 0 : _e.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
|
|
241
260
|
);
|
|
242
261
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
243
262
|
const config = {
|
|
244
|
-
data: (0, import_vue.reactive)(
|
|
245
|
-
|
|
246
|
-
),
|
|
263
|
+
data: (0, import_vue.reactive)(import_object_manager.default.on(
|
|
264
|
+
isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
|
|
265
|
+
).clone()),
|
|
247
266
|
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
248
267
|
notifications: props.notifications,
|
|
249
268
|
subscriptions: props.subscriptions,
|
|
@@ -257,9 +276,11 @@ var ReactiveView_default = {
|
|
|
257
276
|
var _a2;
|
|
258
277
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
259
278
|
if (typeof beforeSetData === "function") {
|
|
260
|
-
const after = import_object_manager.default.on(datatype).set(...params.length ? params : [defaultData]).get();
|
|
261
279
|
const before = target.getData();
|
|
262
|
-
|
|
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
|
+
}
|
|
263
284
|
} else {
|
|
264
285
|
target[key](...params);
|
|
265
286
|
}
|
|
@@ -270,48 +291,53 @@ var ReactiveView_default = {
|
|
|
270
291
|
}
|
|
271
292
|
}
|
|
272
293
|
});
|
|
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({
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
once: context.attrs["data:once"]
|
|
281
|
-
}, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
|
|
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)
|
|
282
305
|
};
|
|
283
306
|
if (context.attrs["data:log"]) {
|
|
284
|
-
console.log(`[data:
|
|
307
|
+
console.log(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
285
308
|
}
|
|
286
|
-
(0, import_vue.watch)(
|
|
309
|
+
(0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
287
310
|
var _a3;
|
|
288
|
-
const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
|
|
289
311
|
if (typeof config2.callback === "function") {
|
|
290
|
-
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);
|
|
291
313
|
} else {
|
|
292
314
|
model.replaceData(after);
|
|
293
315
|
}
|
|
294
316
|
}, config2.options);
|
|
295
317
|
};
|
|
318
|
+
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
319
|
+
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
320
|
+
callback: context.attrs["onUpdate:model"],
|
|
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 : {};
|
|
325
|
+
if (context.attrs["model:log"]) {
|
|
326
|
+
console.log(`[ReactiveView]:model`, { config: config2 });
|
|
327
|
+
}
|
|
328
|
+
(0, import_vue.watch)(() => model.getData(), (after, before) => {
|
|
329
|
+
config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
330
|
+
}, config2.options);
|
|
331
|
+
}
|
|
296
332
|
setTimeout(async () => {
|
|
297
333
|
var _a2;
|
|
298
|
-
const [
|
|
299
|
-
watchDataProp(
|
|
334
|
+
const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
|
|
335
|
+
watchDataProp(data);
|
|
300
336
|
});
|
|
301
337
|
setTimeout(async () => {
|
|
302
338
|
var _a2;
|
|
303
|
-
|
|
339
|
+
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
304
340
|
});
|
|
305
|
-
if (context.attrs["onUpdate:model"]) {
|
|
306
|
-
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
307
|
-
callback: context.attrs["onUpdate:model"]
|
|
308
|
-
} : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
|
|
309
|
-
(0, import_vue.watch)(() => model.getData(), (after, before) => {
|
|
310
|
-
const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
|
|
311
|
-
config2.callback(diff, { component });
|
|
312
|
-
}, config2.options);
|
|
313
|
-
}
|
|
314
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
315
341
|
component.value = [access(component)].reduce((options, parent) => {
|
|
316
342
|
var _a2;
|
|
317
343
|
while (parent) {
|
|
@@ -331,7 +357,7 @@ var ReactiveView_default = {
|
|
|
331
357
|
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
332
358
|
return (vue2) => {
|
|
333
359
|
var _a2, _b2;
|
|
334
|
-
if (
|
|
360
|
+
if (isReady.value) {
|
|
335
361
|
return access(component).template(component, vue2);
|
|
336
362
|
} else {
|
|
337
363
|
return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
|
|
@@ -343,6 +369,7 @@ var ReactiveView_default = {
|
|
|
343
369
|
// src/index.ts
|
|
344
370
|
var import_vue2 = require("vue");
|
|
345
371
|
var import_date_fns_tz = require("date-fns-tz");
|
|
372
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
346
373
|
var index_default = ReactiveView_default;
|
|
347
374
|
function safeRequest(request) {
|
|
348
375
|
return new Promise(async (resolve) => {
|
|
@@ -372,7 +399,7 @@ function safeRequest(request) {
|
|
|
372
399
|
}
|
|
373
400
|
});
|
|
374
401
|
}
|
|
375
|
-
function getProps(props, param2) {
|
|
402
|
+
function getProps(props = {}, param2) {
|
|
376
403
|
var _a;
|
|
377
404
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
378
405
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -417,7 +444,7 @@ function getDate(param1, param2) {
|
|
|
417
444
|
}
|
|
418
445
|
function access(view = {}, alternative) {
|
|
419
446
|
const resolve = (target) => {
|
|
420
|
-
return new Proxy(target, {
|
|
447
|
+
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
421
448
|
get(target2, key) {
|
|
422
449
|
const component = { tree: target2 };
|
|
423
450
|
do {
|
|
@@ -524,36 +551,47 @@ var extendVnode = (component, element) => {
|
|
|
524
551
|
return (props = {}, slots) => {
|
|
525
552
|
var _a;
|
|
526
553
|
const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
527
|
-
const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
|
|
554
|
+
const finalClasses = (0, import_tailwind_merge.twMerge)(MergeStyles(classes).string, MergeStyles(typeof props.class === "function" ? props.class(classes) : props.class).string);
|
|
555
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
528
556
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
].includes(key2) && typeof value === "function") {
|
|
533
|
-
props2[key2] = value(vnode.props[key2]);
|
|
557
|
+
var _a2;
|
|
558
|
+
if (!["class", "style"].includes(key2) && typeof value === "function") {
|
|
559
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
534
560
|
}
|
|
535
561
|
return props2;
|
|
536
562
|
}, props);
|
|
537
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
});
|
|
541
|
-
const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
|
|
542
|
-
return (0, import_vue2.h)(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
|
|
563
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
564
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
565
|
+
return (0, import_vue2.h)(["undefined"].includes(typeof element) ? vnode.type : element, finalProps, finalSlots);
|
|
543
566
|
};
|
|
544
567
|
}
|
|
545
568
|
});
|
|
546
569
|
};
|
|
570
|
+
var getData = (component, path, alternative) => {
|
|
571
|
+
return import_object_manager2.default.on((0, import_vue2.unref)(component.state)).get(dataPath(component, path), alternative);
|
|
572
|
+
};
|
|
573
|
+
var setData = (component, data, path) => {
|
|
574
|
+
return component.$emit("update:state", {
|
|
575
|
+
before: import_object_manager2.default.on((0, import_vue2.unref)(component.state)).clone(),
|
|
576
|
+
after: path ? import_object_manager2.default.on({}).set(dataPath(component, path), data).get() : data
|
|
577
|
+
});
|
|
578
|
+
};
|
|
579
|
+
var dataPath = (component, path) => {
|
|
580
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
581
|
+
};
|
|
547
582
|
// Annotate the CommonJS export names for ESM import in node:
|
|
548
583
|
0 && (module.exports = {
|
|
549
584
|
MergeStyles,
|
|
550
585
|
StyleParser,
|
|
551
586
|
access,
|
|
587
|
+
dataPath,
|
|
552
588
|
extendVnode,
|
|
589
|
+
getData,
|
|
553
590
|
getDate,
|
|
554
591
|
getProps,
|
|
555
592
|
getReactiveViewComponent,
|
|
556
593
|
safeRequest,
|
|
594
|
+
setData,
|
|
557
595
|
setup,
|
|
558
596
|
useSubscription
|
|
559
597
|
});
|
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.
|
|
131
|
+
var version = "0.0.34-beta.10";
|
|
129
132
|
|
|
130
133
|
// src/ReactiveView.ts
|
|
131
134
|
var setup = {
|
|
@@ -141,13 +144,13 @@ var ReactiveView_default = {
|
|
|
141
144
|
default: true
|
|
142
145
|
},
|
|
143
146
|
instance: {
|
|
144
|
-
default: ref()
|
|
147
|
+
default: () => ref()
|
|
145
148
|
},
|
|
146
149
|
notifications: Object,
|
|
147
150
|
subscriptions: Object,
|
|
148
151
|
beforeSetData: Function,
|
|
149
152
|
data: {
|
|
150
|
-
default: {}
|
|
153
|
+
default: () => ({})
|
|
151
154
|
},
|
|
152
155
|
defaultData: {},
|
|
153
156
|
getDefaultData: {
|
|
@@ -168,10 +171,27 @@ var ReactiveView_default = {
|
|
|
168
171
|
debug: {
|
|
169
172
|
type: Boolean,
|
|
170
173
|
default: false
|
|
171
|
-
}
|
|
174
|
+
},
|
|
175
|
+
state: {}
|
|
172
176
|
},
|
|
173
177
|
setup(props, context) {
|
|
174
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
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
|
+
};
|
|
175
195
|
const template = (component2, vue2) => {
|
|
176
196
|
return createVNode(
|
|
177
197
|
"div",
|
|
@@ -182,25 +202,23 @@ var ReactiveView_default = {
|
|
|
182
202
|
);
|
|
183
203
|
};
|
|
184
204
|
const isValid = ref(false);
|
|
185
|
-
const
|
|
186
|
-
const
|
|
205
|
+
const isReady = ref(false);
|
|
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
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
|
|
192
|
-
}
|
|
193
|
-
if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
|
|
194
|
-
console.error("[ReactiveView]: defaultData is required for async data.");
|
|
210
|
+
const vue = getCurrentInstance();
|
|
211
|
+
if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
|
|
212
|
+
console.error("[ReactiveView]: defaultData is required for promise or async function data.");
|
|
195
213
|
}
|
|
196
214
|
const defaultData = props.getDefaultData(
|
|
197
|
-
((
|
|
215
|
+
((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_e = vue.vnode.props) == null ? void 0 : _e.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
|
|
198
216
|
);
|
|
199
217
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
200
218
|
const config = {
|
|
201
|
-
data: reactive(
|
|
202
|
-
|
|
203
|
-
),
|
|
219
|
+
data: reactive(ObjectManager.on(
|
|
220
|
+
isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
|
|
221
|
+
).clone()),
|
|
204
222
|
defaultData: ObjectManager.on(defaultData).clone(),
|
|
205
223
|
notifications: props.notifications,
|
|
206
224
|
subscriptions: props.subscriptions,
|
|
@@ -214,9 +232,11 @@ var ReactiveView_default = {
|
|
|
214
232
|
var _a2;
|
|
215
233
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
216
234
|
if (typeof beforeSetData === "function") {
|
|
217
|
-
const after = ObjectManager.on(datatype).set(...params.length ? params : [defaultData]).get();
|
|
218
235
|
const before = target.getData();
|
|
219
|
-
|
|
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
|
+
}
|
|
220
240
|
} else {
|
|
221
241
|
target[key](...params);
|
|
222
242
|
}
|
|
@@ -227,48 +247,53 @@ var ReactiveView_default = {
|
|
|
227
247
|
}
|
|
228
248
|
}
|
|
229
249
|
});
|
|
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({
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
once: context.attrs["data:once"]
|
|
238
|
-
}, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
|
|
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)
|
|
239
261
|
};
|
|
240
262
|
if (context.attrs["data:log"]) {
|
|
241
|
-
console.log(`[data:
|
|
263
|
+
console.log(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
242
264
|
}
|
|
243
|
-
watch(
|
|
265
|
+
watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
244
266
|
var _a3;
|
|
245
|
-
const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
|
|
246
267
|
if (typeof config2.callback === "function") {
|
|
247
|
-
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);
|
|
248
269
|
} else {
|
|
249
270
|
model.replaceData(after);
|
|
250
271
|
}
|
|
251
272
|
}, config2.options);
|
|
252
273
|
};
|
|
274
|
+
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
275
|
+
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
276
|
+
callback: context.attrs["onUpdate:model"],
|
|
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 : {};
|
|
281
|
+
if (context.attrs["model:log"]) {
|
|
282
|
+
console.log(`[ReactiveView]:model`, { config: config2 });
|
|
283
|
+
}
|
|
284
|
+
watch(() => model.getData(), (after, before) => {
|
|
285
|
+
config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
|
|
286
|
+
}, config2.options);
|
|
287
|
+
}
|
|
253
288
|
setTimeout(async () => {
|
|
254
289
|
var _a2;
|
|
255
|
-
const [
|
|
256
|
-
watchDataProp(
|
|
290
|
+
const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
|
|
291
|
+
watchDataProp(data);
|
|
257
292
|
});
|
|
258
293
|
setTimeout(async () => {
|
|
259
294
|
var _a2;
|
|
260
|
-
|
|
295
|
+
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
261
296
|
});
|
|
262
|
-
if (context.attrs["onUpdate:model"]) {
|
|
263
|
-
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
264
|
-
callback: context.attrs["onUpdate:model"]
|
|
265
|
-
} : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
|
|
266
|
-
watch(() => model.getData(), (after, before) => {
|
|
267
|
-
const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
|
|
268
|
-
config2.callback(diff, { component });
|
|
269
|
-
}, config2.options);
|
|
270
|
-
}
|
|
271
|
-
const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
272
297
|
component.value = [access(component)].reduce((options, parent) => {
|
|
273
298
|
var _a2;
|
|
274
299
|
while (parent) {
|
|
@@ -288,7 +313,7 @@ var ReactiveView_default = {
|
|
|
288
313
|
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
289
314
|
return (vue2) => {
|
|
290
315
|
var _a2, _b2;
|
|
291
|
-
if (
|
|
316
|
+
if (isReady.value) {
|
|
292
317
|
return access(component).template(component, vue2);
|
|
293
318
|
} else {
|
|
294
319
|
return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
|
|
@@ -298,8 +323,9 @@ var ReactiveView_default = {
|
|
|
298
323
|
};
|
|
299
324
|
|
|
300
325
|
// src/index.ts
|
|
301
|
-
import {
|
|
326
|
+
import { h, unref as unref2, isRef as isRef2, toRaw, createVNode as createVNode2 } from "vue";
|
|
302
327
|
import { formatInTimeZone } from "date-fns-tz";
|
|
328
|
+
import { twMerge } from "tailwind-merge";
|
|
303
329
|
var index_default = ReactiveView_default;
|
|
304
330
|
function safeRequest(request) {
|
|
305
331
|
return new Promise(async (resolve) => {
|
|
@@ -329,7 +355,7 @@ function safeRequest(request) {
|
|
|
329
355
|
}
|
|
330
356
|
});
|
|
331
357
|
}
|
|
332
|
-
function getProps(props, param2) {
|
|
358
|
+
function getProps(props = {}, param2) {
|
|
333
359
|
var _a;
|
|
334
360
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
335
361
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -374,7 +400,7 @@ function getDate(param1, param2) {
|
|
|
374
400
|
}
|
|
375
401
|
function access(view = {}, alternative) {
|
|
376
402
|
const resolve = (target) => {
|
|
377
|
-
return new Proxy(target, {
|
|
403
|
+
return new Proxy(toRaw(target), {
|
|
378
404
|
get(target2, key) {
|
|
379
405
|
const component = { tree: target2 };
|
|
380
406
|
do {
|
|
@@ -481,36 +507,47 @@ var extendVnode = (component, element) => {
|
|
|
481
507
|
return (props = {}, slots) => {
|
|
482
508
|
var _a;
|
|
483
509
|
const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
484
|
-
const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
|
|
510
|
+
const finalClasses = twMerge(MergeStyles(classes).string, MergeStyles(typeof props.class === "function" ? props.class(classes) : props.class).string);
|
|
511
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
485
512
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
].includes(key2) && typeof value === "function") {
|
|
490
|
-
props2[key2] = value(vnode.props[key2]);
|
|
513
|
+
var _a2;
|
|
514
|
+
if (!["class", "style"].includes(key2) && typeof value === "function") {
|
|
515
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
491
516
|
}
|
|
492
517
|
return props2;
|
|
493
518
|
}, props);
|
|
494
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
});
|
|
498
|
-
const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
|
|
499
|
-
return h(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
|
|
519
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
520
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
521
|
+
return h(["undefined"].includes(typeof element) ? vnode.type : element, finalProps, finalSlots);
|
|
500
522
|
};
|
|
501
523
|
}
|
|
502
524
|
});
|
|
503
525
|
};
|
|
526
|
+
var getData = (component, path, alternative) => {
|
|
527
|
+
return ObjectManager2.on(unref2(component.state)).get(dataPath(component, path), alternative);
|
|
528
|
+
};
|
|
529
|
+
var setData = (component, data, path) => {
|
|
530
|
+
return component.$emit("update:state", {
|
|
531
|
+
before: ObjectManager2.on(unref2(component.state)).clone(),
|
|
532
|
+
after: path ? ObjectManager2.on({}).set(dataPath(component, path), data).get() : data
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
var dataPath = (component, path) => {
|
|
536
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
537
|
+
};
|
|
504
538
|
export {
|
|
505
539
|
MergeStyles,
|
|
506
540
|
StyleParser,
|
|
507
541
|
access,
|
|
542
|
+
dataPath,
|
|
508
543
|
index_default as default,
|
|
509
544
|
extendVnode,
|
|
545
|
+
getData,
|
|
510
546
|
getDate,
|
|
511
547
|
getProps,
|
|
512
548
|
getReactiveViewComponent,
|
|
513
549
|
safeRequest,
|
|
550
|
+
setData,
|
|
514
551
|
setup,
|
|
515
552
|
useSubscription
|
|
516
553
|
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@razaman2/reactive-view",
|
|
3
|
-
"version": "0.0.
|
|
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.10",
|
|
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
|
+
}
|