cdui-js 1.0.7 → 1.0.8
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/build/css.ts +32 -23
- package/package.json +1 -1
- package/src/components/Dialog.ts +36 -36
- package/src/components/For.ts +26 -26
- package/src/components/If.ts +14 -14
- package/src/components/KeepAlive.ts +26 -26
package/build/css.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
|
|
3
3
|
export interface Rule {
|
|
4
4
|
match: string;
|
|
5
|
-
build(outputs: string[], selector: string, value: string): void;
|
|
5
|
+
build(outputs: string[], selector: string, value: string, before: string[]): void;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export const rules: Rule[] = [
|
|
@@ -35,13 +35,13 @@ export const rules: Rule[] = [
|
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
match: '.border-c',
|
|
38
|
-
build: (outputs: string[], selector: string, value: string) => {
|
|
38
|
+
build: (outputs: string[], selector: string, value: string, before: string[]) => {
|
|
39
39
|
if (selector === '.border-c') {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
before.push(`.border { border-color: ${value} }`);
|
|
41
|
+
before.push(`.border-t { border-top-color: ${value} }`);
|
|
42
|
+
before.push(`.border-r { border-right-color: ${value} }`);
|
|
43
|
+
before.push(`.border-b { border-bottom-color: ${value} }`);
|
|
44
|
+
before.push(`.border-l { border-left-color: ${value} }\n`);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
outputs.push(`${selector} { border-color: ${value} }`);
|
|
@@ -143,9 +143,9 @@ export const rules: Rule[] = [
|
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
145
|
match: '.icon-c',
|
|
146
|
-
build: (outputs: string[], selector: string, value: string) => {
|
|
146
|
+
build: (outputs: string[], selector: string, value: string, before: string[]) => {
|
|
147
147
|
if (selector === '.icon-c') {
|
|
148
|
-
|
|
148
|
+
before.push(`body { stroke: ${value}; fill: ${value}; }\n.icon { stroke: inherit; fill: inherit; }`);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
outputs.push(`${selector} { stroke: ${value}; fill: ${value}; }`);
|
|
@@ -153,9 +153,9 @@ export const rules: Rule[] = [
|
|
|
153
153
|
},
|
|
154
154
|
{
|
|
155
155
|
match: '.icon-s',
|
|
156
|
-
build: (outputs: string[], selector: string, value: string) => {
|
|
156
|
+
build: (outputs: string[], selector: string, value: string, before: string[]) => {
|
|
157
157
|
if (selector === '.icon-s') {
|
|
158
|
-
|
|
158
|
+
before.push(`.icon { width: ${value}; height: ${value}; }\n`);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
outputs.push(`${selector} .icon { width: ${value}; height: ${value}; }`);
|
|
@@ -188,32 +188,39 @@ const findRule = (name: string) => {
|
|
|
188
188
|
}
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
-
const parse = (
|
|
191
|
+
const parse = (
|
|
192
|
+
rule: Rule,
|
|
193
|
+
outputs: string[],
|
|
194
|
+
selectorPrefix: string,
|
|
195
|
+
name: string,
|
|
196
|
+
value: string,
|
|
197
|
+
before: string[],
|
|
198
|
+
) => {
|
|
192
199
|
if (name.endsWith('-hover')) {
|
|
193
|
-
rule.build(outputs, selectorPrefix + name + ':hover', value);
|
|
194
|
-
rule.build(outputs, selectorPrefix + '.hover:hover ' + name, value);
|
|
200
|
+
rule.build(outputs, selectorPrefix + name + ':hover', value, before);
|
|
201
|
+
rule.build(outputs, selectorPrefix + '.hover:hover ' + name, value, before);
|
|
195
202
|
return;
|
|
196
203
|
}
|
|
197
204
|
|
|
198
205
|
if (name.endsWith('-active')) {
|
|
199
|
-
rule.build(outputs, selectorPrefix + name + ':active', value);
|
|
200
|
-
rule.build(outputs, selectorPrefix + '.active:active ' + name, value);
|
|
206
|
+
rule.build(outputs, selectorPrefix + name + ':active', value, before);
|
|
207
|
+
rule.build(outputs, selectorPrefix + '.active:active ' + name, value, before);
|
|
201
208
|
return;
|
|
202
209
|
}
|
|
203
210
|
|
|
204
211
|
if (name.endsWith('-focus')) {
|
|
205
|
-
rule.build(outputs, selectorPrefix + name + ':focus', value);
|
|
206
|
-
rule.build(outputs, selectorPrefix + '.focus:focus ' + name, value);
|
|
212
|
+
rule.build(outputs, selectorPrefix + name + ':focus', value, before);
|
|
213
|
+
rule.build(outputs, selectorPrefix + '.focus:focus ' + name, value, before);
|
|
207
214
|
return;
|
|
208
215
|
}
|
|
209
216
|
|
|
210
217
|
if (name.endsWith('-selected')) {
|
|
211
|
-
rule.build(outputs, selectorPrefix + name + '.selected', value);
|
|
212
|
-
rule.build(outputs, selectorPrefix + '.selected ' + name, value);
|
|
218
|
+
rule.build(outputs, selectorPrefix + name + '.selected', value, before);
|
|
219
|
+
rule.build(outputs, selectorPrefix + '.selected ' + name, value, before);
|
|
213
220
|
return;
|
|
214
221
|
}
|
|
215
222
|
|
|
216
|
-
rule.build(outputs, selectorPrefix + name, value);
|
|
223
|
+
rule.build(outputs, selectorPrefix + name, value, before);
|
|
217
224
|
};
|
|
218
225
|
|
|
219
226
|
/**
|
|
@@ -227,6 +234,7 @@ export const buildCSS = (cssRuleFile: string, cssFile?: string) => {
|
|
|
227
234
|
let lines = css.split(/\r?\n\s*/);
|
|
228
235
|
let selectorPrefix = '';
|
|
229
236
|
let outputs = [];
|
|
237
|
+
let before = [];
|
|
230
238
|
|
|
231
239
|
for (let i = 0, l = lines.length; i < l; i++) {
|
|
232
240
|
let line = lines[i].trim();
|
|
@@ -241,7 +249,7 @@ export const buildCSS = (cssRuleFile: string, cssFile?: string) => {
|
|
|
241
249
|
value = line.slice(index + 1);
|
|
242
250
|
|
|
243
251
|
if ((value = value.replace(/}\s*\;*\s*/, '').trim())) {
|
|
244
|
-
rule.build(outputs, selectorPrefix + name, value);
|
|
252
|
+
rule.build(outputs, selectorPrefix + name, value, before);
|
|
245
253
|
}
|
|
246
254
|
|
|
247
255
|
continue;
|
|
@@ -255,7 +263,7 @@ export const buildCSS = (cssRuleFile: string, cssFile?: string) => {
|
|
|
255
263
|
.trim();
|
|
256
264
|
|
|
257
265
|
if (value && value !== '#') {
|
|
258
|
-
parse(rule, outputs, selectorPrefix, name, value);
|
|
266
|
+
parse(rule, outputs, selectorPrefix, name, value, before);
|
|
259
267
|
}
|
|
260
268
|
|
|
261
269
|
continue;
|
|
@@ -283,6 +291,7 @@ export const buildCSS = (cssRuleFile: string, cssFile?: string) => {
|
|
|
283
291
|
}
|
|
284
292
|
}
|
|
285
293
|
|
|
294
|
+
outputs.unshift(...before);
|
|
286
295
|
css = outputs.join('\n');
|
|
287
296
|
|
|
288
297
|
if (cssFile) {
|
package/package.json
CHANGED
package/src/components/Dialog.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { createRoot } from 'solid-js';
|
|
2
|
-
|
|
3
|
-
import { JSX } from '../jsx';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 对话框
|
|
7
|
-
*/
|
|
8
|
-
export type Dialog = HTMLElement & {
|
|
9
|
-
/**
|
|
10
|
-
* 关闭对话框方法
|
|
11
|
-
*/
|
|
12
|
-
close(): void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 显示对话框
|
|
17
|
-
*
|
|
18
|
-
* @param component 对话框组件
|
|
19
|
-
* @returns 关闭对话框方法
|
|
20
|
-
*/
|
|
21
|
-
export const showDialog = (component: () => JSX.Element): Dialog => {
|
|
22
|
-
return createRoot((dispose) => {
|
|
23
|
-
let body = document.body;
|
|
24
|
-
let dialog = component() as Dialog;
|
|
25
|
-
|
|
26
|
-
dialog.style.cssText = 'position:fixed;z-index:9';
|
|
27
|
-
body.appendChild(dialog);
|
|
28
|
-
|
|
29
|
-
dialog.close = () => {
|
|
30
|
-
body.removeChild(dialog);
|
|
31
|
-
dispose();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return dialog;
|
|
35
|
-
});
|
|
36
|
-
};
|
|
1
|
+
import { createRoot } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
import { JSX } from '../jsx';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 对话框
|
|
7
|
+
*/
|
|
8
|
+
export type Dialog = HTMLElement & {
|
|
9
|
+
/**
|
|
10
|
+
* 关闭对话框方法
|
|
11
|
+
*/
|
|
12
|
+
close(): void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 显示对话框
|
|
17
|
+
*
|
|
18
|
+
* @param component 对话框组件
|
|
19
|
+
* @returns 关闭对话框方法
|
|
20
|
+
*/
|
|
21
|
+
export const showDialog = (component: () => JSX.Element): Dialog => {
|
|
22
|
+
return createRoot((dispose) => {
|
|
23
|
+
let body = document.body;
|
|
24
|
+
let dialog = component() as Dialog;
|
|
25
|
+
|
|
26
|
+
dialog.style.cssText = 'position:fixed;z-index:9';
|
|
27
|
+
body.appendChild(dialog);
|
|
28
|
+
|
|
29
|
+
dialog.close = () => {
|
|
30
|
+
body.removeChild(dialog);
|
|
31
|
+
dispose();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return dialog;
|
|
35
|
+
});
|
|
36
|
+
};
|
package/src/components/For.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { createMemo, mapArray } from 'solid-js';
|
|
2
|
-
|
|
3
|
-
import { JSX } from '../jsx';
|
|
4
|
-
|
|
5
|
-
export const For = <T, U extends JSX.Element>(props: {
|
|
6
|
-
/**
|
|
7
|
-
* 要循环的数据集合
|
|
8
|
-
*/
|
|
9
|
-
each: readonly T[];
|
|
10
|
-
/**
|
|
11
|
-
* 子节点
|
|
12
|
-
*
|
|
13
|
-
* @param item 数据项
|
|
14
|
-
* @param index 索引
|
|
15
|
-
* @returns JSX.Element
|
|
16
|
-
*/
|
|
17
|
-
children: (item: T, index: () => number) => U;
|
|
18
|
-
}) => {
|
|
19
|
-
return createMemo(
|
|
20
|
-
mapArray(() => props.each, props.children),
|
|
21
|
-
void 0,
|
|
22
|
-
{
|
|
23
|
-
name: 'value',
|
|
24
|
-
}
|
|
25
|
-
) as unknown as JSX.Element;
|
|
26
|
-
};
|
|
1
|
+
import { createMemo, mapArray } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
import { JSX } from '../jsx';
|
|
4
|
+
|
|
5
|
+
export const For = <T, U extends JSX.Element>(props: {
|
|
6
|
+
/**
|
|
7
|
+
* 要循环的数据集合
|
|
8
|
+
*/
|
|
9
|
+
each: readonly T[];
|
|
10
|
+
/**
|
|
11
|
+
* 子节点
|
|
12
|
+
*
|
|
13
|
+
* @param item 数据项
|
|
14
|
+
* @param index 索引
|
|
15
|
+
* @returns JSX.Element
|
|
16
|
+
*/
|
|
17
|
+
children: (item: T, index: () => number) => U;
|
|
18
|
+
}) => {
|
|
19
|
+
return createMemo(
|
|
20
|
+
mapArray(() => props.each, props.children),
|
|
21
|
+
void 0,
|
|
22
|
+
{
|
|
23
|
+
name: 'value',
|
|
24
|
+
}
|
|
25
|
+
) as unknown as JSX.Element;
|
|
26
|
+
};
|
package/src/components/If.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { createMemo } from 'solid-js';
|
|
2
|
-
|
|
3
|
-
import { JSX } from '../jsx';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 条件渲染
|
|
7
|
-
*
|
|
8
|
-
* @param props 属性集合
|
|
9
|
-
*/
|
|
10
|
-
export const If = (props: { when: any; children: JSX.Element | JSX.Element[]; else?: JSX.Element | JSX.Element[] }) => {
|
|
11
|
-
return createMemo(() => {
|
|
12
|
-
return props.when ? props.children : props.else;
|
|
13
|
-
}) as unknown as JSX.Element;
|
|
14
|
-
};
|
|
1
|
+
import { createMemo } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
import { JSX } from '../jsx';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 条件渲染
|
|
7
|
+
*
|
|
8
|
+
* @param props 属性集合
|
|
9
|
+
*/
|
|
10
|
+
export const If = (props: { when: any; children: JSX.Element | JSX.Element[]; else?: JSX.Element | JSX.Element[] }) => {
|
|
11
|
+
return createMemo(() => {
|
|
12
|
+
return props.when ? props.children : props.else;
|
|
13
|
+
}) as unknown as JSX.Element;
|
|
14
|
+
};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { JSX, createMemo, createRoot, onCleanup } from 'solid-js';
|
|
2
|
-
|
|
3
|
-
export const KeepAlive = (props: {
|
|
4
|
-
/**
|
|
5
|
-
* 是否显示
|
|
6
|
-
*/
|
|
7
|
-
show: boolean;
|
|
8
|
-
children: JSX.Element | JSX.Element[];
|
|
9
|
-
}) => {
|
|
10
|
-
let root, ondestory;
|
|
11
|
-
|
|
12
|
-
onCleanup(() => {
|
|
13
|
-
ondestory && ondestory();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
return createMemo(() => {
|
|
17
|
-
return (
|
|
18
|
-
props.show &&
|
|
19
|
-
(root ||
|
|
20
|
-
(root = createRoot((dispose) => {
|
|
21
|
-
ondestory = dispose;
|
|
22
|
-
return props.children;
|
|
23
|
-
})))
|
|
24
|
-
);
|
|
25
|
-
}) as unknown as JSX.Element;
|
|
26
|
-
};
|
|
1
|
+
import { JSX, createMemo, createRoot, onCleanup } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
export const KeepAlive = (props: {
|
|
4
|
+
/**
|
|
5
|
+
* 是否显示
|
|
6
|
+
*/
|
|
7
|
+
show: boolean;
|
|
8
|
+
children: JSX.Element | JSX.Element[];
|
|
9
|
+
}) => {
|
|
10
|
+
let root, ondestory;
|
|
11
|
+
|
|
12
|
+
onCleanup(() => {
|
|
13
|
+
ondestory && ondestory();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return createMemo(() => {
|
|
17
|
+
return (
|
|
18
|
+
props.show &&
|
|
19
|
+
(root ||
|
|
20
|
+
(root = createRoot((dispose) => {
|
|
21
|
+
ondestory = dispose;
|
|
22
|
+
return props.children;
|
|
23
|
+
})))
|
|
24
|
+
);
|
|
25
|
+
}) as unknown as JSX.Element;
|
|
26
|
+
};
|