aio-capacitor 2.0.2 → 2.2.0

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/index.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { type I_logItem } from 'aio-utils';
1
+ type I_logItem = {
2
+ tags?: string[];
3
+ id?: string;
4
+ message: string;
5
+ status?: 'error' | 'success' | 'warning' | 'info';
6
+ data?: any;
7
+ date?: number;
8
+ };
2
9
  export type NotificationItem = {
3
10
  id: number;
4
11
  title: string;
@@ -103,39 +110,4 @@ export declare class Tracker {
103
110
  stop(): Promise<void>;
104
111
  isTracking(): boolean;
105
112
  }
106
- export type I_FileRecordType = 'image' | 'file' | 'json' | 'text';
107
- export type I_FileRecord = {
108
- id: string;
109
- name: string;
110
- path: string;
111
- type: I_FileRecordType;
112
- createdAt: number;
113
- meta?: any;
114
- };
115
- export declare class FileRegistry {
116
- private store;
117
- private onChange;
118
- private storageKey;
119
- isNative: boolean;
120
- private webStorage;
121
- private initialRecords;
122
- constructor(p: {
123
- onChange: (v: I_FileRecord[]) => void;
124
- storageKey: string;
125
- mock?: I_FileRecord[];
126
- });
127
- private init;
128
- private initialLoad;
129
- private save;
130
- add(p: {
131
- type: I_FileRecordType;
132
- path: string;
133
- name?: string;
134
- meta?: any;
135
- }): I_FileRecord;
136
- rename(id: string, newName?: string): I_FileRecord;
137
- remove(id: string): void;
138
- list: () => I_FileRecord[];
139
- getById: (id: string) => I_FileRecord | null;
140
- }
141
113
  export {};
package/index.js CHANGED
@@ -7,19 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Capacitor } from '@capacitor/core';
11
- import { Preferences } from '@capacitor/preferences';
12
- import { Clipboard } from '@capacitor/clipboard';
13
- import { Camera } from '@capacitor/camera';
14
- import { Geolocation } from '@capacitor/geolocation';
15
- import { PushNotifications } from '@capacitor/push-notifications';
16
- import { TextToSpeech } from '@capacitor-community/text-to-speech';
17
- import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
18
- import { Haptics, ImpactStyle } from '@capacitor/haptics';
19
- import { Share } from '@capacitor/share';
20
- import { LocalNotifications } from '@capacitor/local-notifications';
21
- import { FileClass, Storage } from 'aio-utils';
22
- import { KeepAwake } from '@capacitor-community/keep-awake';
10
+ import { Capacitor, Preferences, Clipboard, Camera, Geolocation, PushNotifications, TextToSpeech, Filesystem, Directory, Encoding, Haptics, ImpactStyle, Share, LocalNotifications, KeepAwake } from 'aio-capacitor-deps';
11
+ import { FileClass } from 'aio-class';
23
12
  export class AIOCapacitor {
24
13
  constructor(p) {
25
14
  this.getPlatform = () => Capacitor.getPlatform();
@@ -434,98 +423,3 @@ export class Tracker {
434
423
  return !!this.watchId;
435
424
  }
436
425
  }
437
- export class FileRegistry {
438
- constructor(p) {
439
- this.store = new Map();
440
- this.storageKey = '';
441
- this.isNative = false;
442
- this.initialRecords = [];
443
- this.init = () => __awaiter(this, void 0, void 0, function* () {
444
- yield this.initialLoad();
445
- this.onChange(this.list());
446
- });
447
- this.initialLoad = () => __awaiter(this, void 0, void 0, function* () {
448
- let raw;
449
- if (!this.isNative) {
450
- raw = this.webStorage.load('records', this.initialRecords);
451
- }
452
- else {
453
- raw = yield new AIOCapacitor().storageLoad(this.storageKey, this.initialRecords);
454
- }
455
- raw = raw === null || !raw ? [] : raw;
456
- this.store = new Map(raw.map((i) => [i.id, i]));
457
- });
458
- this.save = () => __awaiter(this, void 0, void 0, function* () {
459
- const raw = this.list();
460
- if (!this.isNative) {
461
- this.webStorage.save('records', raw);
462
- }
463
- else {
464
- yield new AIOCapacitor().storageSave(this.storageKey, raw);
465
- }
466
- this.onChange(raw);
467
- });
468
- this.list = () => [...this.store.values()];
469
- this.getById = (id) => this.store.get(id) || null;
470
- if (p.mock) {
471
- this.initialRecords = p.mock;
472
- }
473
- const a = new AIOCapacitor();
474
- this.webStorage = new Storage(p.storageKey);
475
- this.isNative = a.isNative();
476
- this.storageKey = p.storageKey;
477
- this.onChange = p.onChange;
478
- this.init();
479
- }
480
- add(p) {
481
- const { type, path, meta } = p;
482
- if (['image', 'file', 'json', 'text'].indexOf(type) === -1) {
483
- alert('file type should be image or file or json or text');
484
- return;
485
- }
486
- if (!path) {
487
- alert('missing file path');
488
- return;
489
- }
490
- const id = crypto.randomUUID();
491
- const createdAt = Date.now();
492
- const name = p.name || window.prompt('inter file name');
493
- if (!name || name === null) {
494
- return;
495
- }
496
- const records = this.list();
497
- if (records.find((o) => o.name === name)) {
498
- const res = window.confirm('a file by this name is already exist, do you want to overwrite?');
499
- if (!res) {
500
- return;
501
- }
502
- }
503
- const record = { id, createdAt, name, type, path, meta };
504
- this.store.set(id, record);
505
- this.save();
506
- return record;
507
- }
508
- rename(id, newName) {
509
- const record = this.getById(id);
510
- if (!record) {
511
- return;
512
- }
513
- const name = newName || window.prompt('inter file new name');
514
- if (!name || name === null) {
515
- return;
516
- }
517
- const records = this.list();
518
- if (records.find((o) => o.name === name)) {
519
- alert('a file by this name is already exist, you cannot rename');
520
- return;
521
- }
522
- const newRecord = Object.assign(Object.assign({}, record), { name });
523
- this.store.set(id, newRecord);
524
- this.save();
525
- return newRecord;
526
- }
527
- remove(id) {
528
- this.store.delete(id);
529
- this.save();
530
- }
531
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-capacitor",
3
- "version": "2.0.2",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -8,20 +8,8 @@
8
8
  "test": "echo \"Error: no test specified\" && exit 1"
9
9
  },
10
10
  "dependencies": {
11
- "aio-utils": "latest",
12
- "aio-input": "latest",
13
- "@capacitor/core": "^8.4.0",
14
- "@capacitor/preferences": "^8.0.1",
15
- "@capacitor/clipboard": "^8.0.1",
16
- "@capacitor/camera": "^8.2.0",
17
- "@capacitor/geolocation": "^8.2.0",
18
- "@capacitor/push-notifications": "^8.1.1",
19
- "@capacitor-community/text-to-speech": "^8.0.0",
20
- "@capacitor/filesystem": "^8.1.2",
21
- "@capacitor/haptics": "^8.0.2",
22
- "@capacitor/share": "^8.0.1",
23
- "@capacitor/local-notifications": "^8.2.0",
24
- "@capacitor-community/keep-awake": "^8.0.1"
11
+ "aio-capacitor-deps": "latest",
12
+ "aio-class":"latest"
25
13
  },
26
14
  "repository": {
27
15
  "type": "git",
package/index.css DELETED
@@ -1,24 +0,0 @@
1
- .io-manager{
2
- display: flex;
3
- flex-direction: column;
4
- align-items: center;
5
- justify-content: center;
6
- gap: 1em;
7
- height:100%;
8
- }
9
- .io-manager-button{
10
- background:#e9d171;
11
- width:8em;
12
- height:8em;
13
- color:#111;
14
- font-weight:bold;
15
- border-radius:1em;
16
- display:flex;
17
- align-items: center;
18
- justify-content: center;
19
- }
20
- .io-manager-button .aio-input{
21
- background: none;
22
- border: none;
23
- padding: 0;
24
- }
package/react.d.ts DELETED
@@ -1,69 +0,0 @@
1
- import { type FC, type ReactNode } from "react";
2
- import { type I_FileRecord } from "./index";
3
- import './index.css';
4
- export declare const useCapacitorStorage: <T>(p: {
5
- key: string;
6
- def: T;
7
- debugId?: string;
8
- }) => {
9
- value: any;
10
- save: (value: T) => Promise<void>;
11
- getValue: () => any;
12
- change: (obj: Partial<T>) => Promise<void>;
13
- isLoaded: any;
14
- };
15
- export declare const useCapacitorStorageList: <T>(p: {
16
- key: string;
17
- def: T[];
18
- getId: (row: T) => any;
19
- }) => {
20
- value: any;
21
- add: (row: T) => Promise<void>;
22
- edit: (row: T) => Promise<void>;
23
- remove: (id: any) => Promise<void>;
24
- getById: (id: any) => any;
25
- change: (id: any, obj: Partial<T>) => Promise<void>;
26
- };
27
- export declare const useAwake: () => {
28
- awake: any;
29
- setAwake: (state?: boolean) => Promise<any>;
30
- };
31
- declare const useFileManager: (p: {
32
- mock?: boolean;
33
- fa?: boolean;
34
- storageKey: string;
35
- option?: {
36
- text?: (o: I_FileRecord) => ReactNode;
37
- subtext?: (o: I_FileRecord) => ReactNode;
38
- before?: (o: I_FileRecord) => ReactNode;
39
- onClick?: (o: I_FileRecord) => void;
40
- };
41
- }) => {
42
- mainProps: {
43
- mock?: boolean;
44
- fa?: boolean;
45
- storageKey: string;
46
- option?: {
47
- text?: (o: I_FileRecord) => ReactNode;
48
- subtext?: (o: I_FileRecord) => ReactNode;
49
- before?: (o: I_FileRecord) => ReactNode;
50
- onClick?: (o: I_FileRecord) => void;
51
- };
52
- };
53
- files: any;
54
- registery: any;
55
- click: (actionName: string, row: I_FileRecord) => void;
56
- getActions: (row: I_FileRecord) => {
57
- text: string;
58
- onClick: () => void;
59
- }[];
60
- };
61
- export declare const FileManager: FC<{
62
- hook: ReturnType<typeof useFileManager>;
63
- }>;
64
- export declare const IOManager: <T>({ data, onImport, onExport }: {
65
- data: T;
66
- onImport?: (v: T) => void;
67
- onExport?: () => void;
68
- }) => import("react/jsx-runtime").JSX.Element;
69
- export {};
package/react.js DELETED
@@ -1,171 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { useEffect, useRef, useState } from "react";
12
- import { AIOCapacitor, FileRegistry } from "./index";
13
- import { GetSvg, FileClass } from "aio-utils";
14
- import { Cards, AIFile } from "aio-input";
15
- import './index.css';
16
- export const useCapacitorStorage = (p) => {
17
- const { key, def } = p;
18
- const [data, setData] = useState({ isLoaded: false, value: def });
19
- const dataRef = useRef(data);
20
- dataRef.current = data;
21
- const ac = new AIOCapacitor();
22
- const isNative = ac.isNative();
23
- const load = () => __awaiter(void 0, void 0, void 0, function* () {
24
- if (!isNative) {
25
- const newData = Object.assign(Object.assign({}, dataRef.current), { isLoaded: true });
26
- setData(newData);
27
- }
28
- else {
29
- const res = yield ac.storageLoad(key, def);
30
- const newData = Object.assign(Object.assign({}, dataRef.current), { value: res, isLoaded: true });
31
- setData(newData);
32
- }
33
- });
34
- const save = (value) => __awaiter(void 0, void 0, void 0, function* () {
35
- if (isNative) {
36
- yield ac.storageSave(key, value);
37
- }
38
- const newData = Object.assign(Object.assign({}, dataRef.current), { value });
39
- setData(newData);
40
- });
41
- const change = (obj) => __awaiter(void 0, void 0, void 0, function* () {
42
- const oldData = dataRef.current;
43
- const { value } = oldData;
44
- save(Object.assign(Object.assign({}, value), obj));
45
- });
46
- const getValue = () => dataRef.current.value;
47
- useEffect(() => { load(); }, []);
48
- return { value: data.value, save, getValue, change, isLoaded: data.isLoaded };
49
- };
50
- export const useCapacitorStorageList = (p) => {
51
- const { key, def } = p;
52
- const [value, setValue] = useState(def);
53
- const ac = new AIOCapacitor();
54
- const isNative = ac.isNative();
55
- const getById = (id) => value.filter((o) => p.getId(o) === id)[0];
56
- const load = () => __awaiter(void 0, void 0, void 0, function* () {
57
- if (!ac.isNative()) {
58
- return;
59
- }
60
- const res = yield ac.storageLoad(key, def);
61
- setValue(res);
62
- });
63
- const save = (value) => __awaiter(void 0, void 0, void 0, function* () {
64
- if (isNative) {
65
- yield ac.storageSave(key, value);
66
- }
67
- setValue(value);
68
- });
69
- const add = (row) => __awaiter(void 0, void 0, void 0, function* () { return yield save([...value, Object.assign({}, row)]); });
70
- const edit = (row) => __awaiter(void 0, void 0, void 0, function* () {
71
- const newValue = value.map((o) => {
72
- if (p.getId(o) === p.getId(row)) {
73
- return row;
74
- }
75
- return o;
76
- });
77
- save(newValue);
78
- });
79
- const change = (id, obj) => __awaiter(void 0, void 0, void 0, function* () {
80
- const row = getById(id);
81
- if (!row) {
82
- return;
83
- }
84
- yield edit(Object.assign(Object.assign({}, row), obj));
85
- });
86
- const remove = (id) => __awaiter(void 0, void 0, void 0, function* () { return yield save(value.filter((o) => p.getId(o) !== id)); });
87
- useEffect(() => { load(); }, []);
88
- return { value, add, edit, remove, getById, change };
89
- };
90
- export const useAwake = () => {
91
- const ac = new AIOCapacitor();
92
- const [awake, setAwake] = useState(false);
93
- const getAwake = () => __awaiter(void 0, void 0, void 0, function* () {
94
- const awake = yield ac.isAwake();
95
- setAwake(awake.isKeptAwake);
96
- });
97
- useEffect(() => {
98
- getAwake();
99
- }, []);
100
- return { awake, setAwake: ac.awake };
101
- };
102
- const useFileManager = (p) => {
103
- const [files, setFiles] = useState([]);
104
- const registeryRef = useRef(undefined);
105
- useEffect(() => {
106
- const mock = [
107
- { name: 'file1', id: '64563454564', path: './ddsd/sddgf', "createdAt": Date.now(), type: 'text' },
108
- { name: 'file2', id: '7664564', path: './ddsd/sddgf', "createdAt": Date.now(), type: 'text' },
109
- { name: 'file3', id: '876456464', path: './ddsd/sddgf', "createdAt": Date.now(), type: 'text' },
110
- { name: 'file4', id: '544745345', path: './ddsd/sddgf', "createdAt": Date.now(), type: 'text' },
111
- { name: 'file5', id: '8965565', path: './ddsd/sddgf', "createdAt": Date.now(), type: 'text' },
112
- ];
113
- registeryRef.current = new FileRegistry({ storageKey: p.storageKey, onChange: (v) => setFiles(v), mock: p.mock ? mock : undefined });
114
- }, []);
115
- const click = (actionName, row) => {
116
- const registery = registeryRef.current;
117
- if (registery) {
118
- if (actionName === 'rename') {
119
- registery.rename(row.id);
120
- }
121
- else if (actionName === 'remove') {
122
- registery.remove(row.id);
123
- }
124
- }
125
- };
126
- const getActions = (row) => {
127
- return [
128
- { text: p.fa ? 'تغییر نام' : 'Rename', onClick: () => click('rename', row) },
129
- { text: p.fa ? 'حذف' : 'Remove', onClick: () => click('remove', row) },
130
- ];
131
- };
132
- return { mainProps: p, files, registery: registeryRef.current, click, getActions };
133
- };
134
- export const FileManager = ({ hook }) => {
135
- const { mainProps } = hook;
136
- const { option = {} } = mainProps;
137
- return (_jsx("div", { className: "fr-list", children: _jsx(Cards, { items: hook.files, option: {
138
- text: (row) => !option.text ? row.name : option.text(row),
139
- subtext: (row) => !option.subtext ? undefined : option.subtext(row),
140
- before: (row) => !(option === null || option === void 0 ? void 0 : option.before) ? new GetSvg().getIcon('mdiFile', 0.7) : option.before(row),
141
- actions: (o) => hook.getActions(o)
142
- } }) }));
143
- };
144
- export const IOManager = ({ data, onImport, onExport }) => {
145
- const importData = (file) => __awaiter(void 0, void 0, void 0, function* () {
146
- if (!onImport) {
147
- return;
148
- }
149
- const res = yield new FileClass().readText(file);
150
- if (res.success) {
151
- onImport(JSON.parse(res.result));
152
- }
153
- else {
154
- alert(res.message);
155
- }
156
- });
157
- const exportData = () => __awaiter(void 0, void 0, void 0, function* () {
158
- if (!onExport) {
159
- return;
160
- }
161
- const f = new FileClass();
162
- const res = yield f.saveFile(data, 'finance-data.json');
163
- if (res.success) {
164
- onExport();
165
- }
166
- else {
167
- alert(res.message);
168
- }
169
- });
170
- return (_jsxs("div", { className: "io-manager", children: [!!onImport && _jsx("div", { className: "io-manager-button", children: _jsx(AIFile, { text: 'Import', onChange: (file) => importData(file) }) }), !!onExport && _jsx("div", { className: "io-manager-button", onClick: () => exportData(), children: "Export" })] }));
171
- };