@razaman2/reactive-view 0.1.0-beta.15 → 0.1.0-beta.17

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.mjs CHANGED
@@ -1,917 +1,942 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
1
+ import e from "@razaman2/object-manager";
2
+ import t from "@razaman2/data-manager";
3
+ import { computed as n, createTextVNode as r, createVNode as i, defineComponent as a, getCurrentInstance as o, h as s, isReactive as c, isRef as l, mergeProps as u, nextTick as d, onBeforeUnmount as f, onMounted as p, provide as m, reactive as h, ref as g, render as _, resolveComponent as v, toRaw as y, unref as b, watch as x, watchEffect as S } from "vue";
4
+ import { formatInTimeZone as C } from "date-fns-tz";
5
+ import { twMerge as w } from "tailwind-merge";
6
+ //#region src/Subscription.ts
7
+ var T = class e {
8
+ subscriptions = [];
9
+ data = {};
10
+ static create() {
11
+ return new e();
12
+ }
13
+ subscribe(e, t, n) {
14
+ return this.isNameAvailable(e) && (this.subscriptions.push({
15
+ name: e,
16
+ handler: t
17
+ }), this.data[e] = n), this;
18
+ }
19
+ replace(e, t, n) {
20
+ return this.unsubscribe(e), this.subscribe(e, t, n);
21
+ }
22
+ unsubscribe(e) {
23
+ Array.isArray(e) || (e = e ? [e] : []);
24
+ let t = (e) => console.log(`%cUnsubscribed From Subscription (${e})`, "background-color: yellow; color: green; font-weight: bold; padding: 3px;");
25
+ return e.length ? e.forEach((e) => {
26
+ let n = this.find(e);
27
+ n && (n.handler(), this.remove(n), t(e));
28
+ }) : (this.subscriptions.forEach((e) => {
29
+ e.handler(), t(e.name);
30
+ }), this.subscriptions = []), this;
31
+ }
32
+ size() {
33
+ return this.subscriptions.length;
34
+ }
35
+ hasSubscription(e) {
36
+ return !!this.find(e);
37
+ }
38
+ remove(e) {
39
+ this.subscriptions.splice(this.subscriptions.indexOf(e), 1);
40
+ }
41
+ find(e) {
42
+ return this.subscriptions.find((t) => t.name === e);
43
+ }
44
+ isNameAvailable(e) {
45
+ if (this.hasSubscription(e)) throw Error(`There is already a subscription called "${e}".`);
46
+ return !0;
47
+ }
48
+ registrations() {
49
+ return this.subscriptions;
50
+ }
51
+ get(e) {
52
+ let t = this.find(e);
53
+ if (t) return t;
54
+ throw Error(`Subscription "${e}" doesn't exist!`);
55
+ }
56
+ }, E = class e extends T {
57
+ static subscriptions = e.create();
58
+ static get() {
59
+ return this.subscriptions;
60
+ }
61
+ }, D = {
62
+ name: "@razaman2/reactive-view",
63
+ version: "0.1.0-beta.17",
64
+ 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.",
65
+ main: "dist/index.js",
66
+ module: "dist/index.mjs",
67
+ types: "dist/index.d.ts",
68
+ exports: { ".": {
69
+ types: "./dist/index.d.ts",
70
+ require: "./dist/index.js",
71
+ import: "./dist/index.mjs"
72
+ } },
73
+ scripts: {
74
+ prepublishOnly: "npm run build",
75
+ build: "vue-tsc -p tsconfig.build.json && vite build",
76
+ lint: "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
77
+ "lint:fix": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix",
78
+ format: "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
79
+ typecheck: "tsc",
80
+ test: "vitest run",
81
+ "test:watch": "vitest",
82
+ pr: "sh pr.sh"
83
+ },
84
+ keywords: [
85
+ "vue",
86
+ "vue-helper",
87
+ "reactive-view",
88
+ "vue-class-component",
89
+ "reactive-ui"
90
+ ],
91
+ repository: {
92
+ type: "git",
93
+ url: "git+https://github.com/razaman2/reactive-view.git"
94
+ },
95
+ bugs: { url: "https://github.com/razaman2/reactive-view/issues" },
96
+ homepage: "https://github.com/razaman2/reactive-view#readme",
97
+ author: "razaman2",
98
+ license: "MIT",
99
+ dependencies: {
100
+ "@razaman2/data-manager": "^3.3.12",
101
+ "@razaman2/event-emitter": "^2.1.1",
102
+ "@razaman2/object-manager": "^3.4.7",
103
+ "date-fns": "^4.1.0",
104
+ "date-fns-tz": "^3.2.0",
105
+ "tailwind-merge": "^3.5.0"
106
+ },
107
+ peerDependencies: { vue: ">=3.0.0" },
108
+ devDependencies: {
109
+ "@eslint/js": "^10.0.1",
110
+ "@stylistic/eslint-plugin": "^5.10.0",
111
+ "@typescript-eslint/eslint-plugin": "^8.59.2",
112
+ "@typescript-eslint/parser": "^8.59.2",
113
+ "@vitejs/plugin-vue": "^6.0.6",
114
+ "@vitejs/plugin-vue-jsx": "^5.1.5",
115
+ "@vue/server-renderer": "^3.5.34",
116
+ "@vue/test-utils": "^2.4.10",
117
+ eslint: "^10.3.0",
118
+ "eslint-config-prettier": "^10.1.8",
119
+ "eslint-plugin-prettier": "^5.5.5",
120
+ "eslint-plugin-vue": "^10.9.1",
121
+ jsdom: "^29.1.1",
122
+ prettier: "^3.8.3",
123
+ typescript: "^5.9.3",
124
+ "typescript-eslint": "^8.59.2",
125
+ vite: "^8.0.11",
126
+ vitest: "^4.1.5",
127
+ "vue-tsc": "^3.2.8"
128
+ },
129
+ publishConfig: { access: "public" },
130
+ files: ["dist"]
131
+ }, O = {
132
+ type: Function,
133
+ default: (e = {}, t = {}) => t,
134
+ ReactiveView: !0
135
+ }, k = {
136
+ props: {
137
+ setup: {},
138
+ beta: [Boolean, String],
139
+ ReactiveView: {
140
+ type: Boolean,
141
+ default: !0
142
+ },
143
+ instance: { default: g() },
144
+ notifications: Object,
145
+ subscriptions: Object,
146
+ beforeSetData: Function,
147
+ data: { default: h({}) },
148
+ defaultData: {},
149
+ getDefaultData: {
150
+ type: Function,
151
+ default: (e) => e
152
+ },
153
+ model: {},
154
+ defer: {},
155
+ logging: { validator: (e) => ["Boolean"].includes(e.constructor.name) },
156
+ modelName: {
157
+ type: String,
158
+ default: "ReactiveView"
159
+ },
160
+ debug: {
161
+ type: Boolean,
162
+ default: !1
163
+ },
164
+ state: { default: h({}) }
165
+ },
166
+ setup(n, r) {
167
+ let a = [];
168
+ f(() => a.forEach((e) => e()));
169
+ let s = (t, n) => {
170
+ let r = g(!1), i = Array.from(new Set(t.paths().concat(n.paths()))).reduce((e, i) => (t.get(i) !== n.get(i) && (e.set(i, n.get(i)), r.value = !0), e), e.on({}));
171
+ return {
172
+ before: t.get(),
173
+ after: n.get(),
174
+ changes: i.get(),
175
+ changed: r.value
176
+ };
177
+ }, u = (e) => {
178
+ let t = r.attrs["data:path"];
179
+ return typeof t == "function" ? t(e) : e;
180
+ }, p = (e, t) => i("div", r.slots.default ? r.attrs : {
181
+ style: {
182
+ color: "red",
183
+ textAlign: "center"
184
+ },
185
+ ...r.attrs
186
+ }, r.slots.default ? r.slots.default({
187
+ component: e,
188
+ vue: t,
189
+ props: n,
190
+ context: r
191
+ }) : `${n.modelName}: ${D.name}@${D.version}`), m = g(!1), _ = g(!1), v = g(typeof n.defer == "function" ? n.defer() : n.defer), y = ["Function"].includes(n.data?.constructor.name), S = ["AsyncFunction"].includes(n.data?.constructor.name), C = ["Promise"].includes(n.data?.constructor.name) || S, w = o(), T = n.getDefaultData("defaultData" in w.vnode.props ? w.vnode.props.defaultData : "data" in w.vnode.props && Array.isArray(b(w.vnode.props.data)) ? [] : {}), E = Array.isArray(T) ? [] : {};
192
+ return n.beta === "current" ? (() => {
193
+ let i = (e, t) => {
194
+ if (w && w.vnode.el) {
195
+ let n = new CustomEvent("data:emit", {
196
+ bubbles: !0,
197
+ composed: !0,
198
+ detail: {
199
+ before: t,
200
+ after: e
201
+ }
202
+ });
203
+ w.vnode.el.dispatchEvent(n);
204
+ }
205
+ }, o = {
206
+ data: n.beta ? ((e) => {
207
+ if (n.debug && console.warn(`[ReactiveView]: using beta props data in [${n.modelName}] component`, {
208
+ vue: w,
209
+ data: e,
210
+ defaultData: T,
211
+ isRef: l(e),
212
+ isReactive: c(e)
213
+ }), c(e)) return e;
214
+ if (l(e) || y || C) return h(E);
215
+ {
216
+ let t = "data" in w.vnode.props;
217
+ try {
218
+ return ["Array", "Object"].includes(e?.constructor?.name) ? h(t ? e : E) : h(t ? { "": e } : E);
219
+ } catch {
220
+ return h(t ? { "": e } : E);
221
+ }
222
+ }
223
+ })(w.vnode.props?.data) : h(e.on(C || y || l(n.data) || c(n.data) ? E : "data" in w.vnode.props ? n.data : E).clone()),
224
+ defaultData: e.on(T).clone(),
225
+ notifications: n.notifications,
226
+ subscriptions: n.subscriptions,
227
+ name: n.modelName,
228
+ logging: n.logging
229
+ }, d = new Proxy(n.model ? typeof n.model == "function" ? n.model(o) : n.model : new t(o), { get(t, r, i) {
230
+ return ["setData", "replaceData"].includes(r.toString()) ? (...i) => {
231
+ let a = B(f).beforeSetData ?? n.beforeSetData;
232
+ if (typeof a == "function") {
233
+ let n = e.on(t.getData()), o = i.length ? e.on(E).set(...i) : e.on(E).set(T);
234
+ a(B(f).diff(n, o), t) && t[r](...i);
235
+ } else t[r](...i);
236
+ return t;
237
+ } : Reflect.get(t, r, i);
238
+ } }), f = g({
239
+ parent: { self: w.proxy },
240
+ self: {
241
+ template: p,
242
+ model: d,
243
+ diff: s,
244
+ emit: i,
245
+ dataPath: u,
246
+ isValid: m
247
+ }
248
+ });
249
+ n.debug && console.warn("[ReactiveView]:", {
250
+ props: n,
251
+ context: r,
252
+ vue: w,
253
+ defer: v,
254
+ config: o,
255
+ model: d,
256
+ component: f,
257
+ datatype: E,
258
+ defaultData: T,
259
+ isValid: m,
260
+ isReady: _,
261
+ isFunctionData: y,
262
+ isAsyncFunctionData: S,
263
+ isAsyncData: C
264
+ });
265
+ let b = (t) => {
266
+ let n = typeof r.attrs["onUpdate:data"] == "function" ? { callback: r.attrs["onUpdate:data"] } : {
267
+ callback: (r.attrs["onUpdate:data"] ?? {}).callback ?? r.attrs["data:callback"],
268
+ options: Object.assign({
269
+ deep: r.attrs["data:deep"] ?? !0,
270
+ ...r.attrs["data:immediate"] ? { immediate: r.attrs["data:immediate"] } : {},
271
+ ...r.attrs["data:once"] ? { once: r.attrs["data:once"] } : {}
272
+ }, (r.attrs["onUpdate:data"] ?? {}).options)
273
+ };
274
+ r.attrs["data:log"] && console.warn("[ReactiveView]:data", {
275
+ config: n,
276
+ dataProp: t
277
+ }), a.push(x(y || l(t) || c(t) ? t : () => t, (t, r) => {
278
+ typeof n.callback == "function" ? d.replaceData(n.callback(B(f).diff(e.on(r), e.on(t)), { component: f }) ?? t) : d.replaceData(t);
279
+ }, n.options));
280
+ };
281
+ if (r.attrs["onUpdate:model"] || r.attrs["update:model"]) {
282
+ let t = typeof r.attrs["onUpdate:model"] == "function" ? {
283
+ callback: r.attrs["onUpdate:model"],
284
+ options: Object.assign({
285
+ deep: r.attrs["model:deep"] ?? !0,
286
+ ...r.attrs["model:immediate"] ? { immediate: r.attrs["model:immediate"] } : {},
287
+ ...r.attrs["model:once"] ? { once: r.attrs["model:once"] } : {}
288
+ }, (r.attrs["onUpdate:model"] ?? {}).options)
289
+ } : r.attrs["onUpdate:model"] ?? {};
290
+ r.attrs["model:log"] && console.warn("[ReactiveView]:model", { config: t }), a.push(x(() => e.on(d.getData()).clone(), (n, r) => {
291
+ t.callback(B(f).diff(e.on(r), e.on(n)), { component: f });
292
+ }, t.options));
293
+ }
294
+ if (n.beta) {
295
+ let t = l(n.data);
296
+ (t || y || C) && setTimeout(async () => {
297
+ let [i] = C ? await Promise.all([S ? n.data() : n.data, v.value ?? !0]) : [n.data];
298
+ a.push(x(t || y || typeof i == "function" ? i : () => i, (t, n) => {
299
+ if (n !== void 0 || t !== void 0) {
300
+ let i = r.attrs["data:callback"];
301
+ if (typeof i == "function") {
302
+ let r = B(f).diff(e.on(n), e.on(t));
303
+ d.replaceData(i(r, { component: f }) ?? t);
304
+ } else d.replaceData(t);
305
+ }
306
+ }, {
307
+ immediate: r.attrs["data:immediate"] ?? !0,
308
+ deep: r.attrs["data:deep"] ?? !0,
309
+ once: r.attrs["data:once"]
310
+ }));
311
+ });
312
+ } else setTimeout(async () => {
313
+ let [e] = await Promise.all([S ? n.data() : n.data, v.value ?? !0]);
314
+ b(e);
315
+ });
316
+ return setTimeout(async () => {
317
+ _.value = await v.value ?? !0;
318
+ }), f.value = [B(f)].reduce((e, t) => {
319
+ for (; t && typeof t.setup == "function" && (e = {
320
+ parent: e,
321
+ self: t.setup(f, e) ?? {}
322
+ }, !B(t.$parent).ReactiveView);) t = B(t.$parent);
323
+ return e;
324
+ }, f.value), n.instance.value = typeof n.instance == "function" ? n.instance(f.value) : f.value, (e) => _.value ? B(f).template(f, e) : r.slots.loading?.({ component: f });
325
+ })() : (() => {
326
+ let i = (e, t) => {
327
+ if (w && w.vnode.el) {
328
+ let n = new CustomEvent("emit:data", {
329
+ bubbles: !0,
330
+ composed: !0,
331
+ detail: {
332
+ before: t,
333
+ after: e
334
+ }
335
+ });
336
+ B(O).setData(e), w.vnode.el.dispatchEvent(n), w.vnode.el.dispatchEvent(new CustomEvent("data:emit", {
337
+ bubbles: !0,
338
+ composed: !0,
339
+ detail: {
340
+ before: t,
341
+ after: e
342
+ }
343
+ }));
344
+ }
345
+ }, o = (e) => B(O).model.setData(e), f = (t) => new Proxy(t, { get(t, r, i) {
346
+ return ["setData", "replaceData"].includes(r.toString()) ? (...i) => {
347
+ let a = B(O).beforeSetData ?? n.beforeSetData;
348
+ if (typeof a == "function") {
349
+ let n = e.on(t.getData()), o = i.length ? e.on(E).set(...i) : e.on(E).set(T);
350
+ a(B(O).diff(n, o), t) && t[r](...i);
351
+ } else t[r](...i);
352
+ return t;
353
+ } : Reflect.get(t, r, i);
354
+ } }), h = {
355
+ data: ((e) => {
356
+ if (l(e) || c(e)) return e;
357
+ if (y || C) return g(E);
358
+ {
359
+ let t = "data" in w.vnode.props;
360
+ try {
361
+ return ["Array", "Object"].includes(e?.constructor?.name) ? g(e) : g(t ? { "": e } : E);
362
+ } catch {
363
+ return g(t ? { "": e } : E);
364
+ }
365
+ }
366
+ })(w.vnode.props?.data),
367
+ defaultData: e.on(T).clone(),
368
+ notifications: n.notifications,
369
+ subscriptions: n.subscriptions,
370
+ name: n.modelName,
371
+ logging: n.logging
372
+ }, D = n.model ? typeof n.model == "function" ? n.model(h) : n.model : t.setConfig({ beforeGetData: (e) => l(e) ? b(e) : e }, h), O = g({
373
+ parent: { self: w.proxy },
374
+ self: {
375
+ template: p,
376
+ diff: s,
377
+ emit: i,
378
+ setData: o,
379
+ dataPath: u,
380
+ model: f(D),
381
+ isValid: m
382
+ }
383
+ });
384
+ if (r.attrs["onUpdate:model"] || r.attrs["update:model"]) {
385
+ let t = {
386
+ callback: typeof r.attrs["onUpdate:model"] == "function" ? r.attrs["onUpdate:model"] : r.attrs["update:model"],
387
+ options: {
388
+ immediate: r.attrs["model:immediate"],
389
+ deep: r.attrs["model:deep"],
390
+ once: r.attrs["model:once"]
391
+ }
392
+ };
393
+ a.push(x(() => e.on(D.getData()).clone(), (r, i) => {
394
+ let a = B(O).diff(e.on(i), e.on(r));
395
+ n.debug && console.warn(`[${n.modelName}]:model`, {
396
+ diff: a,
397
+ before: i,
398
+ after: r
399
+ }), a.changed && t.callback(a, { component: O });
400
+ }, t.options));
401
+ }
402
+ return d(async () => {
403
+ if (n.model !== !1) {
404
+ (y || C) && !("defaultData" in w.vnode.props) && console.warn(`${n.modelName}: defaultData is required for promise or function data.`, n.data);
405
+ let [t] = C ? await Promise.all([S ? n.data() : n.data, v.value ?? !0]) : [n.data], i = l(t) || c(t), o = typeof t == "function" || i ? t : () => t;
406
+ a.push(x(o, async (i, a) => {
407
+ let o = B(O).diff(e.on(a), e.on(i)), s = r.attrs["data:callback"];
408
+ n.debug && console.warn(`[${n.modelName}]:data`, {
409
+ diff: o,
410
+ data: t,
411
+ callback: s,
412
+ props: n,
413
+ context: r,
414
+ component: O
415
+ }), typeof s == "function" ? s(o, { component: O }) : D.replaceData(i);
416
+ }, {
417
+ immediate: r.attrs["data:immediate"] ?? !i,
418
+ deep: r.attrs["data:deep"],
419
+ once: r.attrs["data:once"]
420
+ }));
421
+ }
422
+ }), d(async () => {
423
+ _.value = await v.value ?? !0;
424
+ }), O.value = [B(O)].reduce((e, t) => {
425
+ for (; t && typeof t.setup == "function" && (e = {
426
+ parent: e,
427
+ self: t.setup(O, e) ?? {}
428
+ }, !B(t.$parent).ReactiveView);) t = B(t.$parent);
429
+ return e;
430
+ }, O.value), n.instance.value = typeof n.instance == "function" ? n.instance(O.value) : O.value, (e) => _.value ? B(O).template(O, e) : r.slots.loading?.({ component: O });
431
+ })();
432
+ }
18
433
  };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
-
33
- // src/index.ts
34
- import ObjectManager2 from "@razaman2/object-manager";
35
-
36
- // src/Subscription.ts
37
- var Subscription = class _Subscription {
38
- constructor() {
39
- this.subscriptions = [];
40
- this.data = {};
41
- }
42
- static create() {
43
- return new _Subscription();
44
- }
45
- subscribe(name, handler, data) {
46
- if (this.isNameAvailable(name)) {
47
- this.subscriptions.push({
48
- name,
49
- handler
50
- });
51
- this.data[name] = data;
52
- }
53
- return this;
54
- }
55
- replace(name, handler, data) {
56
- this.unsubscribe(name);
57
- return this.subscribe(name, handler, data);
58
- }
59
- unsubscribe(param1) {
60
- if (!Array.isArray(param1)) {
61
- param1 = param1 ? [param1] : [];
62
- }
63
- const log = (name) => {
64
- return console.log(`%cUnsubscribed From Subscription (${name})`, "background-color: yellow; color: green; font-weight: bold; padding: 3px;");
65
- };
66
- if (param1.length) {
67
- param1.forEach((name) => {
68
- const subscription = this.find(name);
69
- if (subscription) {
70
- subscription.handler();
71
- this.remove(subscription);
72
- log(name);
73
- }
74
- });
75
- } else {
76
- this.subscriptions.forEach((subscription) => {
77
- subscription.handler();
78
- log(subscription.name);
79
- });
80
- this.subscriptions = [];
81
- }
82
- return this;
83
- }
84
- size() {
85
- return this.subscriptions.length;
86
- }
87
- hasSubscription(name) {
88
- return Boolean(this.find(name));
89
- }
90
- remove(subscription) {
91
- this.subscriptions.splice(this.subscriptions.indexOf(subscription), 1);
92
- }
93
- find(name) {
94
- return this.subscriptions.find((subscription) => {
95
- return subscription.name === name;
96
- });
97
- }
98
- isNameAvailable(name) {
99
- if (this.hasSubscription(name)) {
100
- throw new Error(`There is already a subscription called "${name}".`);
101
- } else {
102
- return true;
103
- }
104
- }
105
- registrations() {
106
- return this.subscriptions;
107
- }
108
- get(name) {
109
- const subscription = this.find(name);
110
- if (subscription) {
111
- return subscription;
112
- } else {
113
- throw new Error(`Subscription "${name}" doesn't exist!`);
114
- }
115
- }
116
- };
117
-
118
- // src/Subscriptions.ts
119
- var _Subscriptions = class _Subscriptions extends Subscription {
120
- static get() {
121
- return this.subscriptions;
122
- }
123
- };
124
- _Subscriptions.subscriptions = _Subscriptions.create();
125
- var Subscriptions = _Subscriptions;
126
-
127
- // src/ReactiveView.ts
128
- import ObjectManager from "@razaman2/object-manager";
129
- import DataManager from "@razaman2/data-manager";
130
- import { ref, reactive, watch, unref, isRef, isReactive, createVNode, getCurrentInstance, onBeforeUnmount } from "vue";
131
-
132
- // package.json
133
- var version = "0.1.0-beta.15";
134
- var package_default = {
135
- name: "@razaman2/reactive-view",
136
- version,
137
- 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.",
138
- main: "dist/index.js",
139
- module: "dist/index.mjs",
140
- types: "dist/index.d.ts",
141
- scripts: {
142
- prepublishOnly: "npm run build",
143
- build: "tsup src/index.ts --format cjs,esm --dts",
144
- lint: "tsc",
145
- test: "cd tests/vue-ts && npm run dev",
146
- pr: "sh pr.sh"
147
- },
148
- keywords: [
149
- "vue",
150
- "vue-helper",
151
- "reactive-view",
152
- "vue-class-component",
153
- "reactive-ui"
154
- ],
155
- author: "razaman2",
156
- license: "MIT",
157
- dependencies: {
158
- "@razaman2/data-manager": "^3.3.8",
159
- "@razaman2/event-emitter": "^2.1.1",
160
- "@razaman2/object-manager": "^3.4.7",
161
- "date-fns": "^4.1.0",
162
- "date-fns-tz": "^3.2.0",
163
- "tailwind-merge": "^3.5.0",
164
- uuid: "^13.0.0"
165
- },
166
- peerDependencies: {
167
- vue: ">=3.0.0"
168
- },
169
- devDependencies: {
170
- "@types/uuid": "^11.0.0",
171
- tsup: "^8.5.1",
172
- typescript: "^5.9.3",
173
- vitest: "^4.1.2"
174
- },
175
- publishConfig: {
176
- access: "public"
177
- },
178
- files: [
179
- "dist"
180
- ]
181
- };
182
-
183
- // src/ReactiveView.ts
184
- var setup = {
185
- type: Function,
186
- default: (parent = {}, self = {}) => self,
187
- ReactiveView: true
188
- };
189
- var ReactiveView_default = {
190
- props: {
191
- setup: {},
192
- beta: [Boolean, String],
193
- ReactiveView: {
194
- type: Boolean,
195
- default: true
196
- },
197
- instance: { default: ref() },
198
- notifications: Object,
199
- subscriptions: Object,
200
- beforeSetData: Function,
201
- data: { default: reactive({}) },
202
- defaultData: {},
203
- getDefaultData: {
204
- type: Function,
205
- default: (data) => data
206
- },
207
- model: {},
208
- defer: {},
209
- logging: {
210
- validator: (logging) => {
211
- return ["Boolean"].includes(logging.constructor.name);
212
- }
213
- },
214
- modelName: {
215
- type: String,
216
- default: "ReactiveView"
217
- },
218
- debug: {
219
- type: Boolean,
220
- default: false
221
- },
222
- state: { default: reactive({}) }
223
- },
224
- setup(props, context) {
225
- var _a, _b, _c;
226
- const subscriptions = [];
227
- onBeforeUnmount(() => subscriptions.forEach((subscription) => subscription()));
228
- const diff = (before, after) => {
229
- const changed = ref(false);
230
- const paths = Array.from(new Set(before.paths().concat(after.paths())));
231
- const changes = paths.reduce((changes2, path) => {
232
- if (before.get(path) !== after.get(path)) {
233
- changes2.set(path, after.get(path));
234
- changed.value = true;
235
- }
236
- return changes2;
237
- }, ObjectManager.on({}));
238
- return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
239
- };
240
- const dataPath2 = (path) => {
241
- try {
242
- return context.attrs["data:path"](path);
243
- } catch (e) {
244
- return path;
245
- }
246
- };
247
- const template = (component, vue2) => {
248
- return createVNode("div", context.slots.default ? context.attrs : __spreadValues({
249
- style: { color: "red", textAlign: "center" }
250
- }, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${package_default.name}@${package_default.version}`);
251
- };
252
- const isValid = ref(false);
253
- const isReady = ref(false);
254
- const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
255
- const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
256
- const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
257
- const isAsyncData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
258
- const vue = getCurrentInstance();
259
- const defaultData = props.getDefaultData(
260
- "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(unref(vue.vnode.props.data)) ? [] : {} : {}
261
- );
262
- const datatype = Array.isArray(defaultData) ? [] : {};
263
- const beta = () => {
264
- var _a2;
265
- const emit = (after, before) => {
266
- if (vue && vue.vnode.el) {
267
- const event = new CustomEvent("data:emit", {
268
- bubbles: true,
269
- // Key: allows it to travel up
270
- composed: true,
271
- // Key: allows it to cross Shadow DOM boundaries
272
- detail: { before, after }
273
- // Payload goes here
274
- });
275
- access(component).model.setData(after);
276
- vue.vnode.el.dispatchEvent(event);
277
- }
278
- };
279
- const proxy = (data) => {
280
- return new Proxy(data, {
281
- get(target, key, receiver) {
282
- if (["setData", "replaceData"].includes(key.toString())) {
283
- return (...params) => {
284
- var _a3;
285
- const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
286
- if (typeof beforeSetData === "function") {
287
- const before = ObjectManager.on(target.getData());
288
- const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
289
- const diff2 = access(component).diff(before, after);
290
- if (beforeSetData(diff2, target)) {
291
- target[key](...params);
292
- }
293
- } else {
294
- target[key](...params);
295
- }
296
- return target;
297
- };
298
- } else {
299
- return Reflect.get(target, key, receiver);
300
- }
301
- }
302
- });
303
- };
304
- const normalize = (data) => {
305
- if (isRef(data) || isReactive(data)) {
306
- return data;
307
- } else if (isFunctionData || isAsyncData) {
308
- return ref(datatype);
309
- } else {
310
- const props2 = "data" in vue.vnode.props;
311
- try {
312
- if (["Array", "Object"].includes(data.constructor.name)) {
313
- return ref(data);
314
- } else {
315
- return ref(props2 ? { "": data } : datatype);
316
- }
317
- } catch (e) {
318
- return ref(props2 ? { "": data } : datatype);
319
- }
320
- }
321
- };
322
- const config = {
323
- data: normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data),
324
- defaultData: ObjectManager.on(defaultData).clone(),
325
- notifications: props.notifications,
326
- subscriptions: props.subscriptions,
327
- name: props.modelName,
328
- logging: props.logging
329
- };
330
- const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : DataManager.setConfig({ beforeGetData: (data) => isRef(data) ? unref(data) : data }, config);
331
- const component = ref({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
332
- if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
333
- const config2 = {
334
- callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
335
- options: {
336
- immediate: context.attrs["model:immediate"],
337
- deep: context.attrs["model:deep"],
338
- once: context.attrs["model:once"]
339
- }
340
- };
341
- const source = () => ObjectManager.on(model.getData()).clone();
342
- subscriptions.push(watch(source, (after, before) => {
343
- const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
344
- if (props.debug) {
345
- console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
346
- }
347
- if (diff2.changed) {
348
- config2.callback(diff2, { component });
349
- }
350
- }, config2.options));
351
- }
352
- const track = (source, options = {}) => {
353
- var _a3, _b2, _c2, _d, _e;
354
- subscriptions.push(watch(source, async (after, before) => {
355
- const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
356
- const callback = context.attrs["data:callback"];
357
- if (typeof callback === "function") {
358
- callback(diff2, { component });
359
- } else {
360
- model.replaceData(after);
361
- }
362
- }, {
363
- immediate: (_b2 = (_a3 = context.attrs["data:immediate"]) != null ? _a3 : options.immediate) != null ? _b2 : true,
364
- deep: (_d = (_c2 = context.attrs["data:deep"]) != null ? _c2 : options.deep) != null ? _d : true,
365
- once: (_e = context.attrs["data:once"]) != null ? _e : options.once
366
- }));
367
- };
368
- setTimeout(async () => {
369
- var _a3;
370
- if (props.model !== false) {
371
- if (isFunctionData || isAsyncData) {
372
- if (!("defaultData" in vue.vnode.props)) {
373
- console.warn(`${props.modelName}: defaultData is required for promise or function data.`, props.data);
374
- }
375
- const [data] = isAsyncData ? await Promise.all([
376
- isAsyncFunctionData ? props.data() : props.data,
377
- (_a3 = defer.value) != null ? _a3 : true
378
- ]) : [props.data];
379
- track(typeof data === "function" ? data : (() => data));
380
- } else {
381
- track(isRef(props.data) || isReactive(props.data) ? props.data : () => props.data, { immediate: false, deep: false });
382
- }
383
- }
384
- });
385
- setTimeout(async () => {
386
- var _a3;
387
- isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
388
- });
389
- component.value = [access(component)].reduce((options, parent) => {
390
- var _a3;
391
- while (parent) {
392
- if (typeof parent.setup === "function") {
393
- options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
394
- if (access(parent.$parent).ReactiveView) {
395
- break;
396
- } else {
397
- parent = access(parent.$parent);
398
- }
399
- } else {
400
- break;
401
- }
402
- }
403
- return options;
404
- }, component.value);
405
- props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
406
- return (vue2) => {
407
- var _a3, _b2;
408
- if (isReady.value) {
409
- return access(component).template(component, vue2);
410
- } else {
411
- return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
412
- }
413
- };
414
- };
415
- const current = () => {
416
- var _a2, _b2, _c2, _d;
417
- const emit = (after, before) => {
418
- if (vue && vue.vnode.el) {
419
- const event = new CustomEvent("data:emit", {
420
- bubbles: true,
421
- // Key: allows it to travel up
422
- composed: true,
423
- // Key: allows it to cross Shadow DOM boundaries
424
- detail: { before, after }
425
- // Payload goes here
426
- });
427
- vue.vnode.el.dispatchEvent(event);
428
- }
429
- };
430
- const normalize = (data) => {
431
- if (props.debug) {
432
- console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: isRef(data), isReactive: isReactive(data) });
433
- }
434
- if (isReactive(data)) {
435
- return data;
436
- } else {
437
- if (isRef(data) || isFunctionData || isAsyncData) {
438
- return reactive(datatype);
439
- } else {
440
- const props2 = "data" in vue.vnode.props;
441
- try {
442
- if (["Array", "Object"].includes(data.constructor.name)) {
443
- return reactive(props2 ? data : datatype);
444
- } else {
445
- return reactive(props2 ? { "": data } : datatype);
446
- }
447
- } catch (e) {
448
- return reactive(props2 ? { "": data } : datatype);
449
- }
450
- }
451
- }
452
- };
453
- const config = {
454
- data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : reactive(ObjectManager.on(
455
- isAsyncData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
456
- ).clone()),
457
- defaultData: ObjectManager.on(defaultData).clone(),
458
- notifications: props.notifications,
459
- subscriptions: props.subscriptions,
460
- name: props.modelName,
461
- logging: props.logging
462
- };
463
- const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config), {
464
- get(target, key, receiver) {
465
- if (["setData", "replaceData"].includes(key.toString())) {
466
- return (...params) => {
467
- var _a3;
468
- const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
469
- if (typeof beforeSetData === "function") {
470
- const before = ObjectManager.on(target.getData());
471
- const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
472
- if (beforeSetData(access(component).diff(before, after), target)) {
473
- target[key](...params);
474
- }
475
- } else {
476
- target[key](...params);
477
- }
478
- return target;
479
- };
480
- } else {
481
- return Reflect.get(target, key, receiver);
482
- }
483
- }
484
- });
485
- const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
486
- if (props.debug) {
487
- console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
488
- }
489
- const watchDataProp = (dataProp) => {
490
- var _a3, _b3, _c3, _d2;
491
- const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
492
- callback: (_b3 = ((_a3 = context.attrs["onUpdate:data"]) != null ? _a3 : {}).callback) != null ? _b3 : context.attrs["data:callback"],
493
- options: Object.assign(__spreadValues(__spreadValues({
494
- deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true
495
- }, 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)
496
- };
497
- if (context.attrs["data:log"]) {
498
- console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
499
- }
500
- subscriptions.push(watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
501
- var _a4;
502
- if (typeof config2.callback === "function") {
503
- model.replaceData((_a4 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a4 : after);
504
- } else {
505
- model.replaceData(after);
506
- }
507
- }, config2.options));
508
- };
509
- if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
510
- const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
511
- callback: context.attrs["onUpdate:model"],
512
- options: Object.assign(__spreadValues(__spreadValues({
513
- deep: (_b2 = context.attrs["model:deep"]) != null ? _b2 : true
514
- }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_c2 = context.attrs["onUpdate:model"]) != null ? _c2 : {}).options)
515
- } : (_d = context.attrs["onUpdate:model"]) != null ? _d : {};
516
- if (context.attrs["model:log"]) {
517
- console.warn(`[ReactiveView]:model`, { config: config2 });
518
- }
519
- subscriptions.push(watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
520
- config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
521
- }, config2.options));
522
- }
523
- if (props.beta) {
524
- const isRefData = isRef(props.data);
525
- if (isRefData || isFunctionData || isAsyncData) {
526
- setTimeout(async () => {
527
- var _a3, _b3, _c3;
528
- const [data] = isAsyncData ? await Promise.all([
529
- isAsyncFunctionData ? props.data() : props.data,
530
- (_a3 = defer.value) != null ? _a3 : true
531
- ]) : [props.data];
532
- subscriptions.push(watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
533
- var _a4;
534
- if (before !== void 0 || after !== void 0) {
535
- const callback = context.attrs["data:callback"];
536
- if (typeof callback === "function") {
537
- const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
538
- model.replaceData((_a4 = callback(diff2, { component })) != null ? _a4 : after);
539
- } else {
540
- model.replaceData(after);
541
- }
542
- }
543
- }, {
544
- immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
545
- deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
546
- once: context.attrs["data:once"]
547
- }));
548
- });
549
- }
550
- } else {
551
- setTimeout(async () => {
552
- var _a3;
553
- const [data] = await Promise.all([
554
- isAsyncFunctionData ? props.data() : props.data,
555
- (_a3 = defer.value) != null ? _a3 : true
556
- ]);
557
- watchDataProp(data);
558
- });
559
- }
560
- setTimeout(async () => {
561
- var _a3;
562
- isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
563
- });
564
- component.value = [access(component)].reduce((options, parent) => {
565
- var _a3;
566
- while (parent) {
567
- if (typeof parent.setup === "function") {
568
- options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
569
- if (access(parent.$parent).ReactiveView) {
570
- break;
571
- } else {
572
- parent = access(parent.$parent);
573
- }
574
- } else {
575
- break;
576
- }
577
- }
578
- return options;
579
- }, component.value);
580
- props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
581
- return (vue2) => {
582
- var _a3, _b3;
583
- if (isReady.value) {
584
- return access(component).template(component, vue2);
585
- } else {
586
- return (_b3 = (_a3 = context.slots).loading) == null ? void 0 : _b3.call(_a3, { component });
587
- }
588
- };
589
- };
590
- return props.beta === "next" ? beta() : current();
591
- }
592
- };
593
-
594
- // src/index.ts
595
- import { h, ref as ref2, unref as unref2, toRaw, isRef as isRef2, isReactive as isReactive2, createApp, createVNode as createVNode2, defineComponent } from "vue";
596
- import { formatInTimeZone } from "date-fns-tz";
597
- import { twMerge } from "tailwind-merge";
598
- console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
599
- var index_default = ReactiveView_default;
600
- function safeRequest(request) {
601
- return new Promise(async (resolve) => {
602
- var _a, _b, _c, _d;
603
- const { message } = (_a = request.loading) != null ? _a : {};
604
- if (request.loading) {
605
- request.loading.status = true;
606
- if (request.message) {
607
- request.loading.message = request.message;
608
- }
609
- }
610
- try {
611
- resolve(await request.try());
612
- } catch (e) {
613
- if ((_b = request.alternative) != null ? _b : true) {
614
- resolve(request.catch ? await request.catch(e) : console.log(e));
615
- }
616
- } finally {
617
- await ((_c = request.finally) == null ? void 0 : _c.call(request));
618
- if (request.loading) {
619
- request.loading.status = false;
620
- }
621
- if (request.loading && message) {
622
- request.loading.message = message;
623
- }
624
- await ((_d = request.complete) == null ? void 0 : _d.call(request));
625
- }
626
- });
627
- }
628
- function getProps(props = {}, param2) {
629
- var _a;
630
- const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
631
- const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
632
- const include = (_a = param2.include) != null ? _a : {};
633
- return Object.entries(include).reduce((props2, [key, val]) => {
634
- props2[key] = val;
635
- return props2;
636
- }, Object.entries(props).reduce((props2, [key, val]) => {
637
- if (!RegExp(`(^|\\|)${key}($|\\|)`, "i").test(exclusions)) {
638
- props2[key] = val;
639
- }
640
- return props2;
641
- }, {}));
434
+ //#endregion
435
+ //#region src/showComponent.ts
436
+ function A(e, t = {}) {
437
+ let n = (e) => {
438
+ let n = t.id ?? `dialog_${e.children.length + 1}`, r = document.createElement("div");
439
+ return r.setAttribute("id", n), e.appendChild(r), r;
440
+ }, r = (e) => {
441
+ let t = document.getElementById(e);
442
+ if (t) return n(t);
443
+ {
444
+ let t = document.createElement("div");
445
+ return t.setAttribute("id", e), document.body.appendChild(t), n(t);
446
+ }
447
+ }, a = t.container || "app-dialogs", o = r(a), s = i({ setup: () => () => e }, {
448
+ container: a,
449
+ unmount: () => {
450
+ _(null, o), o.remove();
451
+ }
452
+ }), c = t.app ?? document.querySelector("[data-v-app]");
453
+ try {
454
+ s.appContext = c.__vue_app__._context, _(s, o);
455
+ } catch {
456
+ console.warn("[ReactiveView]: showComponent called without an active app context.");
457
+ }
642
458
  }
643
- function getReactiveViewComponent(component, options = {}) {
644
- const model = (component2) => {
645
- try {
646
- return (component2.type || component2).props.hasOwnProperty("model");
647
- } catch (e) {
648
- return false;
649
- }
650
- };
651
- const props = getProps(options, "setup");
652
- const slots = typeof component === "function" ? component : () => {
653
- return (component.type || component).setup ? createVNode2(component, component.setup ? {} : props) : component;
654
- };
655
- return model(component) ? createVNode2(component, props) : createVNode2(ReactiveView_default, props, slots);
459
+ //#endregion
460
+ //#region src/components/CustomButton.vue
461
+ var j = K({
462
+ modelName: "CustomButton",
463
+ props: {
464
+ label: [Number, String],
465
+ tag: {
466
+ type: String,
467
+ default: "button"
468
+ },
469
+ loading: {
470
+ type: [Boolean, Function],
471
+ default: !1
472
+ },
473
+ padding: {
474
+ type: Boolean,
475
+ default: !0
476
+ },
477
+ buttonClass: {},
478
+ loadingClass: {}
479
+ },
480
+ setup(e, t, n) {
481
+ let r = typeof n.loading == "function" ? n.loading : () => n.loading, a = g(!1);
482
+ return S(() => {
483
+ a.value = r();
484
+ }), {
485
+ template: () => i(n.tag, { class: w(W({
486
+ "px-0 h-min": !n.padding,
487
+ "btn uppercase rounded-lg text-sm font-normal leading-none": !0
488
+ }).string, W(n.buttonClass).string) }, { default: () => [B(e).buttonLoading(), i("div", { class: {
489
+ hidden: a.value,
490
+ contents: !0
491
+ } }, [B(e).buttonIcon(), n.$slots.default ? n.$slots.default({ component: e }) : n.label])] }),
492
+ buttonIcon: () => {
493
+ if (n.$slots.icon) return n.$slots.icon({ component: e });
494
+ },
495
+ buttonLoading: () => {
496
+ if (a.value) return n.$slots.loading ? n.$slots.loading({ component: e }) : i("span", { class: W("loading", n.loadingClass) }, null);
497
+ }
498
+ };
499
+ }
500
+ }), M = K({
501
+ modelName: "CustomModal",
502
+ props: {
503
+ title: {
504
+ type: [
505
+ Boolean,
506
+ Number,
507
+ String
508
+ ],
509
+ default: "Modal Title"
510
+ },
511
+ persistent: {
512
+ type: Boolean,
513
+ default: !1
514
+ },
515
+ header: {
516
+ type: Boolean,
517
+ default: !0
518
+ },
519
+ actions: {
520
+ type: Boolean,
521
+ default: !0
522
+ },
523
+ ok: {
524
+ type: Boolean,
525
+ default: !0
526
+ },
527
+ cancel: {
528
+ type: Boolean,
529
+ default: !1
530
+ },
531
+ close: {
532
+ type: Boolean,
533
+ default: !0
534
+ },
535
+ show: {
536
+ type: Boolean,
537
+ default: !0
538
+ },
539
+ whenOk: {
540
+ type: Function,
541
+ default: () => {}
542
+ },
543
+ whenCancel: {
544
+ type: Function,
545
+ default: () => {}
546
+ },
547
+ whenClose: {
548
+ type: Function,
549
+ default: () => {}
550
+ },
551
+ whenEscape: {
552
+ type: Function,
553
+ default: () => {}
554
+ },
555
+ whenDismiss: {
556
+ type: Function,
557
+ default: () => {}
558
+ },
559
+ whenRouteChange: {
560
+ type: Function,
561
+ default: () => {}
562
+ },
563
+ class: {},
564
+ headerClass: {},
565
+ titleClass: {},
566
+ actionsClass: {},
567
+ backdropClass: {},
568
+ timeout: {
569
+ default: !1,
570
+ validator: (e) => typeof e == "number" || e === !1
571
+ },
572
+ modal: {
573
+ type: Boolean,
574
+ default: !1
575
+ },
576
+ id: [Number, String]
577
+ },
578
+ setup: (e, t, a) => {
579
+ m("dialog", e);
580
+ let o = g(), s = g(), c = document.getElementById(a.$attrs.container ?? "app-dialogs"), l = n(() => B(e).trigger ?? a.$slots.trigger), d = n(() => l.value ? !1 : a.show), f = n(() => !0), p = (e) => {
581
+ throw Error(e);
582
+ }, h = () => i("div", null, [i("dialog", u({
583
+ class: "modal",
584
+ ref: o
585
+ }, l.value || B(e).watch ? {} : c ? { id: c.lastChild?.id } : p("Modal should be called with showComponent.ts | trigger element | trigger slot")), [B(e).modalBox(), B(e).modalBackdrop()]), l.value?.({ component: e })]), _ = () => i("div", { class: w(W("modal-box flex flex-col p-0", a.class).string, W(a.class).string) }, [
586
+ B(e).modalHeader(),
587
+ B(e).modalContent(),
588
+ B(e).modalActions()
589
+ ]), y = () => a.$slots.default ? a.$slots.default({ component: e }) : i("div", { class: "px-4" }, [r("No Content")]), b = () => i("div", {
590
+ class: w("modal-backdrop", W({ "pointer-events-none": a.persistent }).string, W(a.backdropClass).string),
591
+ onClick: () => B(e).hide("backdrop")
592
+ }, null), S = () => {
593
+ if (a.actions) return i("div", {
594
+ style: "margin: 0;",
595
+ class: w("modal-action px-4 pb-4", W(a.actionsClass).string)
596
+ }, [B(e).okButton(), B(e).cancelButton()]);
597
+ }, C = () => {
598
+ if (a.header) return i("div", { class: w("flex items-center justify-between px-4 pt-4", W(a.headerClass).string) }, [B(e).title(), B(e).closeButton()]);
599
+ }, T = () => {
600
+ if (a.close) return i(v("i-mdi-close"), {
601
+ class: "cursor-pointer rounded-full text-xl transition duration-500 hover:scale-80 hover:ring",
602
+ onClick: async () => {
603
+ await a.whenClose(), B(e).hide("close");
604
+ }
605
+ }, null);
606
+ }, E = () => {
607
+ if (a.ok) return i(j, {
608
+ label: "ok",
609
+ class: "btn-sm btn-success text-white",
610
+ onClick: () => B(e).triggerOk(),
611
+ disabled: !B(e).isValid
612
+ }, null);
613
+ }, D = () => {
614
+ if (a.cancel) return i(j, {
615
+ label: "cancel",
616
+ class: "btn-sm btn-error text-white",
617
+ onClick: async () => {
618
+ await a.whenCancel(), B(e).hide("cancel");
619
+ }
620
+ }, null);
621
+ }, O = () => {
622
+ if (["String", "Number"].includes(a.title.constructor.name)) return i("h3", { class: w("w-full text-center font-bold", W(a.titleClass).string) }, [a.title]);
623
+ }, k = () => o.value[a.modal ? "showModal" : "show"](), A = (e) => o.value.close(e), M = () => o.value.open, N = (e) => {
624
+ a.$attrs.unmount?.(e), clearTimeout(s.value);
625
+ };
626
+ return setTimeout(() => {
627
+ let t = "open";
628
+ o.value && (new MutationObserver(async () => {
629
+ if (B(e).showing()) try {
630
+ await (await import("@razaman2/event-emitter")).default.global().emit(`dialog:${t}`, {
631
+ type: t,
632
+ component: e,
633
+ id: a.id
634
+ });
635
+ } finally {}
636
+ }).observe(o.value, {
637
+ attributes: !0,
638
+ attributeFilter: [t]
639
+ }), o.value.addEventListener("close", async (t) => {
640
+ let n = t.target.returnValue || "escape";
641
+ try {
642
+ await (await import("@razaman2/event-emitter")).default.global().emit("dialog:close", {
643
+ e: t,
644
+ type: n,
645
+ component: e,
646
+ id: a.id
647
+ });
648
+ } finally {
649
+ await a.whenDismiss({ type: n }), N({ type: n });
650
+ }
651
+ }), typeof a.timeout == "number" && (s.value = setTimeout(() => B(e).hide("timeout"), a.timeout)), B(e).watch ? x(B(e).watch, (t) => {
652
+ o.value && t ? B(e).show() : o.value && B(e).hide();
653
+ }, { deep: !0 }) : d.value && B(e).show()), document.addEventListener("keydown", async (e) => {
654
+ let t = e.key === "Escape";
655
+ a.persistent && t ? (e.stopPropagation(), e.preventDefault()) : t && await a.whenEscape();
656
+ });
657
+ }), {
658
+ template: h,
659
+ title: O,
660
+ modalBox: _,
661
+ modalHeader: C,
662
+ modalContent: y,
663
+ modalActions: S,
664
+ modalBackdrop: b,
665
+ closeButton: T,
666
+ okButton: E,
667
+ cancelButton: D,
668
+ show: k,
669
+ hide: A,
670
+ showing: M,
671
+ triggerOk: async () => {
672
+ await a.whenOk(B(e).model.getData()), B(e).hide("ok");
673
+ },
674
+ isValid: f,
675
+ modalRef: o
676
+ };
677
+ }
678
+ }), N = {
679
+ props: {
680
+ setup: O,
681
+ title: { type: String },
682
+ description: { type: String },
683
+ close: {
684
+ type: Boolean,
685
+ default: !0
686
+ },
687
+ timeout: {
688
+ default: 3e3,
689
+ validator: (e) => typeof e == "number" || e === !1
690
+ }
691
+ },
692
+ setup(e, t) {
693
+ return (e) => i(F, {
694
+ modelName: "CustomAlert",
695
+ setup: (n) => {
696
+ let r = {
697
+ default: i("path", {
698
+ "stroke-linecap": "round",
699
+ "stroke-linejoin": "round",
700
+ "stroke-width": "2",
701
+ d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
702
+ }, null),
703
+ "alert-info": i("path", {
704
+ "stroke-linecap": "round",
705
+ "stroke-linejoin": "round",
706
+ "stroke-width": "2",
707
+ d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
708
+ }, null),
709
+ "alert-success": i("path", {
710
+ "stroke-linecap": "round",
711
+ "stroke-linejoin": "round",
712
+ "stroke-width": "2",
713
+ d: "M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
714
+ }, null),
715
+ "alert-warning": i("path", {
716
+ "stroke-linecap": "round",
717
+ "stroke-linejoin": "round",
718
+ "stroke-width": "2",
719
+ d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
720
+ }, null),
721
+ "alert-error": i("path", {
722
+ "stroke-linecap": "round",
723
+ "stroke-linejoin": "round",
724
+ "stroke-width": "2",
725
+ d: "M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
726
+ }, null)
727
+ }, a = /alert-(info|success|warning|error)/.exec(e.$attrs.class)?.shift();
728
+ return e.timeout && p(() => {
729
+ setTimeout(() => B(n).hide("timeout"), e.timeout);
730
+ }), {
731
+ template: () => i("div", {
732
+ role: "alert",
733
+ class: "alert"
734
+ }, [
735
+ B(n).alertIcon(),
736
+ i("div", null, [B(n).alertTitle(), e.$slots.default ? e.$slots.default({ component: n }) : B(n).alertDescription()]),
737
+ B(n).alertClose()
738
+ ]),
739
+ alertIcon: () => i("svg", {
740
+ xmlns: "http://www.w3.org/2000/svg",
741
+ class: {
742
+ [a ? "stroke-current" : "stroke-black"]: !0,
743
+ "h-6 w-6 shrink-0": !0
744
+ },
745
+ fill: "none",
746
+ viewBox: "0 0 24 24"
747
+ }, [r[a] || r.default]),
748
+ alertTitle: () => i("h3", { class: "font-bold" }, [e.title]),
749
+ alertDescription: () => i("div", { class: "text-xs" }, [e.description]),
750
+ alertClose: () => {
751
+ if (e.close) return i(v("i-mdi-close"), {
752
+ id: "alert-close",
753
+ class: "text-xl cursor-pointer rounded-full hover:scale-80 hover:ring transition duration-500",
754
+ onClick: () => B(n).hide("close")
755
+ }, null);
756
+ },
757
+ hide: (n) => {
758
+ e.$el.remove(), t.emit("close", n);
759
+ }
760
+ };
761
+ }
762
+ }, e.$slots);
763
+ }
764
+ }, P = e.default || e;
765
+ console.log(`%c[ReactiveView]: ${D.version}`, "background-color: red; color: yellow;");
766
+ var F = k;
767
+ async function I(e) {
768
+ let { message: t } = e.loading ?? {};
769
+ e.loading && (e.loading.status = !0, e.message && (e.loading.message = e.message));
770
+ try {
771
+ return await e.try();
772
+ } catch (t) {
773
+ if (e.alternative ?? !0) return e.catch ? await e.catch(t) : console.log(t);
774
+ } finally {
775
+ await e.finally?.(), e.loading && (e.loading.status = !1), e.loading && t && (e.loading.message = t), await e.complete?.();
776
+ }
656
777
  }
657
- function getDate(param1, param2) {
658
- var _a, _b;
659
- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
660
- const format = "MM/dd/yyyy h:mm a";
661
- const options = typeof param2 === "string" ? { format: param2, timezone } : { format: (_a = param2 == null ? void 0 : param2.format) != null ? _a : format, timezone: (_b = param2 == null ? void 0 : param2.timezone) != null ? _b : timezone };
662
- const datetime = () => {
663
- try {
664
- return param1 instanceof Date ? param1 : param1.toDate();
665
- } catch (e) {
666
- return /* @__PURE__ */ new Date();
667
- }
668
- };
669
- return formatInTimeZone(datetime(), options.timezone, options.format);
778
+ function L(e = {}, t) {
779
+ let n = Array.isArray(t) || typeof t == "string" ? t : t.exclude, r = (Array.isArray(n) ? n : [n]).join("|"), i = t.include ?? {};
780
+ return Object.entries(i).reduce((e, [t, n]) => (e[t] = n, e), Object.entries(e).reduce((e, [t, n]) => (RegExp(`(^|\\|)${t}($|\\|)`, "i").test(r) || (e[t] = n), e), {}));
670
781
  }
671
- function access(view = {}, alternative) {
672
- var _a;
673
- const resolve = (target) => {
674
- return new Proxy(toRaw(target), {
675
- get(target2, key) {
676
- const component = { tree: target2 };
677
- do {
678
- if (key in component.tree) {
679
- return component.tree[key];
680
- } else if ("self" in component.tree && key in component.tree.self) {
681
- return component.tree.self[key];
682
- } else {
683
- component.tree = "parent" in component.tree && component.tree.parent;
684
- }
685
- } while (component.tree);
686
- try {
687
- return new alternative();
688
- } catch (e) {
689
- return alternative;
690
- }
691
- }
692
- });
693
- };
694
- try {
695
- const component = (_a = unref2(typeof view === "function" ? view() : view)) != null ? _a : {};
696
- return resolve("instance" in component ? component.instance : component);
697
- } catch (e) {
698
- return resolve(view);
699
- }
782
+ function R(e, t = {}) {
783
+ let n = (e) => {
784
+ try {
785
+ let t = (e.type || e).props;
786
+ return t && Object.prototype.hasOwnProperty.call(t, "model");
787
+ } catch {
788
+ return !1;
789
+ }
790
+ }, r = L(t, "setup"), a = typeof e == "function" ? e : () => (e.type || e).setup ? i(e, e.setup ? {} : r) : e;
791
+ return n(e) ? i(e, r) : i(k, r, a);
700
792
  }
701
- function useSubscription() {
702
- const subscriptions = [];
703
- const subscription = Subscriptions.get();
704
- return {
705
- addSubscription(name, handler = () => false, data) {
706
- subscription.subscribe(name, handler, data);
707
- subscriptions.push(() => subscription.unsubscribe(name));
708
- },
709
- replaceSubscription(name, handler = () => false, data) {
710
- subscription.replace(name, handler, data);
711
- subscriptions.push(() => subscription.unsubscribe(name));
712
- },
713
- removeSubscriptions() {
714
- subscriptions.forEach((subscription2) => safeRequest({
715
- try: () => subscription2()
716
- }));
717
- },
718
- removeSubscription(name) {
719
- subscription.unsubscribe(name);
720
- },
721
- hasSubscription(name) {
722
- return subscription.hasSubscription(name);
723
- },
724
- subscriptions,
725
- subscription
726
- };
793
+ function z(e, t) {
794
+ let n = Intl.DateTimeFormat().resolvedOptions().timeZone, r = typeof t == "string" ? {
795
+ format: t,
796
+ timezone: n
797
+ } : {
798
+ format: t?.format ?? "MM/dd/yyyy h:mm a",
799
+ timezone: t?.timezone ?? n
800
+ };
801
+ return C((() => {
802
+ try {
803
+ return e instanceof Date ? e : e.toDate();
804
+ } catch {
805
+ return /* @__PURE__ */ new Date();
806
+ }
807
+ })(), r.timezone, r.format);
727
808
  }
728
- var Prop = ({ default: value, type, validator, required } = {}) => {
729
- const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
730
- const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
731
- return __spreadProps(__spreadValues({}, value ? { default: isRef2(value) || isReactive2(value) ? value : ref2(value) } : {}), {
732
- required,
733
- validator: (value2) => {
734
- try {
735
- return validator ? validator(unref2(value2)) : Array.from(new Set(types2.map((type2) => {
736
- return typeof type2 === "function" ? type2().constructor.name : type2;
737
- }))).includes(unref2(value2).constructor.name);
738
- } catch (e) {
739
- return !required;
740
- }
741
- }
742
- });
743
- };
744
- function StyleParser(styles = {}) {
745
- const transform = (style, status = true) => {
746
- const remove = style.split(/(-{[^}]+})/);
747
- return remove.reduce((object, style2) => {
748
- var _a;
749
- const remove2 = /-{(.+?)}/.exec(style2);
750
- (remove2 ? (_a = remove2[1]) != null ? _a : style2 : style2).split(/\s+/).forEach((item) => {
751
- if (item) {
752
- Object.assign(object, { [item]: remove2 ? false : status });
753
- }
754
- });
755
- return object;
756
- }, {});
757
- };
758
- return Array.isArray(styles) ? styles.reduce((styles2, style) => Object.assign(transform(style), styles2), {}) : typeof styles === "string" ? transform(styles) : Object.entries(styles).reduce((acc, [styles2, value]) => {
759
- return __spreadValues(__spreadValues({}, acc), transform(styles2, value));
760
- }, {});
809
+ function B(e = {}, t) {
810
+ let n = (e) => new Proxy(y(e), { get(e, n) {
811
+ let r = { tree: e };
812
+ do
813
+ if (n in r.tree) return r.tree[n];
814
+ else if ("self" in r.tree && n in r.tree.self) return r.tree.self[n];
815
+ else r.tree = "parent" in r.tree && r.tree.parent;
816
+ while (r.tree);
817
+ try {
818
+ return new t();
819
+ } catch {
820
+ return t;
821
+ }
822
+ } });
823
+ try {
824
+ let t = b(typeof e == "function" ? e() : e) ?? {};
825
+ return n("instance" in t ? t.instance : t);
826
+ } catch {
827
+ return n(e);
828
+ }
761
829
  }
762
- function MergeStyles(...params) {
763
- return new Proxy(params.reduce((styles, style, index, items) => {
764
- var _a;
765
- const item = (_a = items[items.length - index - 1]) != null ? _a : {};
766
- return __spreadValues(__spreadValues({}, StyleParser(typeof item === "function" ? item(items.slice(0, index - 1)) : item)), styles);
767
- }, {}), {
768
- get: (target, key, receiver) => {
769
- const styles = Object.entries(target).reduce((styles2, [key2, val]) => {
770
- return val ? styles2.concat(key2) : styles2;
771
- }, []);
772
- if (key === "string") {
773
- return styles.join(" ");
774
- } else if (key === "array") {
775
- return styles;
776
- } else {
777
- return Reflect.get(target, key, receiver);
778
- }
779
- }
780
- });
830
+ function V() {
831
+ let e = [], t = E.get();
832
+ return {
833
+ addSubscription(n, r, i) {
834
+ t.subscribe(n, r, i), e.push(() => t.unsubscribe(n));
835
+ },
836
+ replaceSubscription(n, r, i) {
837
+ t.replace(n, r, i), e.push(() => t.unsubscribe(n));
838
+ },
839
+ removeSubscriptions() {
840
+ e.forEach((e) => I({ try: () => e() }));
841
+ },
842
+ removeSubscription(e) {
843
+ t.unsubscribe(e);
844
+ },
845
+ hasSubscription(e) {
846
+ return t.hasSubscription(e);
847
+ },
848
+ subscriptions: e,
849
+ subscription: t
850
+ };
781
851
  }
782
- var extendVnode = (component, element) => {
783
- return new Proxy(access(component), {
784
- get: (target, key) => {
785
- const getVnode = () => {
786
- try {
787
- return target[key]();
788
- } catch (e) {
789
- throw new Error(`${key} does not exist as vnode on component.`);
790
- }
791
- };
792
- const vnode = getVnode();
793
- return (props = {}, slots) => {
794
- var _a;
795
- const isFunctionClass = typeof props.class === "function";
796
- const isFunctionStyle = typeof props.style === "function";
797
- const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
798
- const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
799
- const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
800
- const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
801
- var _a2;
802
- if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
803
- props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
804
- }
805
- return props2;
806
- }, props);
807
- const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
808
- const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
809
- const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
810
- return h(finalElement, finalProps, finalSlots);
811
- };
812
- }
813
- });
852
+ var H = ({ default: e, type: t, validator: n, required: r } = {}) => {
853
+ let i = Array.isArray(t) ? t : [t ?? Array], a = i.includes(Object) ? i : i.concat(Object);
854
+ return {
855
+ ...e ? { default: l(e) || c(e) ? e : g(e) } : {},
856
+ required: r,
857
+ validator: (e) => {
858
+ try {
859
+ return n ? n(b(e)) : Array.from(new Set(a.map((e) => typeof e == "function" ? e().constructor.name : e))).includes(b(e).constructor.name);
860
+ } catch {
861
+ return !r;
862
+ }
863
+ }
864
+ };
814
865
  };
815
- function defineReactiveView(param1, param2) {
816
- const instance = ref2();
817
- return defineComponent({
818
- name: param1 == null ? void 0 : param1.modelName,
819
- props: __spreadValues({ setup }, param1 ? param1.props : {}),
820
- setup() {
821
- const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
822
- return (component) => {
823
- const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
824
- return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
825
- }, {});
826
- 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;
827
- return createVNode2(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
828
- setup: (self, parent) => setup2(self, parent, component)
829
- } : {})), {
830
- instance
831
- }), slots);
832
- };
833
- }
834
- });
866
+ function U(e = {}) {
867
+ let t = (e, t = !0) => e.split(/(-{[^}]+})/).reduce((e, n) => {
868
+ let r = /-{(.+?)}/.exec(n);
869
+ return (r ? r[1] ?? n : n).split(/\s+/).forEach((n) => {
870
+ n && Object.assign(e, { [n]: r ? !1 : t });
871
+ }), e;
872
+ }, {});
873
+ return Array.isArray(e) ? e.reduce((e, n) => Object.assign(t(n), e), {}) : typeof e == "string" ? t(e) : Object.entries(e).reduce((e, [n, r]) => ({
874
+ ...e,
875
+ ...t(n, r)
876
+ }), {});
835
877
  }
836
- function showComponent(component, options = {}) {
837
- var _a;
838
- if (options.router) {
839
- console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
840
- }
841
- if (!options.key || !document.getElementById(options.key)) {
842
- const container = options.container || "app-dialogs";
843
- const dialogs = document.getElementById(container) || document.createElement("div");
844
- if (!dialogs.hasAttribute("id")) {
845
- dialogs.setAttribute("id", container);
846
- document.body.appendChild(dialogs);
847
- }
848
- const dialog = document.createElement("div");
849
- const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
850
- dialog.setAttribute("id", id);
851
- dialogs.appendChild(dialog);
852
- const app = createApp(
853
- {
854
- setup() {
855
- return () => component;
856
- }
857
- },
858
- {
859
- __cleanup__: () => {
860
- document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
861
- app.unmount();
862
- }
863
- }
864
- );
865
- if (options.router) {
866
- return app.use(options.router).mount(`#${id}`);
867
- } else if (options.plugins) {
868
- return options.plugins.reduce((app2, plugin) => {
869
- return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
870
- }, app).mount(`#${id}`);
871
- } else {
872
- return app.mount(`#${id}`);
873
- }
874
- }
878
+ function W(...e) {
879
+ return new Proxy(e.reduce((e, t, n, r) => {
880
+ let i = r[r.length - n - 1] ?? {};
881
+ return {
882
+ ...U(typeof i == "function" ? i(r.slice(0, n - 1)) : i),
883
+ ...e
884
+ };
885
+ }, {}), { get: (e, t, n) => {
886
+ let r = Object.entries(e).reduce((e, [t, n]) => n ? e.concat(t) : e, []);
887
+ return t === "string" ? r.join(" ") : t === "array" ? r : Reflect.get(e, t, n);
888
+ } });
875
889
  }
876
- var getData = (component, path, alternative) => {
877
- const vue = access(component);
878
- const data = ObjectManager2.on(componentState(vue));
879
- if (path) {
880
- return data.get(dataPath(vue, path), alternative);
881
- } else {
882
- return data.get();
883
- }
884
- };
885
- var setData = (component, data, path) => {
886
- const vue = access(component);
887
- const diff = {
888
- before: ObjectManager2.on(componentState(vue)).clone(),
889
- after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
890
- };
891
- return "state" in vue ? diff : vue.$emit("update:state", diff);
892
- };
893
- var componentState = (component) => {
894
- return unref2("state" in component ? component.state : component.$attrs.state);
895
- };
896
- var dataPath = (component, path) => {
897
- return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
898
- };
899
- export {
900
- MergeStyles,
901
- Prop,
902
- StyleParser,
903
- access,
904
- dataPath,
905
- index_default as default,
906
- defineReactiveView,
907
- extendVnode,
908
- getData,
909
- getDate,
910
- getProps,
911
- getReactiveViewComponent,
912
- safeRequest,
913
- setData,
914
- setup,
915
- showComponent,
916
- useSubscription
917
- };
890
+ var G = (e, t) => new Proxy(B(e), { get: (e, n) => {
891
+ let r = (() => {
892
+ try {
893
+ return e[n]();
894
+ } catch {
895
+ throw Error(`${n} does not exist as vnode on component.`);
896
+ }
897
+ })();
898
+ return (e = {}, n) => {
899
+ let i = typeof e.class == "function", a = typeof e.style == "function", { class: o, style: c, ...l } = r.props ?? {}, u = w(i ? "" : o, W(i ? e.class(o) : e.class).string), d = W(c, a ? e.style(c) : e.style), f = Object.entries(e).reduce((e, [t, n]) => (![
900
+ "class",
901
+ "style",
902
+ "setup"
903
+ ].includes(t) && typeof n == "function" && (e[t] = n(r.props?.[t])), e), e), p = Object.assign(l, f, {
904
+ class: u,
905
+ style: d
906
+ }), m = n ? typeof n == "function" ? n(r.children) : n : r.children;
907
+ return s(["undefined"].includes(typeof t) ? r.type : t, p, m);
908
+ };
909
+ } });
910
+ function K(e, t) {
911
+ let n = g();
912
+ return a({
913
+ name: e?.modelName,
914
+ props: {
915
+ setup: O,
916
+ ...e ? e.props : {}
917
+ },
918
+ setup() {
919
+ let { setup: r, props: a, ...o } = e ?? {};
920
+ return (a) => {
921
+ let s = Object.entries(o).reduce((e, [t, r]) => Object.assign(e, { [t]: typeof r == "function" ? r(a, n) : r }), {}), c = typeof e?.slots == "function" ? e.slots(a) : Array.isArray(e?.slots) ? () => e.slots : e?.slots;
922
+ return i(t ?? k, {
923
+ ...s,
924
+ ...Object.assign({}, s, typeof r == "function" ? { setup: (e, t) => r(e, t, a) } : {}),
925
+ instance: n
926
+ }, c);
927
+ };
928
+ }
929
+ });
930
+ }
931
+ var q = (e, t, n) => {
932
+ let r = B(e), i = P.on(Y(r));
933
+ return t ? i.get(X(r, t), n) : i.get();
934
+ }, J = (e, t, n) => {
935
+ let r = B(e), i = {
936
+ before: P.on(Y(r)).clone(),
937
+ after: n ? P.on(Y(r)).set(X(r, n), t).get() : P.on(Y(r)).set(t).get()
938
+ };
939
+ return "state" in r ? i : r.$emit("update:state", i);
940
+ }, Y = (e) => b("state" in e ? e.state : e.$attrs.state), X = (e, t) => typeof e.$attrs["data:path"] == "function" ? e.$attrs["data:path"](t) : t;
941
+ //#endregion
942
+ export { N as CustomAlert, j as CustomButton, M as CustomModal, W as MergeStyles, H as Prop, U as StyleParser, B as access, X as dataPath, F as default, K as defineReactiveView, G as extendVnode, q as getData, z as getDate, L as getProps, R as getReactiveViewComponent, I as safeRequest, J as setData, O as setup, A as showComponent, V as useSubscription };