@razaman2/reactive-view 0.0.34-beta.2 → 0.0.34-beta.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/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +187 -49
- package/dist/index.mjs +186 -51
- package/package.json +47 -46
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
|
|
2
|
+
import { SetupContext, ComponentPublicInstance, UnwrapRef, defineComponent } from 'vue';
|
|
3
3
|
|
|
4
4
|
type ComponentExtension = {
|
|
5
5
|
parent?: ComponentExtension;
|
|
@@ -43,6 +43,7 @@ declare const setup: {
|
|
|
43
43
|
declare const _default: {
|
|
44
44
|
props: {
|
|
45
45
|
setup: {};
|
|
46
|
+
beta: BooleanConstructor;
|
|
46
47
|
ReactiveView: {
|
|
47
48
|
type: BooleanConstructor;
|
|
48
49
|
default: boolean;
|
|
@@ -53,7 +54,9 @@ declare const _default: {
|
|
|
53
54
|
notifications: ObjectConstructor;
|
|
54
55
|
subscriptions: ObjectConstructor;
|
|
55
56
|
beforeSetData: FunctionConstructor;
|
|
56
|
-
data: {
|
|
57
|
+
data: {
|
|
58
|
+
default: () => {};
|
|
59
|
+
};
|
|
57
60
|
defaultData: {};
|
|
58
61
|
getDefaultData: {
|
|
59
62
|
type: FunctionConstructor;
|
|
@@ -72,6 +75,9 @@ declare const _default: {
|
|
|
72
75
|
type: BooleanConstructor;
|
|
73
76
|
default: boolean;
|
|
74
77
|
};
|
|
78
|
+
state: {
|
|
79
|
+
default: () => {};
|
|
80
|
+
};
|
|
75
81
|
};
|
|
76
82
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
77
83
|
};
|
|
@@ -115,5 +121,16 @@ declare function useSubscription(): {
|
|
|
115
121
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
116
122
|
declare function MergeStyles(...params: any): any;
|
|
117
123
|
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>;
|
|
124
|
+
declare function defineReactiveView(): ReturnType<typeof defineComponent>;
|
|
125
|
+
declare function defineReactiveView(options: Record<string, any>): ReturnType<typeof defineComponent>;
|
|
126
|
+
declare function defineReactiveView(options: Record<string, any>, component: typeof _default): ReturnType<typeof defineComponent>;
|
|
127
|
+
declare function showComponent(component: any, options?: {
|
|
128
|
+
container?: string;
|
|
129
|
+
key?: string;
|
|
130
|
+
router?: any;
|
|
131
|
+
}): void;
|
|
132
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
133
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
134
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
118
135
|
|
|
119
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
136
|
+
export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
|
|
2
|
+
import { SetupContext, ComponentPublicInstance, UnwrapRef, defineComponent } from 'vue';
|
|
3
3
|
|
|
4
4
|
type ComponentExtension = {
|
|
5
5
|
parent?: ComponentExtension;
|
|
@@ -43,6 +43,7 @@ declare const setup: {
|
|
|
43
43
|
declare const _default: {
|
|
44
44
|
props: {
|
|
45
45
|
setup: {};
|
|
46
|
+
beta: BooleanConstructor;
|
|
46
47
|
ReactiveView: {
|
|
47
48
|
type: BooleanConstructor;
|
|
48
49
|
default: boolean;
|
|
@@ -53,7 +54,9 @@ declare const _default: {
|
|
|
53
54
|
notifications: ObjectConstructor;
|
|
54
55
|
subscriptions: ObjectConstructor;
|
|
55
56
|
beforeSetData: FunctionConstructor;
|
|
56
|
-
data: {
|
|
57
|
+
data: {
|
|
58
|
+
default: () => {};
|
|
59
|
+
};
|
|
57
60
|
defaultData: {};
|
|
58
61
|
getDefaultData: {
|
|
59
62
|
type: FunctionConstructor;
|
|
@@ -72,6 +75,9 @@ declare const _default: {
|
|
|
72
75
|
type: BooleanConstructor;
|
|
73
76
|
default: boolean;
|
|
74
77
|
};
|
|
78
|
+
state: {
|
|
79
|
+
default: () => {};
|
|
80
|
+
};
|
|
75
81
|
};
|
|
76
82
|
setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
|
|
77
83
|
};
|
|
@@ -115,5 +121,16 @@ declare function useSubscription(): {
|
|
|
115
121
|
declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
|
|
116
122
|
declare function MergeStyles(...params: any): any;
|
|
117
123
|
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>;
|
|
124
|
+
declare function defineReactiveView(): ReturnType<typeof defineComponent>;
|
|
125
|
+
declare function defineReactiveView(options: Record<string, any>): ReturnType<typeof defineComponent>;
|
|
126
|
+
declare function defineReactiveView(options: Record<string, any>, component: typeof _default): ReturnType<typeof defineComponent>;
|
|
127
|
+
declare function showComponent(component: any, options?: {
|
|
128
|
+
container?: string;
|
|
129
|
+
key?: string;
|
|
130
|
+
router?: any;
|
|
131
|
+
}): void;
|
|
132
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
133
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
134
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
118
135
|
|
|
119
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
136
|
+
export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
|
package/dist/index.js
CHANGED
|
@@ -59,16 +59,22 @@ __export(index_exports, {
|
|
|
59
59
|
MergeStyles: () => MergeStyles,
|
|
60
60
|
StyleParser: () => StyleParser,
|
|
61
61
|
access: () => access,
|
|
62
|
+
dataPath: () => dataPath,
|
|
62
63
|
default: () => index_default,
|
|
64
|
+
defineReactiveView: () => defineReactiveView,
|
|
63
65
|
extendVnode: () => extendVnode,
|
|
66
|
+
getData: () => getData,
|
|
64
67
|
getDate: () => getDate,
|
|
65
68
|
getProps: () => getProps,
|
|
66
69
|
getReactiveViewComponent: () => getReactiveViewComponent,
|
|
67
70
|
safeRequest: () => safeRequest,
|
|
71
|
+
setData: () => setData,
|
|
68
72
|
setup: () => setup,
|
|
73
|
+
showComponent: () => showComponent,
|
|
69
74
|
useSubscription: () => useSubscription
|
|
70
75
|
});
|
|
71
76
|
module.exports = __toCommonJS(index_exports);
|
|
77
|
+
var import_object_manager2 = __toESM(require("@razaman2/object-manager"));
|
|
72
78
|
|
|
73
79
|
// src/Subscription.ts
|
|
74
80
|
var Subscription = class _Subscription {
|
|
@@ -168,7 +174,7 @@ var import_vue = require("vue");
|
|
|
168
174
|
|
|
169
175
|
// package.json
|
|
170
176
|
var name = "@razaman2/reactive-view";
|
|
171
|
-
var version = "0.0.34-beta.
|
|
177
|
+
var version = "0.0.34-beta.21";
|
|
172
178
|
|
|
173
179
|
// src/ReactiveView.ts
|
|
174
180
|
var setup = {
|
|
@@ -179,17 +185,16 @@ var setup = {
|
|
|
179
185
|
var ReactiveView_default = {
|
|
180
186
|
props: {
|
|
181
187
|
setup: {},
|
|
188
|
+
beta: Boolean,
|
|
182
189
|
ReactiveView: {
|
|
183
190
|
type: Boolean,
|
|
184
191
|
default: true
|
|
185
192
|
},
|
|
186
|
-
instance: {
|
|
187
|
-
default: () => (0, import_vue.ref)()
|
|
188
|
-
},
|
|
193
|
+
instance: { default: () => (0, import_vue.ref)() },
|
|
189
194
|
notifications: Object,
|
|
190
195
|
subscriptions: Object,
|
|
191
196
|
beforeSetData: Function,
|
|
192
|
-
data: {},
|
|
197
|
+
data: { default: () => ({}) },
|
|
193
198
|
defaultData: {},
|
|
194
199
|
getDefaultData: {
|
|
195
200
|
type: Function,
|
|
@@ -209,10 +214,27 @@ var ReactiveView_default = {
|
|
|
209
214
|
debug: {
|
|
210
215
|
type: Boolean,
|
|
211
216
|
default: false
|
|
212
|
-
}
|
|
217
|
+
},
|
|
218
|
+
state: { default: () => (0, import_vue.reactive)({}) }
|
|
213
219
|
},
|
|
214
220
|
setup(props, context) {
|
|
215
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
221
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
222
|
+
const diff = (before, after) => {
|
|
223
|
+
const change = after.paths().reduce((change2, path) => {
|
|
224
|
+
if (before.get(path) !== after.get(path)) {
|
|
225
|
+
change2.set(path, after.get(path));
|
|
226
|
+
}
|
|
227
|
+
return change2;
|
|
228
|
+
}, import_object_manager.default.on({}));
|
|
229
|
+
return { before: before.get(), after: after.get(), change: change.get() };
|
|
230
|
+
};
|
|
231
|
+
const dataPath2 = (path) => {
|
|
232
|
+
try {
|
|
233
|
+
return context.attrs["data:path"](path);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
return path;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
216
238
|
const template = (component2, vue2) => {
|
|
217
239
|
return (0, import_vue.createVNode)(
|
|
218
240
|
"div",
|
|
@@ -224,21 +246,51 @@ var ReactiveView_default = {
|
|
|
224
246
|
};
|
|
225
247
|
const isValid = (0, import_vue.ref)(false);
|
|
226
248
|
const isReady = (0, import_vue.ref)(false);
|
|
227
|
-
const isFunctionData = ["Function"].includes((
|
|
228
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes((
|
|
229
|
-
const isPromiseData = ["Promise"].includes((
|
|
249
|
+
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
250
|
+
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
251
|
+
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
230
252
|
const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
231
253
|
const vue = (0, import_vue.getCurrentInstance)();
|
|
232
|
-
if ((
|
|
254
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
233
255
|
console.error("[ReactiveView]: defaultData is required for promise or async function data.");
|
|
234
256
|
}
|
|
235
257
|
const defaultData = props.getDefaultData(
|
|
236
|
-
|
|
258
|
+
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
|
|
237
259
|
);
|
|
238
260
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
261
|
+
const normalize = (data) => {
|
|
262
|
+
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, data, defaultData);
|
|
263
|
+
if ((0, import_vue.isReactive)(data)) {
|
|
264
|
+
return data;
|
|
265
|
+
} else if ((0, import_vue.isRef)(data)) {
|
|
266
|
+
try {
|
|
267
|
+
if (["Array", "Object"].includes((0, import_vue.unref)(data).constructor.name)) {
|
|
268
|
+
return (0, import_vue.unref)(data);
|
|
269
|
+
} else {
|
|
270
|
+
return (0, import_vue.reactive)({ "": (0, import_vue.unref)(data) });
|
|
271
|
+
}
|
|
272
|
+
} catch (e) {
|
|
273
|
+
return (0, import_vue.reactive)({ "": (0, import_vue.unref)(data) });
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
if (isFunctionData || isPromiseData) {
|
|
277
|
+
return (0, import_vue.reactive)(datatype);
|
|
278
|
+
} else {
|
|
279
|
+
try {
|
|
280
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
281
|
+
return (0, import_vue.reactive)("data" in vue.vnode.props ? data : defaultData);
|
|
282
|
+
} else {
|
|
283
|
+
return (0, import_vue.reactive)({ "": "data" in vue.vnode.props ? data : defaultData });
|
|
284
|
+
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
return (0, import_vue.reactive)({ "": "data" in vue.vnode.props ? data : defaultData });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
239
291
|
const config = {
|
|
240
|
-
data: (0, import_vue.reactive)(import_object_manager.default.on(
|
|
241
|
-
isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype :
|
|
292
|
+
data: props.beta ? normalize((_d = vue.vnode.props) == null ? void 0 : _d.data) : (0, import_vue.reactive)(import_object_manager.default.on(
|
|
293
|
+
isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
242
294
|
).clone()),
|
|
243
295
|
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
244
296
|
notifications: props.notifications,
|
|
@@ -254,8 +306,8 @@ var ReactiveView_default = {
|
|
|
254
306
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
255
307
|
if (typeof beforeSetData === "function") {
|
|
256
308
|
const before = target.getData();
|
|
257
|
-
const after =
|
|
258
|
-
if (beforeSetData(
|
|
309
|
+
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
310
|
+
if (beforeSetData(diff(import_object_manager.default.on(before), after), target)) {
|
|
259
311
|
target[key](...params);
|
|
260
312
|
}
|
|
261
313
|
} else {
|
|
@@ -268,24 +320,25 @@ var ReactiveView_default = {
|
|
|
268
320
|
}
|
|
269
321
|
}
|
|
270
322
|
});
|
|
271
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
323
|
+
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, dataPath: dataPath2, isValid } });
|
|
272
324
|
if (props.debug) {
|
|
273
325
|
console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
274
326
|
}
|
|
275
327
|
const watchDataProp = (dataProp) => {
|
|
276
|
-
var _a2, _b2, _c2;
|
|
328
|
+
var _a2, _b2, _c2, _d2;
|
|
277
329
|
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
278
330
|
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
279
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
331
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
332
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
|
|
333
|
+
}, 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)
|
|
280
334
|
};
|
|
281
335
|
if (context.attrs["data:log"]) {
|
|
282
336
|
console.log(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
283
337
|
}
|
|
284
338
|
(0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
285
339
|
var _a3;
|
|
286
|
-
const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
|
|
287
340
|
if (typeof config2.callback === "function") {
|
|
288
|
-
model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
|
|
341
|
+
model.replaceData((_a3 = config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a3 : after);
|
|
289
342
|
} else {
|
|
290
343
|
model.replaceData(after);
|
|
291
344
|
}
|
|
@@ -295,22 +348,29 @@ var ReactiveView_default = {
|
|
|
295
348
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
296
349
|
callback: context.attrs["onUpdate:model"],
|
|
297
350
|
options: Object.assign(__spreadValues(__spreadValues({
|
|
298
|
-
deep: (
|
|
299
|
-
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((
|
|
300
|
-
} : (
|
|
351
|
+
deep: (_e = context.attrs["model:deep"]) != null ? _e : true
|
|
352
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_f = context.attrs["onUpdate:model"]) != null ? _f : {}).options)
|
|
353
|
+
} : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
|
|
301
354
|
if (context.attrs["model:log"]) {
|
|
302
355
|
console.log(`[ReactiveView]:model`, { config: config2 });
|
|
303
356
|
}
|
|
304
357
|
(0, import_vue.watch)(() => model.getData(), (after, before) => {
|
|
305
|
-
|
|
306
|
-
config2.callback(diff, { component });
|
|
358
|
+
config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
307
359
|
}, config2.options);
|
|
308
360
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
361
|
+
if (!props.beta) {
|
|
362
|
+
setTimeout(async () => {
|
|
363
|
+
var _a2;
|
|
364
|
+
const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
|
|
365
|
+
watchDataProp(data);
|
|
366
|
+
});
|
|
367
|
+
} else if (props.beta && (isFunctionData || isPromiseData)) {
|
|
368
|
+
setTimeout(async () => {
|
|
369
|
+
var _a2;
|
|
370
|
+
const [data] = await Promise.all([isFunctionData || isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
|
|
371
|
+
model.replaceData((0, import_vue.toRaw)((0, import_vue.unref)(data)));
|
|
372
|
+
});
|
|
373
|
+
}
|
|
314
374
|
setTimeout(async () => {
|
|
315
375
|
var _a2;
|
|
316
376
|
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
@@ -346,6 +406,8 @@ var ReactiveView_default = {
|
|
|
346
406
|
// src/index.ts
|
|
347
407
|
var import_vue2 = require("vue");
|
|
348
408
|
var import_date_fns_tz = require("date-fns-tz");
|
|
409
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
410
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
349
411
|
var index_default = ReactiveView_default;
|
|
350
412
|
function safeRequest(request) {
|
|
351
413
|
return new Promise(async (resolve) => {
|
|
@@ -375,7 +437,7 @@ function safeRequest(request) {
|
|
|
375
437
|
}
|
|
376
438
|
});
|
|
377
439
|
}
|
|
378
|
-
function getProps(props, param2) {
|
|
440
|
+
function getProps(props = {}, param2) {
|
|
379
441
|
var _a;
|
|
380
442
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
381
443
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -420,7 +482,7 @@ function getDate(param1, param2) {
|
|
|
420
482
|
}
|
|
421
483
|
function access(view = {}, alternative) {
|
|
422
484
|
const resolve = (target) => {
|
|
423
|
-
return new Proxy(target, {
|
|
485
|
+
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
424
486
|
get(target2, key) {
|
|
425
487
|
const component = { tree: target2 };
|
|
426
488
|
do {
|
|
@@ -441,9 +503,8 @@ function access(view = {}, alternative) {
|
|
|
441
503
|
});
|
|
442
504
|
};
|
|
443
505
|
try {
|
|
444
|
-
const component = typeof view === "function" ? view() : view;
|
|
445
|
-
|
|
446
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
506
|
+
const component = (0, import_vue2.unref)(typeof view === "function" ? view() : view);
|
|
507
|
+
return resolve("instance" in component ? component.instance : component);
|
|
447
508
|
} catch (e) {
|
|
448
509
|
return resolve(view);
|
|
449
510
|
}
|
|
@@ -526,37 +587,114 @@ var extendVnode = (component, element) => {
|
|
|
526
587
|
const vnode = getVnode();
|
|
527
588
|
return (props = {}, slots) => {
|
|
528
589
|
var _a;
|
|
529
|
-
const
|
|
530
|
-
const
|
|
590
|
+
const isFunctionClass = typeof props.class === "function";
|
|
591
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
592
|
+
const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
593
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
531
594
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
].includes(key2) && typeof value === "function") {
|
|
536
|
-
props2[key2] = value(vnode.props[key2]);
|
|
595
|
+
var _a2;
|
|
596
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
597
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
537
598
|
}
|
|
538
599
|
return props2;
|
|
539
600
|
}, props);
|
|
540
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
601
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
602
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
603
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
604
|
+
return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
};
|
|
609
|
+
function defineReactiveView(param1, param2) {
|
|
610
|
+
console.log(`log params:`, { param1, param2 });
|
|
611
|
+
return (0, import_vue2.defineComponent)({
|
|
612
|
+
name: param1 == null ? void 0 : param1.modelName,
|
|
613
|
+
props: __spreadValues({ setup }, param1 ? param1.props : {}),
|
|
614
|
+
setup() {
|
|
615
|
+
const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
616
|
+
return (component) => {
|
|
617
|
+
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
618
|
+
return Object.assign(props3, { [key]: typeof val === "function" ? val(component) : val });
|
|
619
|
+
}, {});
|
|
620
|
+
const slots = typeof (param1 == null ? void 0 : param1.slots) === "function" ? param1.slots(component) : Array.isArray(param1 == null ? void 0 : param1.slots) ? () => param1.slots : param1 == null ? void 0 : param1.slots;
|
|
621
|
+
return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, __spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
622
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
623
|
+
} : {})), slots);
|
|
546
624
|
};
|
|
547
625
|
}
|
|
548
626
|
});
|
|
627
|
+
}
|
|
628
|
+
function showComponent(component, options = {}) {
|
|
629
|
+
var _a;
|
|
630
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
631
|
+
const container = options.container || "app-dialogs";
|
|
632
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
633
|
+
if (!dialogs.hasAttribute("id")) {
|
|
634
|
+
dialogs.setAttribute("id", container);
|
|
635
|
+
document.body.appendChild(dialogs);
|
|
636
|
+
}
|
|
637
|
+
const dialog = document.createElement("div");
|
|
638
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
639
|
+
dialog.setAttribute("id", id);
|
|
640
|
+
dialogs.appendChild(dialog);
|
|
641
|
+
const app = (0, import_vue2.createApp)(
|
|
642
|
+
{
|
|
643
|
+
setup() {
|
|
644
|
+
return () => component;
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
__cleanup__: () => {
|
|
649
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
);
|
|
653
|
+
if (options.router) {
|
|
654
|
+
app.use(options.router).mount(`#${id}`);
|
|
655
|
+
} else {
|
|
656
|
+
app.mount(`#${id}`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
var getData = (component, path, alternative) => {
|
|
661
|
+
const vue = access(component);
|
|
662
|
+
const data = import_object_manager2.default.on(componentState(vue));
|
|
663
|
+
if (path) {
|
|
664
|
+
return data.get(dataPath(vue, path), alternative);
|
|
665
|
+
} else {
|
|
666
|
+
return data.get();
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
var setData = (component, data, path) => {
|
|
670
|
+
const vue = access(component);
|
|
671
|
+
const diff = {
|
|
672
|
+
before: import_object_manager2.default.on(componentState(vue)).clone(),
|
|
673
|
+
after: path ? import_object_manager2.default.on(componentState(vue)).set(dataPath(vue, path), data).get() : import_object_manager2.default.on(componentState(vue)).set(data).get()
|
|
674
|
+
};
|
|
675
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
676
|
+
};
|
|
677
|
+
var componentState = (component) => {
|
|
678
|
+
return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
|
|
679
|
+
};
|
|
680
|
+
var dataPath = (component, path) => {
|
|
681
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
549
682
|
};
|
|
550
683
|
// Annotate the CommonJS export names for ESM import in node:
|
|
551
684
|
0 && (module.exports = {
|
|
552
685
|
MergeStyles,
|
|
553
686
|
StyleParser,
|
|
554
687
|
access,
|
|
688
|
+
dataPath,
|
|
689
|
+
defineReactiveView,
|
|
555
690
|
extendVnode,
|
|
691
|
+
getData,
|
|
556
692
|
getDate,
|
|
557
693
|
getProps,
|
|
558
694
|
getReactiveViewComponent,
|
|
559
695
|
safeRequest,
|
|
696
|
+
setData,
|
|
560
697
|
setup,
|
|
698
|
+
showComponent,
|
|
561
699
|
useSubscription
|
|
562
700
|
});
|
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() {
|
|
@@ -121,11 +124,11 @@ var Subscriptions = _Subscriptions;
|
|
|
121
124
|
// src/ReactiveView.ts
|
|
122
125
|
import ObjectManager from "@razaman2/object-manager";
|
|
123
126
|
import DataManager from "@razaman2/data-manager";
|
|
124
|
-
import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance } from "vue";
|
|
127
|
+
import { ref, reactive, watch, unref, toRaw, isRef, isReactive, createVNode, getCurrentInstance } from "vue";
|
|
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.21";
|
|
129
132
|
|
|
130
133
|
// src/ReactiveView.ts
|
|
131
134
|
var setup = {
|
|
@@ -136,17 +139,16 @@ var setup = {
|
|
|
136
139
|
var ReactiveView_default = {
|
|
137
140
|
props: {
|
|
138
141
|
setup: {},
|
|
142
|
+
beta: Boolean,
|
|
139
143
|
ReactiveView: {
|
|
140
144
|
type: Boolean,
|
|
141
145
|
default: true
|
|
142
146
|
},
|
|
143
|
-
instance: {
|
|
144
|
-
default: () => ref()
|
|
145
|
-
},
|
|
147
|
+
instance: { default: () => ref() },
|
|
146
148
|
notifications: Object,
|
|
147
149
|
subscriptions: Object,
|
|
148
150
|
beforeSetData: Function,
|
|
149
|
-
data: {},
|
|
151
|
+
data: { default: () => ({}) },
|
|
150
152
|
defaultData: {},
|
|
151
153
|
getDefaultData: {
|
|
152
154
|
type: Function,
|
|
@@ -166,10 +168,27 @@ var ReactiveView_default = {
|
|
|
166
168
|
debug: {
|
|
167
169
|
type: Boolean,
|
|
168
170
|
default: false
|
|
169
|
-
}
|
|
171
|
+
},
|
|
172
|
+
state: { default: () => reactive({}) }
|
|
170
173
|
},
|
|
171
174
|
setup(props, context) {
|
|
172
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
175
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
176
|
+
const diff = (before, after) => {
|
|
177
|
+
const change = after.paths().reduce((change2, path) => {
|
|
178
|
+
if (before.get(path) !== after.get(path)) {
|
|
179
|
+
change2.set(path, after.get(path));
|
|
180
|
+
}
|
|
181
|
+
return change2;
|
|
182
|
+
}, ObjectManager.on({}));
|
|
183
|
+
return { before: before.get(), after: after.get(), change: change.get() };
|
|
184
|
+
};
|
|
185
|
+
const dataPath2 = (path) => {
|
|
186
|
+
try {
|
|
187
|
+
return context.attrs["data:path"](path);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return path;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
173
192
|
const template = (component2, vue2) => {
|
|
174
193
|
return createVNode(
|
|
175
194
|
"div",
|
|
@@ -181,21 +200,51 @@ var ReactiveView_default = {
|
|
|
181
200
|
};
|
|
182
201
|
const isValid = ref(false);
|
|
183
202
|
const isReady = ref(false);
|
|
184
|
-
const isFunctionData = ["Function"].includes((
|
|
185
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes((
|
|
186
|
-
const isPromiseData = ["Promise"].includes((
|
|
203
|
+
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
204
|
+
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
205
|
+
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
187
206
|
const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
188
207
|
const vue = getCurrentInstance();
|
|
189
|
-
if ((
|
|
208
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
190
209
|
console.error("[ReactiveView]: defaultData is required for promise or async function data.");
|
|
191
210
|
}
|
|
192
211
|
const defaultData = props.getDefaultData(
|
|
193
|
-
|
|
212
|
+
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
|
|
194
213
|
);
|
|
195
214
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
215
|
+
const normalize = (data) => {
|
|
216
|
+
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, data, defaultData);
|
|
217
|
+
if (isReactive(data)) {
|
|
218
|
+
return data;
|
|
219
|
+
} else if (isRef(data)) {
|
|
220
|
+
try {
|
|
221
|
+
if (["Array", "Object"].includes(unref(data).constructor.name)) {
|
|
222
|
+
return unref(data);
|
|
223
|
+
} else {
|
|
224
|
+
return reactive({ "": unref(data) });
|
|
225
|
+
}
|
|
226
|
+
} catch (e) {
|
|
227
|
+
return reactive({ "": unref(data) });
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
if (isFunctionData || isPromiseData) {
|
|
231
|
+
return reactive(datatype);
|
|
232
|
+
} else {
|
|
233
|
+
try {
|
|
234
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
235
|
+
return reactive("data" in vue.vnode.props ? data : defaultData);
|
|
236
|
+
} else {
|
|
237
|
+
return reactive({ "": "data" in vue.vnode.props ? data : defaultData });
|
|
238
|
+
}
|
|
239
|
+
} catch (e) {
|
|
240
|
+
return reactive({ "": "data" in vue.vnode.props ? data : defaultData });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
196
245
|
const config = {
|
|
197
|
-
data: reactive(ObjectManager.on(
|
|
198
|
-
isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype :
|
|
246
|
+
data: props.beta ? normalize((_d = vue.vnode.props) == null ? void 0 : _d.data) : reactive(ObjectManager.on(
|
|
247
|
+
isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
199
248
|
).clone()),
|
|
200
249
|
defaultData: ObjectManager.on(defaultData).clone(),
|
|
201
250
|
notifications: props.notifications,
|
|
@@ -211,8 +260,8 @@ var ReactiveView_default = {
|
|
|
211
260
|
const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
|
|
212
261
|
if (typeof beforeSetData === "function") {
|
|
213
262
|
const before = target.getData();
|
|
214
|
-
const after =
|
|
215
|
-
if (beforeSetData(
|
|
263
|
+
const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
|
|
264
|
+
if (beforeSetData(diff(ObjectManager.on(before), after), target)) {
|
|
216
265
|
target[key](...params);
|
|
217
266
|
}
|
|
218
267
|
} else {
|
|
@@ -225,24 +274,25 @@ var ReactiveView_default = {
|
|
|
225
274
|
}
|
|
226
275
|
}
|
|
227
276
|
});
|
|
228
|
-
const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
|
|
277
|
+
const component = ref({ parent: { self: vue.proxy }, self: { template, model, dataPath: dataPath2, isValid } });
|
|
229
278
|
if (props.debug) {
|
|
230
279
|
console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
|
|
231
280
|
}
|
|
232
281
|
const watchDataProp = (dataProp) => {
|
|
233
|
-
var _a2, _b2, _c2;
|
|
282
|
+
var _a2, _b2, _c2, _d2;
|
|
234
283
|
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
235
284
|
callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
|
|
236
|
-
options: Object.assign(__spreadValues(__spreadValues(
|
|
285
|
+
options: Object.assign(__spreadValues(__spreadValues({
|
|
286
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
|
|
287
|
+
}, 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)
|
|
237
288
|
};
|
|
238
289
|
if (context.attrs["data:log"]) {
|
|
239
290
|
console.log(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
240
291
|
}
|
|
241
292
|
watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
242
293
|
var _a3;
|
|
243
|
-
const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
|
|
244
294
|
if (typeof config2.callback === "function") {
|
|
245
|
-
model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
|
|
295
|
+
model.replaceData((_a3 = config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a3 : after);
|
|
246
296
|
} else {
|
|
247
297
|
model.replaceData(after);
|
|
248
298
|
}
|
|
@@ -252,22 +302,29 @@ var ReactiveView_default = {
|
|
|
252
302
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
253
303
|
callback: context.attrs["onUpdate:model"],
|
|
254
304
|
options: Object.assign(__spreadValues(__spreadValues({
|
|
255
|
-
deep: (
|
|
256
|
-
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((
|
|
257
|
-
} : (
|
|
305
|
+
deep: (_e = context.attrs["model:deep"]) != null ? _e : true
|
|
306
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_f = context.attrs["onUpdate:model"]) != null ? _f : {}).options)
|
|
307
|
+
} : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
|
|
258
308
|
if (context.attrs["model:log"]) {
|
|
259
309
|
console.log(`[ReactiveView]:model`, { config: config2 });
|
|
260
310
|
}
|
|
261
311
|
watch(() => model.getData(), (after, before) => {
|
|
262
|
-
|
|
263
|
-
config2.callback(diff, { component });
|
|
312
|
+
config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
|
|
264
313
|
}, config2.options);
|
|
265
314
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
315
|
+
if (!props.beta) {
|
|
316
|
+
setTimeout(async () => {
|
|
317
|
+
var _a2;
|
|
318
|
+
const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
|
|
319
|
+
watchDataProp(data);
|
|
320
|
+
});
|
|
321
|
+
} else if (props.beta && (isFunctionData || isPromiseData)) {
|
|
322
|
+
setTimeout(async () => {
|
|
323
|
+
var _a2;
|
|
324
|
+
const [data] = await Promise.all([isFunctionData || isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
|
|
325
|
+
model.replaceData(toRaw(unref(data)));
|
|
326
|
+
});
|
|
327
|
+
}
|
|
271
328
|
setTimeout(async () => {
|
|
272
329
|
var _a2;
|
|
273
330
|
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
@@ -301,8 +358,10 @@ var ReactiveView_default = {
|
|
|
301
358
|
};
|
|
302
359
|
|
|
303
360
|
// src/index.ts
|
|
304
|
-
import {
|
|
361
|
+
import { h, unref as unref2, toRaw as toRaw2, createApp, createVNode as createVNode2, defineComponent } from "vue";
|
|
305
362
|
import { formatInTimeZone } from "date-fns-tz";
|
|
363
|
+
import { twMerge } from "tailwind-merge";
|
|
364
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
306
365
|
var index_default = ReactiveView_default;
|
|
307
366
|
function safeRequest(request) {
|
|
308
367
|
return new Promise(async (resolve) => {
|
|
@@ -332,7 +391,7 @@ function safeRequest(request) {
|
|
|
332
391
|
}
|
|
333
392
|
});
|
|
334
393
|
}
|
|
335
|
-
function getProps(props, param2) {
|
|
394
|
+
function getProps(props = {}, param2) {
|
|
336
395
|
var _a;
|
|
337
396
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
338
397
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -377,7 +436,7 @@ function getDate(param1, param2) {
|
|
|
377
436
|
}
|
|
378
437
|
function access(view = {}, alternative) {
|
|
379
438
|
const resolve = (target) => {
|
|
380
|
-
return new Proxy(target, {
|
|
439
|
+
return new Proxy(toRaw2(target), {
|
|
381
440
|
get(target2, key) {
|
|
382
441
|
const component = { tree: target2 };
|
|
383
442
|
do {
|
|
@@ -398,9 +457,8 @@ function access(view = {}, alternative) {
|
|
|
398
457
|
});
|
|
399
458
|
};
|
|
400
459
|
try {
|
|
401
|
-
const component = typeof view === "function" ? view() : view;
|
|
402
|
-
|
|
403
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
460
|
+
const component = unref2(typeof view === "function" ? view() : view);
|
|
461
|
+
return resolve("instance" in component ? component.instance : component);
|
|
404
462
|
} catch (e) {
|
|
405
463
|
return resolve(view);
|
|
406
464
|
}
|
|
@@ -483,37 +541,114 @@ var extendVnode = (component, element) => {
|
|
|
483
541
|
const vnode = getVnode();
|
|
484
542
|
return (props = {}, slots) => {
|
|
485
543
|
var _a;
|
|
486
|
-
const
|
|
487
|
-
const
|
|
544
|
+
const isFunctionClass = typeof props.class === "function";
|
|
545
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
546
|
+
const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
547
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
488
548
|
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
].includes(key2) && typeof value === "function") {
|
|
493
|
-
props2[key2] = value(vnode.props[key2]);
|
|
549
|
+
var _a2;
|
|
550
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
551
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
494
552
|
}
|
|
495
553
|
return props2;
|
|
496
554
|
}, props);
|
|
497
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
555
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
556
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
557
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
558
|
+
return h(finalElement, finalProps, finalSlots);
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
function defineReactiveView(param1, param2) {
|
|
564
|
+
console.log(`log params:`, { param1, param2 });
|
|
565
|
+
return defineComponent({
|
|
566
|
+
name: param1 == null ? void 0 : param1.modelName,
|
|
567
|
+
props: __spreadValues({ setup }, param1 ? param1.props : {}),
|
|
568
|
+
setup() {
|
|
569
|
+
const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
570
|
+
return (component) => {
|
|
571
|
+
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
572
|
+
return Object.assign(props3, { [key]: typeof val === "function" ? val(component) : val });
|
|
573
|
+
}, {});
|
|
574
|
+
const slots = typeof (param1 == null ? void 0 : param1.slots) === "function" ? param1.slots(component) : Array.isArray(param1 == null ? void 0 : param1.slots) ? () => param1.slots : param1 == null ? void 0 : param1.slots;
|
|
575
|
+
return createVNode2(param2 != null ? param2 : ReactiveView_default, __spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
576
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
577
|
+
} : {})), slots);
|
|
503
578
|
};
|
|
504
579
|
}
|
|
505
580
|
});
|
|
581
|
+
}
|
|
582
|
+
function showComponent(component, options = {}) {
|
|
583
|
+
var _a;
|
|
584
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
585
|
+
const container = options.container || "app-dialogs";
|
|
586
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
587
|
+
if (!dialogs.hasAttribute("id")) {
|
|
588
|
+
dialogs.setAttribute("id", container);
|
|
589
|
+
document.body.appendChild(dialogs);
|
|
590
|
+
}
|
|
591
|
+
const dialog = document.createElement("div");
|
|
592
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
593
|
+
dialog.setAttribute("id", id);
|
|
594
|
+
dialogs.appendChild(dialog);
|
|
595
|
+
const app = createApp(
|
|
596
|
+
{
|
|
597
|
+
setup() {
|
|
598
|
+
return () => component;
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
__cleanup__: () => {
|
|
603
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
);
|
|
607
|
+
if (options.router) {
|
|
608
|
+
app.use(options.router).mount(`#${id}`);
|
|
609
|
+
} else {
|
|
610
|
+
app.mount(`#${id}`);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
var getData = (component, path, alternative) => {
|
|
615
|
+
const vue = access(component);
|
|
616
|
+
const data = ObjectManager2.on(componentState(vue));
|
|
617
|
+
if (path) {
|
|
618
|
+
return data.get(dataPath(vue, path), alternative);
|
|
619
|
+
} else {
|
|
620
|
+
return data.get();
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
var setData = (component, data, path) => {
|
|
624
|
+
const vue = access(component);
|
|
625
|
+
const diff = {
|
|
626
|
+
before: ObjectManager2.on(componentState(vue)).clone(),
|
|
627
|
+
after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
|
|
628
|
+
};
|
|
629
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
630
|
+
};
|
|
631
|
+
var componentState = (component) => {
|
|
632
|
+
return unref2("state" in component ? component.state : component.$attrs.state);
|
|
633
|
+
};
|
|
634
|
+
var dataPath = (component, path) => {
|
|
635
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
506
636
|
};
|
|
507
637
|
export {
|
|
508
638
|
MergeStyles,
|
|
509
639
|
StyleParser,
|
|
510
640
|
access,
|
|
641
|
+
dataPath,
|
|
511
642
|
index_default as default,
|
|
643
|
+
defineReactiveView,
|
|
512
644
|
extendVnode,
|
|
645
|
+
getData,
|
|
513
646
|
getDate,
|
|
514
647
|
getProps,
|
|
515
648
|
getReactiveViewComponent,
|
|
516
649
|
safeRequest,
|
|
650
|
+
setData,
|
|
517
651
|
setup,
|
|
652
|
+
showComponent,
|
|
518
653
|
useSubscription
|
|
519
654
|
};
|
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.21",
|
|
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
|
+
}
|