@razaman2/reactive-view 0.0.34-beta.2 → 0.0.34-beta.20
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 +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +176 -48
- package/dist/index.mjs +175 -50
- 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,14 @@ 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(options: Record<string, any>, component: typeof _default, _options: Record<string, any>): ReturnType<typeof defineComponent>;
|
|
125
|
+
declare function showComponent(component: any, options?: {
|
|
126
|
+
container?: string;
|
|
127
|
+
key?: string;
|
|
128
|
+
router?: any;
|
|
129
|
+
}): void;
|
|
130
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
131
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
132
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
118
133
|
|
|
119
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
134
|
+
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,14 @@ 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(options: Record<string, any>, component: typeof _default, _options: Record<string, any>): ReturnType<typeof defineComponent>;
|
|
125
|
+
declare function showComponent(component: any, options?: {
|
|
126
|
+
container?: string;
|
|
127
|
+
key?: string;
|
|
128
|
+
router?: any;
|
|
129
|
+
}): void;
|
|
130
|
+
declare const getData: (component: any, path: number | string, alternative: any) => any;
|
|
131
|
+
declare const setData: (component: any, data: any, path?: string) => any;
|
|
132
|
+
declare const dataPath: (component: any, path: string | number) => any;
|
|
118
133
|
|
|
119
|
-
export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
|
|
134
|
+
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.20";
|
|
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, _h, _i;
|
|
221
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
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
|
((_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) ? [] : {} : {}
|
|
237
259
|
);
|
|
238
260
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
261
|
+
const normalize = (data) => {
|
|
262
|
+
var _a2, _b2, _c2;
|
|
263
|
+
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, data, defaultData);
|
|
264
|
+
if ((0, import_vue.isReactive)(data)) {
|
|
265
|
+
return data;
|
|
266
|
+
} else if ((0, import_vue.isRef)(data)) {
|
|
267
|
+
try {
|
|
268
|
+
if (["Array", "Object"].includes((0, import_vue.unref)(data).constructor.name)) {
|
|
269
|
+
return (0, import_vue.unref)(data);
|
|
270
|
+
} else {
|
|
271
|
+
return (0, import_vue.reactive)({ "": (0, import_vue.unref)(data) });
|
|
272
|
+
}
|
|
273
|
+
} catch (e) {
|
|
274
|
+
return (0, import_vue.reactive)({ "": (0, import_vue.unref)(data) });
|
|
275
|
+
}
|
|
276
|
+
} else {
|
|
277
|
+
if (isFunctionData || isPromiseData) {
|
|
278
|
+
} else {
|
|
279
|
+
try {
|
|
280
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
281
|
+
return (0, import_vue.reactive)(((_a2 = vue.vnode.props) == null ? void 0 : _a2.hasOwnProperty("data")) ? data : defaultData);
|
|
282
|
+
} else {
|
|
283
|
+
return (0, import_vue.reactive)({ "": ((_b2 = vue.vnode.props) == null ? void 0 : _b2.hasOwnProperty("data")) ? data : defaultData });
|
|
284
|
+
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
return (0, import_vue.reactive)({ "": ((_c2 = vue.vnode.props) == null ? void 0 : _c2.hasOwnProperty("data")) ? 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((_f = vue.vnode.props) == null ? void 0 : _f.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 : ((_g = vue.vnode.props) == null ? void 0 : _g.hasOwnProperty("data")) ? 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,23 @@ 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: (_h = context.attrs["model:deep"]) != null ? _h : true
|
|
352
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_i = context.attrs["onUpdate:model"]) != null ? _i : {}).options)
|
|
353
|
+
} : (_j = context.attrs["onUpdate:model"]) != null ? _j : {};
|
|
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
|
+
}
|
|
314
368
|
setTimeout(async () => {
|
|
315
369
|
var _a2;
|
|
316
370
|
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
@@ -346,6 +400,8 @@ var ReactiveView_default = {
|
|
|
346
400
|
// src/index.ts
|
|
347
401
|
var import_vue2 = require("vue");
|
|
348
402
|
var import_date_fns_tz = require("date-fns-tz");
|
|
403
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
404
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
349
405
|
var index_default = ReactiveView_default;
|
|
350
406
|
function safeRequest(request) {
|
|
351
407
|
return new Promise(async (resolve) => {
|
|
@@ -375,7 +431,7 @@ function safeRequest(request) {
|
|
|
375
431
|
}
|
|
376
432
|
});
|
|
377
433
|
}
|
|
378
|
-
function getProps(props, param2) {
|
|
434
|
+
function getProps(props = {}, param2) {
|
|
379
435
|
var _a;
|
|
380
436
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
381
437
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -420,7 +476,7 @@ function getDate(param1, param2) {
|
|
|
420
476
|
}
|
|
421
477
|
function access(view = {}, alternative) {
|
|
422
478
|
const resolve = (target) => {
|
|
423
|
-
return new Proxy(target, {
|
|
479
|
+
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
424
480
|
get(target2, key) {
|
|
425
481
|
const component = { tree: target2 };
|
|
426
482
|
do {
|
|
@@ -441,9 +497,8 @@ function access(view = {}, alternative) {
|
|
|
441
497
|
});
|
|
442
498
|
};
|
|
443
499
|
try {
|
|
444
|
-
const component = typeof view === "function" ? view() : view;
|
|
445
|
-
|
|
446
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
500
|
+
const component = (0, import_vue2.unref)(typeof view === "function" ? view() : view);
|
|
501
|
+
return resolve("instance" in component ? component.instance : component);
|
|
447
502
|
} catch (e) {
|
|
448
503
|
return resolve(view);
|
|
449
504
|
}
|
|
@@ -526,37 +581,110 @@ var extendVnode = (component, element) => {
|
|
|
526
581
|
const vnode = getVnode();
|
|
527
582
|
return (props = {}, slots) => {
|
|
528
583
|
var _a;
|
|
529
|
-
const
|
|
530
|
-
const
|
|
584
|
+
const isFunctionClass = typeof props.class === "function";
|
|
585
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
586
|
+
const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
587
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
531
588
|
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]);
|
|
589
|
+
var _a2;
|
|
590
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
591
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
537
592
|
}
|
|
538
593
|
return props2;
|
|
539
594
|
}, props);
|
|
540
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
595
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
596
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
597
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
598
|
+
return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
function defineReactiveView(param1, param2) {
|
|
604
|
+
console.log(`log params:`, { param1, param2 });
|
|
605
|
+
return (0, import_vue2.defineComponent)({
|
|
606
|
+
props: __spreadValues({ setup }, param1.props),
|
|
607
|
+
setup() {
|
|
608
|
+
const _a = param1, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
609
|
+
return (component) => {
|
|
610
|
+
return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, Object.assign({}, rest, setup2 ? {
|
|
611
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
612
|
+
// @ts-ignore
|
|
613
|
+
} : {}), typeof param1.slots === "function" ? param1.slots(component) : param1.slots);
|
|
546
614
|
};
|
|
547
615
|
}
|
|
548
616
|
});
|
|
617
|
+
}
|
|
618
|
+
function showComponent(component, options = {}) {
|
|
619
|
+
var _a;
|
|
620
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
621
|
+
const container = options.container || "app-dialogs";
|
|
622
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
623
|
+
if (!dialogs.hasAttribute("id")) {
|
|
624
|
+
dialogs.setAttribute("id", container);
|
|
625
|
+
document.body.appendChild(dialogs);
|
|
626
|
+
}
|
|
627
|
+
const dialog = document.createElement("div");
|
|
628
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
629
|
+
dialog.setAttribute("id", id);
|
|
630
|
+
dialogs.appendChild(dialog);
|
|
631
|
+
const app = (0, import_vue2.createApp)(
|
|
632
|
+
{
|
|
633
|
+
setup() {
|
|
634
|
+
return () => component;
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
__cleanup__: () => {
|
|
639
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
if (options.router) {
|
|
644
|
+
app.use(options.router).mount(`#${id}`);
|
|
645
|
+
} else {
|
|
646
|
+
app.mount(`#${id}`);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
var getData = (component, path, alternative) => {
|
|
651
|
+
const vue = access(component);
|
|
652
|
+
const data = import_object_manager2.default.on(componentState(vue));
|
|
653
|
+
if (path) {
|
|
654
|
+
return data.get(dataPath(vue, path), alternative);
|
|
655
|
+
} else {
|
|
656
|
+
return data.get();
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
var setData = (component, data, path) => {
|
|
660
|
+
const vue = access(component);
|
|
661
|
+
const diff = {
|
|
662
|
+
before: import_object_manager2.default.on(componentState(vue)).clone(),
|
|
663
|
+
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()
|
|
664
|
+
};
|
|
665
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
666
|
+
};
|
|
667
|
+
var componentState = (component) => {
|
|
668
|
+
return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
|
|
669
|
+
};
|
|
670
|
+
var dataPath = (component, path) => {
|
|
671
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
549
672
|
};
|
|
550
673
|
// Annotate the CommonJS export names for ESM import in node:
|
|
551
674
|
0 && (module.exports = {
|
|
552
675
|
MergeStyles,
|
|
553
676
|
StyleParser,
|
|
554
677
|
access,
|
|
678
|
+
dataPath,
|
|
679
|
+
defineReactiveView,
|
|
555
680
|
extendVnode,
|
|
681
|
+
getData,
|
|
556
682
|
getDate,
|
|
557
683
|
getProps,
|
|
558
684
|
getReactiveViewComponent,
|
|
559
685
|
safeRequest,
|
|
686
|
+
setData,
|
|
560
687
|
setup,
|
|
688
|
+
showComponent,
|
|
561
689
|
useSubscription
|
|
562
690
|
});
|
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, 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.20";
|
|
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, _h, _i;
|
|
175
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
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
|
((_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) ? [] : {} : {}
|
|
194
213
|
);
|
|
195
214
|
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
215
|
+
const normalize = (data) => {
|
|
216
|
+
var _a2, _b2, _c2;
|
|
217
|
+
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, data, defaultData);
|
|
218
|
+
if (isReactive(data)) {
|
|
219
|
+
return data;
|
|
220
|
+
} else if (isRef(data)) {
|
|
221
|
+
try {
|
|
222
|
+
if (["Array", "Object"].includes(unref(data).constructor.name)) {
|
|
223
|
+
return unref(data);
|
|
224
|
+
} else {
|
|
225
|
+
return reactive({ "": unref(data) });
|
|
226
|
+
}
|
|
227
|
+
} catch (e) {
|
|
228
|
+
return reactive({ "": unref(data) });
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
if (isFunctionData || isPromiseData) {
|
|
232
|
+
} else {
|
|
233
|
+
try {
|
|
234
|
+
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
235
|
+
return reactive(((_a2 = vue.vnode.props) == null ? void 0 : _a2.hasOwnProperty("data")) ? data : defaultData);
|
|
236
|
+
} else {
|
|
237
|
+
return reactive({ "": ((_b2 = vue.vnode.props) == null ? void 0 : _b2.hasOwnProperty("data")) ? data : defaultData });
|
|
238
|
+
}
|
|
239
|
+
} catch (e) {
|
|
240
|
+
return reactive({ "": ((_c2 = vue.vnode.props) == null ? void 0 : _c2.hasOwnProperty("data")) ? 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((_f = vue.vnode.props) == null ? void 0 : _f.data) : reactive(ObjectManager.on(
|
|
247
|
+
isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_g = vue.vnode.props) == null ? void 0 : _g.hasOwnProperty("data")) ? 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,23 @@ 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: (_h = context.attrs["model:deep"]) != null ? _h : true
|
|
306
|
+
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_i = context.attrs["onUpdate:model"]) != null ? _i : {}).options)
|
|
307
|
+
} : (_j = context.attrs["onUpdate:model"]) != null ? _j : {};
|
|
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
|
+
}
|
|
271
322
|
setTimeout(async () => {
|
|
272
323
|
var _a2;
|
|
273
324
|
isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
|
|
@@ -301,8 +352,10 @@ var ReactiveView_default = {
|
|
|
301
352
|
};
|
|
302
353
|
|
|
303
354
|
// src/index.ts
|
|
304
|
-
import {
|
|
355
|
+
import { h, unref as unref2, toRaw, createApp, createVNode as createVNode2, defineComponent } from "vue";
|
|
305
356
|
import { formatInTimeZone } from "date-fns-tz";
|
|
357
|
+
import { twMerge } from "tailwind-merge";
|
|
358
|
+
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
306
359
|
var index_default = ReactiveView_default;
|
|
307
360
|
function safeRequest(request) {
|
|
308
361
|
return new Promise(async (resolve) => {
|
|
@@ -332,7 +385,7 @@ function safeRequest(request) {
|
|
|
332
385
|
}
|
|
333
386
|
});
|
|
334
387
|
}
|
|
335
|
-
function getProps(props, param2) {
|
|
388
|
+
function getProps(props = {}, param2) {
|
|
336
389
|
var _a;
|
|
337
390
|
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
338
391
|
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
@@ -377,7 +430,7 @@ function getDate(param1, param2) {
|
|
|
377
430
|
}
|
|
378
431
|
function access(view = {}, alternative) {
|
|
379
432
|
const resolve = (target) => {
|
|
380
|
-
return new Proxy(target, {
|
|
433
|
+
return new Proxy(toRaw(target), {
|
|
381
434
|
get(target2, key) {
|
|
382
435
|
const component = { tree: target2 };
|
|
383
436
|
do {
|
|
@@ -398,9 +451,8 @@ function access(view = {}, alternative) {
|
|
|
398
451
|
});
|
|
399
452
|
};
|
|
400
453
|
try {
|
|
401
|
-
const component = typeof view === "function" ? view() : view;
|
|
402
|
-
|
|
403
|
-
return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
|
|
454
|
+
const component = unref2(typeof view === "function" ? view() : view);
|
|
455
|
+
return resolve("instance" in component ? component.instance : component);
|
|
404
456
|
} catch (e) {
|
|
405
457
|
return resolve(view);
|
|
406
458
|
}
|
|
@@ -483,37 +535,110 @@ var extendVnode = (component, element) => {
|
|
|
483
535
|
const vnode = getVnode();
|
|
484
536
|
return (props = {}, slots) => {
|
|
485
537
|
var _a;
|
|
486
|
-
const
|
|
487
|
-
const
|
|
538
|
+
const isFunctionClass = typeof props.class === "function";
|
|
539
|
+
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
540
|
+
const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
541
|
+
const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
|
|
488
542
|
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]);
|
|
543
|
+
var _a2;
|
|
544
|
+
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
545
|
+
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
494
546
|
}
|
|
495
547
|
return props2;
|
|
496
548
|
}, props);
|
|
497
|
-
const finalProps = Object.assign(rest, functionalProps, {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
|
|
502
|
-
return h(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
|
|
549
|
+
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
550
|
+
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
551
|
+
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
552
|
+
return h(finalElement, finalProps, finalSlots);
|
|
503
553
|
};
|
|
504
554
|
}
|
|
505
555
|
});
|
|
506
556
|
};
|
|
557
|
+
function defineReactiveView(param1, param2) {
|
|
558
|
+
console.log(`log params:`, { param1, param2 });
|
|
559
|
+
return defineComponent({
|
|
560
|
+
props: __spreadValues({ setup }, param1.props),
|
|
561
|
+
setup() {
|
|
562
|
+
const _a = param1, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
563
|
+
return (component) => {
|
|
564
|
+
return createVNode2(param2 != null ? param2 : ReactiveView_default, Object.assign({}, rest, setup2 ? {
|
|
565
|
+
setup: (self, parent) => setup2(self, parent, component)
|
|
566
|
+
// @ts-ignore
|
|
567
|
+
} : {}), typeof param1.slots === "function" ? param1.slots(component) : param1.slots);
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
function showComponent(component, options = {}) {
|
|
573
|
+
var _a;
|
|
574
|
+
if (!options.key || !document.getElementById(options.key)) {
|
|
575
|
+
const container = options.container || "app-dialogs";
|
|
576
|
+
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
577
|
+
if (!dialogs.hasAttribute("id")) {
|
|
578
|
+
dialogs.setAttribute("id", container);
|
|
579
|
+
document.body.appendChild(dialogs);
|
|
580
|
+
}
|
|
581
|
+
const dialog = document.createElement("div");
|
|
582
|
+
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
583
|
+
dialog.setAttribute("id", id);
|
|
584
|
+
dialogs.appendChild(dialog);
|
|
585
|
+
const app = createApp(
|
|
586
|
+
{
|
|
587
|
+
setup() {
|
|
588
|
+
return () => component;
|
|
589
|
+
}
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
__cleanup__: () => {
|
|
593
|
+
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
);
|
|
597
|
+
if (options.router) {
|
|
598
|
+
app.use(options.router).mount(`#${id}`);
|
|
599
|
+
} else {
|
|
600
|
+
app.mount(`#${id}`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
var getData = (component, path, alternative) => {
|
|
605
|
+
const vue = access(component);
|
|
606
|
+
const data = ObjectManager2.on(componentState(vue));
|
|
607
|
+
if (path) {
|
|
608
|
+
return data.get(dataPath(vue, path), alternative);
|
|
609
|
+
} else {
|
|
610
|
+
return data.get();
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
var setData = (component, data, path) => {
|
|
614
|
+
const vue = access(component);
|
|
615
|
+
const diff = {
|
|
616
|
+
before: ObjectManager2.on(componentState(vue)).clone(),
|
|
617
|
+
after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
|
|
618
|
+
};
|
|
619
|
+
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
620
|
+
};
|
|
621
|
+
var componentState = (component) => {
|
|
622
|
+
return unref2("state" in component ? component.state : component.$attrs.state);
|
|
623
|
+
};
|
|
624
|
+
var dataPath = (component, path) => {
|
|
625
|
+
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
626
|
+
};
|
|
507
627
|
export {
|
|
508
628
|
MergeStyles,
|
|
509
629
|
StyleParser,
|
|
510
630
|
access,
|
|
631
|
+
dataPath,
|
|
511
632
|
index_default as default,
|
|
633
|
+
defineReactiveView,
|
|
512
634
|
extendVnode,
|
|
635
|
+
getData,
|
|
513
636
|
getDate,
|
|
514
637
|
getProps,
|
|
515
638
|
getReactiveViewComponent,
|
|
516
639
|
safeRequest,
|
|
640
|
+
setData,
|
|
517
641
|
setup,
|
|
642
|
+
showComponent,
|
|
518
643
|
useSubscription
|
|
519
644
|
};
|
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.20",
|
|
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
|
+
}
|