@medyll/idae-be 0.1.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/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # create-svelte
2
+
3
+ Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
4
+
5
+ Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
6
+
7
+ ## Creating a project
8
+
9
+ If you're seeing this, you've probably already done this step. Congrats!
10
+
11
+ ```bash
12
+ # create a new project in the current directory
13
+ npm create svelte@latest
14
+
15
+ # create a new project in my-app
16
+ npm create svelte@latest my-app
17
+ ```
18
+
19
+ ## Developing
20
+
21
+ Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22
+
23
+ ```bash
24
+ npm run dev
25
+
26
+ # or start the server and open the app in a new browser tab
27
+ npm run dev -- --open
28
+ ```
29
+
30
+ Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31
+
32
+ ## Building
33
+
34
+ To build your library:
35
+
36
+ ```bash
37
+ npm run package
38
+ ```
39
+
40
+ To create a production version of your showcase app:
41
+
42
+ ```bash
43
+ npm run build
44
+ ```
45
+
46
+ You can preview the production build with `npm run preview`.
47
+
48
+ > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
49
+
50
+ ## Publishing
51
+
52
+ Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53
+
54
+ To publish your library to [npm](https://www.npmjs.com):
55
+
56
+ ```bash
57
+ npm publish
58
+ ```
package/dist/be.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ type IsWhat = 'element' | 'array' | 'qy';
2
+ declare class DataHandler {
3
+ private element;
4
+ constructor(element: Be);
5
+ get(key: string): string | null;
6
+ set(keyOrObject: string | Record<string, string>, value?: string): Be;
7
+ get beElem(): Be;
8
+ valueOf(): DOMStringMap | null;
9
+ }
10
+ declare class PropHandler {
11
+ private element;
12
+ constructor(element: Be);
13
+ get(name: string): any;
14
+ set(nameOrObject: string | Record<string, any>, value?: any): Be;
15
+ valueOf(): Record<string, any> | null;
16
+ }
17
+ declare class DomHandler {
18
+ private element;
19
+ constructor(element: Be);
20
+ update(content: string): Be;
21
+ get text(): string | null;
22
+ textUpdate(content: string): Be;
23
+ valueOf(): string | null;
24
+ }
25
+ declare class AttrHandler {
26
+ private element;
27
+ constructor(element: Be);
28
+ get(name?: string): string | null;
29
+ set(nameOrObject: string | Record<string, string>, value?: string): Be;
30
+ valueOf(): Record<string, string> | null;
31
+ }
32
+ export declare class Be {
33
+ node: HTMLElement | HTMLElement[] | string;
34
+ isWhat: IsWhat;
35
+ attr: AttrHandler;
36
+ dom: DomHandler;
37
+ prop: PropHandler;
38
+ data: DataHandler;
39
+ private constructor();
40
+ static elem(node: HTMLElement | HTMLElement[] | string): Be;
41
+ classAdd(className: string): this;
42
+ classRemove(className: string): this;
43
+ classToggle(className: string): this;
44
+ find(qy: string): Element | (Element | null)[] | null;
45
+ findAll(qy: string): Element[];
46
+ get html(): string | null;
47
+ htmlSet(content: string): this;
48
+ get text(): string | null;
49
+ textSet(content: string): this;
50
+ up(qy?: string): Element | (Element | null)[] | null;
51
+ next(qy?: string): Element | (Element | null)[] | null;
52
+ previous(qy?: string): Element | (Element | null)[] | null;
53
+ styleSet(styles: Record<string, any>): this;
54
+ on(eventName: string, handler: EventListener): this;
55
+ off(eventName: string, handler: EventListener): this;
56
+ append(content: string | HTMLElement): this;
57
+ remove(): this;
58
+ fetch<T extends object>(options: {
59
+ url: string;
60
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
61
+ data?: T;
62
+ headers?: Record<string, string>;
63
+ }): Promise<any>;
64
+ each(callback: (el: HTMLElement) => void): void;
65
+ private findWhile;
66
+ }
67
+ export declare function be(selector: string | HTMLElement | HTMLElement[]): Be;
68
+ export {};
package/dist/be.js ADDED
@@ -0,0 +1,299 @@
1
+ class DataHandler {
2
+ element;
3
+ constructor(element) {
4
+ this.element = element;
5
+ }
6
+ get(key) {
7
+ if (this.element.isWhat !== 'element')
8
+ return null;
9
+ return this.element.node.dataset[key] || null;
10
+ }
11
+ set(keyOrObject, value) {
12
+ this.element.each((el) => {
13
+ if (typeof keyOrObject === 'string' && value !== undefined) {
14
+ el.dataset[keyOrObject] = value;
15
+ }
16
+ else if (typeof keyOrObject === 'object') {
17
+ Object.entries(keyOrObject).forEach(([key, val]) => {
18
+ el.dataset[key] = val;
19
+ });
20
+ }
21
+ });
22
+ return this.element;
23
+ }
24
+ get beElem() {
25
+ return this.element;
26
+ }
27
+ valueOf() {
28
+ if (this.element.isWhat !== 'element')
29
+ return null;
30
+ return this.element.node.dataset;
31
+ }
32
+ }
33
+ class PropHandler {
34
+ element;
35
+ constructor(element) {
36
+ this.element = element;
37
+ }
38
+ get(name) {
39
+ if (this.element.isWhat !== 'element')
40
+ return null;
41
+ return this.element.node[name];
42
+ }
43
+ set(nameOrObject, value) {
44
+ this.element.each((el) => {
45
+ if (typeof nameOrObject === 'string' && value !== undefined) {
46
+ el[nameOrObject] = value;
47
+ }
48
+ else if (typeof nameOrObject === 'object') {
49
+ Object.entries(nameOrObject).forEach(([name, val]) => {
50
+ el[name] = val;
51
+ });
52
+ }
53
+ });
54
+ return this.element;
55
+ }
56
+ valueOf() {
57
+ if (this.element.isWhat !== 'element')
58
+ return null;
59
+ const el = this.element.node;
60
+ const props = {};
61
+ for (let prop in el) {
62
+ if (el.hasOwnProperty(prop)) {
63
+ props[prop] = el[prop];
64
+ }
65
+ }
66
+ return props;
67
+ }
68
+ }
69
+ class DomHandler {
70
+ element;
71
+ constructor(element) {
72
+ this.element = element;
73
+ }
74
+ update(content) {
75
+ this.element.each((el) => {
76
+ el.innerHTML = content;
77
+ });
78
+ return this.element;
79
+ }
80
+ get text() {
81
+ if (this.element.isWhat !== 'element')
82
+ return null;
83
+ return this.element.node.textContent;
84
+ }
85
+ textUpdate(content) {
86
+ this.element.each((el) => {
87
+ el.textContent = content;
88
+ });
89
+ return this.element;
90
+ }
91
+ valueOf() {
92
+ if (this.element.isWhat !== 'element')
93
+ return null;
94
+ return this.element.node.innerHTML;
95
+ }
96
+ }
97
+ class AttrHandler {
98
+ element;
99
+ constructor(element) {
100
+ this.element = element;
101
+ }
102
+ get(name) {
103
+ if (this.element.isWhat !== 'element')
104
+ return null;
105
+ const el = this.element.node;
106
+ return name ? el.getAttribute(name) : null;
107
+ }
108
+ set(nameOrObject, value) {
109
+ this.element.each((el) => {
110
+ if (typeof nameOrObject === 'string' && value !== undefined) {
111
+ el.setAttribute(nameOrObject, value);
112
+ }
113
+ else if (typeof nameOrObject === 'object') {
114
+ Object.entries(nameOrObject).forEach(([name, val]) => {
115
+ el.setAttribute(name, val);
116
+ });
117
+ }
118
+ });
119
+ return this.element;
120
+ }
121
+ valueOf() {
122
+ if (this.element.isWhat !== 'element')
123
+ return null;
124
+ const el = this.element.node;
125
+ const attrs = {};
126
+ for (let i = 0; i < el.attributes.length; i++) {
127
+ const attr = el.attributes[i];
128
+ attrs[attr.name] = attr.value;
129
+ }
130
+ return attrs;
131
+ }
132
+ }
133
+ export class Be {
134
+ node;
135
+ isWhat;
136
+ attr;
137
+ dom;
138
+ prop;
139
+ data;
140
+ constructor(node) {
141
+ this.node = node;
142
+ this.isWhat = typeof node === 'string' ? 'qy' : Array.isArray(node) ? 'array' : 'element';
143
+ this.attr = new AttrHandler(this);
144
+ this.dom = new DomHandler(this);
145
+ this.prop = new PropHandler(this);
146
+ this.data = new DataHandler(this);
147
+ }
148
+ static elem(node) {
149
+ return new Be(node);
150
+ }
151
+ classAdd(className) {
152
+ this.each((el) => el.classList.add(className));
153
+ return this;
154
+ }
155
+ classRemove(className) {
156
+ this.each((el) => el.classList.remove(className));
157
+ return this;
158
+ }
159
+ classToggle(className) {
160
+ this.each((el) => el.classList.toggle(className));
161
+ return this;
162
+ }
163
+ find(qy) {
164
+ switch (this.isWhat) {
165
+ case 'element':
166
+ return this.node.querySelector(qy);
167
+ case 'array':
168
+ return this.node
169
+ .map((node) => node.querySelector(qy))
170
+ .filter((el) => el !== null);
171
+ case 'qy': {
172
+ const foundElement = document.querySelector(this.node);
173
+ return foundElement ? foundElement.querySelector(qy) : null;
174
+ }
175
+ default:
176
+ return null;
177
+ }
178
+ }
179
+ findAll(qy) {
180
+ switch (this.isWhat) {
181
+ case 'element':
182
+ return Array.from(this.node.querySelectorAll(qy));
183
+ case 'array':
184
+ return this.node.flatMap((node) => Array.from(node.querySelectorAll(qy)));
185
+ case 'qy':
186
+ return Array.from(document.querySelectorAll(this.node)).flatMap((node) => Array.from(node.querySelectorAll(qy)));
187
+ default:
188
+ return [];
189
+ }
190
+ }
191
+ get html() {
192
+ return this.isWhat === 'element' ? this.node.innerHTML : null;
193
+ }
194
+ htmlSet(content) {
195
+ this.each((el) => (el.innerHTML = content));
196
+ return this;
197
+ }
198
+ get text() {
199
+ return this.isWhat === 'element' ? this.node.textContent : null;
200
+ }
201
+ textSet(content) {
202
+ this.each((el) => (el.textContent = content));
203
+ return this;
204
+ }
205
+ up(qy) {
206
+ switch (this.isWhat) {
207
+ case 'element':
208
+ return this.findWhile(this.node, 'parent', qy);
209
+ case 'array':
210
+ return this.node.map((node) => this.findWhile(node, 'parent', qy));
211
+ case 'qy':
212
+ return Array.from(document.querySelectorAll(this.node)).map((node) => this.findWhile(node, 'parent', qy));
213
+ }
214
+ }
215
+ next(qy) {
216
+ switch (this.isWhat) {
217
+ case 'element':
218
+ return this.findWhile(this.node, 'next', qy);
219
+ case 'array':
220
+ return this.node.map((node) => this.findWhile(node, 'next', qy));
221
+ case 'qy':
222
+ return Array.from(document.querySelectorAll(this.node)).map((node) => this.findWhile(node, 'next', qy));
223
+ }
224
+ }
225
+ previous(qy) {
226
+ switch (this.isWhat) {
227
+ case 'element':
228
+ return this.findWhile(this.node, 'previous', qy);
229
+ case 'array':
230
+ return this.node.map((node) => this.findWhile(node, 'previous', qy));
231
+ case 'qy':
232
+ return Array.from(document.querySelectorAll(this.node)).map((node) => this.findWhile(node, 'previous', qy));
233
+ }
234
+ }
235
+ styleSet(styles) {
236
+ this.each((el) => Object.assign(el.style, styles));
237
+ return this;
238
+ }
239
+ on(eventName, handler) {
240
+ this.each((el) => el.addEventListener(eventName, handler));
241
+ return this;
242
+ }
243
+ off(eventName, handler) {
244
+ this.each((el) => el.removeEventListener(eventName, handler));
245
+ return this;
246
+ }
247
+ append(content) {
248
+ this.each((el) => {
249
+ if (typeof content === 'string') {
250
+ el.insertAdjacentHTML('beforeend', content);
251
+ }
252
+ else {
253
+ el.appendChild(content);
254
+ }
255
+ });
256
+ return this;
257
+ }
258
+ remove() {
259
+ this.each((el) => el.remove());
260
+ return this;
261
+ }
262
+ fetch(options) {
263
+ return fetch(options.url, {
264
+ method: options.method || 'GET',
265
+ body: options.data ? JSON.stringify(options.data) : undefined,
266
+ headers: options.headers || {}
267
+ }).then((response) => response.json());
268
+ }
269
+ each(callback) {
270
+ switch (this.isWhat) {
271
+ case 'element':
272
+ callback(this.node);
273
+ break;
274
+ case 'array':
275
+ this.node.forEach(callback);
276
+ break;
277
+ case 'qy':
278
+ document.querySelectorAll(this.node).forEach((el) => callback(el));
279
+ break;
280
+ }
281
+ }
282
+ findWhile(element, direction, selector) {
283
+ if (direction === 'parent') {
284
+ return selector ? element.closest(selector) : element.parentElement;
285
+ }
286
+ const siblingProperty = direction === 'next' ? 'nextElementSibling' : 'previousElementSibling';
287
+ let sibling = element[siblingProperty];
288
+ while (sibling) {
289
+ if (!selector || sibling.matches(selector)) {
290
+ return sibling;
291
+ }
292
+ sibling = sibling[siblingProperty];
293
+ }
294
+ return null;
295
+ }
296
+ }
297
+ export function be(selector) {
298
+ return Be.elem(selector);
299
+ }
@@ -0,0 +1 @@
1
+ export { be } from './be.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // Reexport your entry components here
2
+ export { be } from './be.js';
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@medyll/idae-be",
3
+ "scope": "@medyll",
4
+ "version": "0.1.0",
5
+ "private": false,
6
+ "scripts": {
7
+ "dev": "vite dev",
8
+ "build": "vite build && npm run package",
9
+ "preview": "vite preview",
10
+ "package": "svelte-kit sync && svelte-package && publint",
11
+ "prepublishOnly": "npm run package",
12
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
13
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
14
+ "test": "vitest",
15
+ "lint": "prettier --check . && eslint .",
16
+ "format": "prettier --write .",
17
+ "prepare": ""
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "svelte": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "!dist/**/*.test.*",
28
+ "!dist/**/*.spec.*"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "peerDependencies": {
34
+ "svelte": "^4.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@sveltejs/adapter-auto": "^3.0.0",
38
+ "@sveltejs/kit": "^2.0.0",
39
+ "@sveltejs/package": "^2.0.0",
40
+ "@sveltejs/vite-plugin-svelte": "^3.0.0",
41
+ "@types/eslint": "^8.56.7",
42
+ "eslint": "^9.0.0",
43
+ "eslint-config-prettier": "^9.1.0",
44
+ "eslint-plugin-svelte": "^2.36.0",
45
+ "globals": "^15.0.0",
46
+ "prettier": "^3.1.1",
47
+ "prettier-plugin-svelte": "^3.1.2",
48
+ "publint": "^0.1.9",
49
+ "svelte": "^4.2.7",
50
+ "svelte-check": "^3.6.0",
51
+ "tslib": "^2.4.1",
52
+ "typescript": "^5.0.0",
53
+ "typescript-eslint": "^8.0.0-alpha.20",
54
+ "vite": "^5.0.11",
55
+ "vitest": "^1.2.0"
56
+ },
57
+ "svelte": "./dist/index.js",
58
+ "types": "./dist/index.d.ts",
59
+ "type": "module"
60
+ }