yuyeon 0.0.42-rc2 → 0.0.42-rc24
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/style.css +1 -1
- package/dist/yuyeon.js +3762 -3475
- package/dist/yuyeon.umd.cjs +6 -6
- package/lib/components/date-picker/YDateCalendar.scss +82 -82
- package/lib/components/date-picker/YDatePickerControl.mjs.map +1 -1
- package/lib/components/dialog/YDialog.mjs +4 -1
- package/lib/components/dialog/YDialog.mjs.map +1 -1
- package/lib/components/dialog/YDialog.scss +2 -0
- package/lib/components/divider/YDivider.mjs.map +1 -1
- package/lib/components/dropdown/YDropdown.mjs +11 -5
- package/lib/components/dropdown/YDropdown.mjs.map +1 -1
- package/lib/components/dropdown/YDropdown.scss +3 -8
- package/lib/components/field-input/YFieldInput.mjs +22 -15
- package/lib/components/field-input/YFieldInput.mjs.map +1 -1
- package/lib/components/icon/YIcon.mjs +62 -0
- package/lib/components/icon/YIcon.mjs.map +1 -0
- package/lib/components/icon/YIcon.scss +18 -0
- package/lib/components/icon/index.mjs +2 -0
- package/lib/components/icon/index.mjs.map +1 -0
- package/lib/components/icon/poly.mjs +57 -0
- package/lib/components/icon/poly.mjs.map +1 -0
- package/lib/components/icons/index.mjs +14 -0
- package/lib/components/icons/index.mjs.map +1 -1
- package/lib/components/index.mjs +2 -1
- package/lib/components/index.mjs.map +1 -1
- package/lib/components/input/YInput.mjs +173 -308
- package/lib/components/input/YInput.mjs.map +1 -1
- package/lib/components/input/index.mjs.map +1 -1
- package/lib/components/layer/YLayer.mjs +3 -1
- package/lib/components/layer/YLayer.mjs.map +1 -1
- package/lib/components/layer/active-stack.mjs.map +1 -1
- package/lib/components/menu/YMenu.mjs +16 -4
- package/lib/components/menu/YMenu.mjs.map +1 -1
- package/lib/components/select/YSelect.mjs +27 -12
- package/lib/components/select/YSelect.mjs.map +1 -1
- package/lib/components/select/YSelect.scss +3 -8
- package/lib/components/tab/types.mjs.map +1 -1
- package/lib/components/textarea/YTextarea.mjs +159 -0
- package/lib/components/textarea/YTextarea.mjs.map +1 -0
- package/lib/components/textarea/YTextarea.scss +25 -0
- package/lib/components/textarea/index.mjs +2 -0
- package/lib/components/textarea/index.mjs.map +1 -0
- package/lib/components/tree-view/YTreeView.mjs.map +1 -1
- package/lib/components/tree-view/YTreeViewNode.mjs.map +1 -1
- package/lib/composables/communication.mjs.map +1 -1
- package/lib/composables/icon.mjs +161 -0
- package/lib/composables/icon.mjs.map +1 -1
- package/lib/composables/theme/index.mjs.map +1 -1
- package/lib/composables/validation.mjs +101 -0
- package/lib/composables/validation.mjs.map +1 -0
- package/lib/index.mjs +3 -0
- package/lib/index.mjs.map +1 -1
- package/lib/styles/util/_mixin.scss +34 -34
- package/lib/types/index.mjs.map +1 -1
- package/lib/util/date/adapters/yuyeon-date-adapter.mjs +1 -1
- package/lib/util/date/adapters/yuyeon-date-adapter.mjs.map +1 -1
- package/lib/util/date/built-in.mjs +6 -2
- package/lib/util/date/built-in.mjs.map +1 -1
- package/package.json +2 -2
- package/types/abstract/items.d.ts +4 -4
- package/types/components/button/YButton.d.ts +10 -10
- package/types/components/checkbox/YInputCheckbox.d.ts +2 -2
- package/types/components/date-picker/YDateCalendar.d.ts +10 -4
- package/types/components/dialog/YDialog.d.ts +4 -1
- package/types/components/dropdown/YDropdown.d.ts +34 -13
- package/types/components/field-input/YFieldInput.d.ts +121 -53
- package/types/components/form/YForm.d.ts +1 -1
- package/types/components/icon/YIcon.d.ts +81 -0
- package/types/components/icon/index.d.ts +1 -0
- package/types/components/icons/YIconCheckbox.d.ts +2 -2
- package/types/components/icons/YIconSort.d.ts +2 -2
- package/types/components/icons/index.d.ts +48 -0
- package/types/components/index.d.ts +2 -1
- package/types/components/input/YInput.d.ts +120 -91
- package/types/components/layer/YLayer.d.ts +20 -19
- package/types/components/layer/active-stack.d.ts +1 -2
- package/types/components/list/YListItem.d.ts +2 -2
- package/types/components/menu/YMenu.d.ts +8 -3
- package/types/components/pagination/YPagination.d.ts +8 -6
- package/types/components/progress-bar/YProgressBar.d.ts +1 -1
- package/types/components/select/YSelect.d.ts +1483 -272
- package/types/components/snackbar/YSnackbar.d.ts +3 -1
- package/types/components/switch/YSwitch.d.ts +1 -1
- package/types/components/tab/YTab.d.ts +15 -15
- package/types/components/tab/YTabs.d.ts +5 -5
- package/types/components/tab/types.d.ts +1 -0
- package/types/components/table/YDataTable.d.ts +18 -18
- package/types/components/table/YDataTableBody.d.ts +5 -5
- package/types/components/table/YDataTableControl.d.ts +2 -2
- package/types/components/table/YDataTableHead.d.ts +2 -2
- package/types/components/table/YDataTableServer.d.ts +21 -21
- package/types/components/table/YTable.d.ts +4 -4
- package/types/components/table/composibles/header.d.ts +1 -1
- package/types/components/table/composibles/items.d.ts +3 -3
- package/types/components/table/composibles/pagination.d.ts +8 -4
- package/types/components/table/composibles/selection.d.ts +2 -2
- package/types/components/table/composibles/sorting.d.ts +4 -2
- package/types/components/textarea/YTextarea.d.ts +664 -0
- package/types/components/textarea/index.d.ts +1 -0
- package/types/components/tooltip/YTooltip.d.ts +9 -8
- package/types/components/tree-view/YTreeView.d.ts +4 -4
- package/types/components/tree-view/YTreeViewNode.d.ts +9 -9
- package/types/composables/choice.d.ts +1 -1
- package/types/composables/communication.d.ts +7 -2
- package/types/composables/coordinate/index.d.ts +6 -6
- package/types/composables/focus.d.ts +3 -1
- package/types/composables/icon.d.ts +96 -0
- package/types/composables/list-items.d.ts +10 -10
- package/types/composables/theme/index.d.ts +2 -2
- package/types/composables/validation.d.ts +75 -0
- package/types/globals.d.ts +12 -7
- package/types/shims.d.ts +88 -85
- package/types/types/index.d.ts +5 -0
- package/types/util/date/built-in.d.ts +2 -2
package/lib/composables/icon.mjs
CHANGED
|
@@ -1,2 +1,163 @@
|
|
|
1
|
+
import { createVNode as _createVNode, Fragment as _Fragment } from "vue";
|
|
2
|
+
import { h } from 'vue';
|
|
3
|
+
import { computed, defineComponent, inject, mergeProps, unref } from 'vue';
|
|
4
|
+
import { builtSet } from "../components/index.mjs";
|
|
5
|
+
import { mergeDeep, propsFactory } from "../util/index.mjs";
|
|
1
6
|
export const IconPropOption = [String, Function, Object, Array];
|
|
7
|
+
export const IconValue = [String, Object, Array, Function];
|
|
8
|
+
export const pressIconPropsOptions = propsFactory({
|
|
9
|
+
icon: {
|
|
10
|
+
type: IconValue
|
|
11
|
+
},
|
|
12
|
+
tag: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true
|
|
15
|
+
}
|
|
16
|
+
}, 'icon');
|
|
17
|
+
export const YComponentIcon = defineComponent({
|
|
18
|
+
name: 'YComponentIcon',
|
|
19
|
+
props: pressIconPropsOptions(),
|
|
20
|
+
setup(props, _ref) {
|
|
21
|
+
let {
|
|
22
|
+
slots
|
|
23
|
+
} = _ref;
|
|
24
|
+
return () => {
|
|
25
|
+
const icon = props.icon;
|
|
26
|
+
let Icon = () => _createVNode(_Fragment, null, null);
|
|
27
|
+
let iconProps = {};
|
|
28
|
+
if (icon instanceof Object) {
|
|
29
|
+
Icon = icon;
|
|
30
|
+
if ('component' in icon) {
|
|
31
|
+
Icon = icon.component;
|
|
32
|
+
iconProps = icon?.props;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return _createVNode(props.tag, null, {
|
|
36
|
+
default: () => [props.icon ? _createVNode(Icon, mergeProps(iconProps), null) : slots.default?.()]
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
export const YSvgIcon = defineComponent({
|
|
42
|
+
name: 'YSvgIcon',
|
|
43
|
+
inheritAttrs: false,
|
|
44
|
+
props: pressIconPropsOptions(),
|
|
45
|
+
setup(props, _ref2) {
|
|
46
|
+
let {
|
|
47
|
+
attrs
|
|
48
|
+
} = _ref2;
|
|
49
|
+
return () => {
|
|
50
|
+
return _createVNode(props.tag, attrs, {
|
|
51
|
+
default: () => [_createVNode("svg", {
|
|
52
|
+
"class": "y-icon__svg",
|
|
53
|
+
"xmlns": "http://www.w3.org/2000/svg",
|
|
54
|
+
"viewBox": "0 0 24 24",
|
|
55
|
+
"role": "img",
|
|
56
|
+
"aria-hidden": "true"
|
|
57
|
+
}, [Array.isArray(props.icon) ? props.icon.map(path => Array.isArray(path) ? _createVNode("path", {
|
|
58
|
+
"d": path[0],
|
|
59
|
+
"fill-opacity": path[1]
|
|
60
|
+
}, null) : _createVNode("path", {
|
|
61
|
+
"d": path
|
|
62
|
+
}, null)) : _createVNode("path", {
|
|
63
|
+
"d": props.icon
|
|
64
|
+
}, null)])]
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
export const YUYEON_ICON_KEY = Symbol.for('yuyeon.icon');
|
|
70
|
+
export function createIconModule(options) {
|
|
71
|
+
return mergeDeep({
|
|
72
|
+
defaultSet: 'built',
|
|
73
|
+
sets: {
|
|
74
|
+
svg: {
|
|
75
|
+
component: YSvgIcon
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
aliases: {
|
|
79
|
+
...builtSet
|
|
80
|
+
}
|
|
81
|
+
}, options);
|
|
82
|
+
}
|
|
83
|
+
export function useIcon(iconProp) {
|
|
84
|
+
const iconModule = inject(YUYEON_ICON_KEY);
|
|
85
|
+
if (!iconModule) throw new Error('Not found provided "IconModule"');
|
|
86
|
+
const iconData = computed(() => {
|
|
87
|
+
const iconMeta = unref(iconProp);
|
|
88
|
+
if (!iconMeta) return {
|
|
89
|
+
component: YComponentIcon
|
|
90
|
+
};
|
|
91
|
+
let icon = iconMeta;
|
|
92
|
+
if (typeof icon === 'object' && 'alias' in icon && typeof icon.alias === 'string') {
|
|
93
|
+
icon = icon.alias;
|
|
94
|
+
}
|
|
95
|
+
if (typeof icon === 'string') {
|
|
96
|
+
icon = icon.trim();
|
|
97
|
+
if (icon.startsWith('$')) {
|
|
98
|
+
icon = iconModule.aliases?.[icon.slice(1)];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!icon) throw new Error(`Could not find aliased icon "${iconMeta}"`);
|
|
102
|
+
if (Array.isArray(icon)) {
|
|
103
|
+
return {
|
|
104
|
+
component: YSvgIcon,
|
|
105
|
+
icon
|
|
106
|
+
};
|
|
107
|
+
} else if (typeof icon !== 'string') {
|
|
108
|
+
const iconValue = unref(iconProp);
|
|
109
|
+
if (iconValue && typeof iconValue === 'object' && 'iconProps' in iconValue) {
|
|
110
|
+
icon = {
|
|
111
|
+
component: 'component' in icon ? icon.component : icon,
|
|
112
|
+
props: 'props' in icon ? mergeDeep(icon.props, iconValue?.iconProps ?? {}) : iconValue.iconProps
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
component: YComponentIcon,
|
|
117
|
+
icon
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const iconSetName = Object.keys(iconModule.sets).find(setName => typeof icon === 'string' && icon.startsWith(`${setName}:`));
|
|
121
|
+
const iconName = iconSetName ? icon.slice(iconSetName.length + 1) : icon;
|
|
122
|
+
const iconSet = iconModule.sets[iconSetName ?? iconModule.defaultSet];
|
|
123
|
+
if (!iconSet?.component && typeof icon === 'string') {
|
|
124
|
+
const text = new DOMParser().parseFromString(icon, 'text/xml');
|
|
125
|
+
const svgNode = text.querySelector('svg');
|
|
126
|
+
if (svgNode) {
|
|
127
|
+
return {
|
|
128
|
+
component: YComponentIcon,
|
|
129
|
+
icon: {
|
|
130
|
+
mounted() {
|
|
131
|
+
svgNode.childNodes.forEach(child => {
|
|
132
|
+
this.$el?.appendChild(child);
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
render: function () {
|
|
136
|
+
const attrs = {};
|
|
137
|
+
if (svgNode.hasAttributes()) {
|
|
138
|
+
for (let i = 0; i < svgNode.attributes.length; i += 1) {
|
|
139
|
+
const attr = svgNode.attributes.item(i);
|
|
140
|
+
if (attr) {
|
|
141
|
+
attrs[`^${attr.name}`] = attr.value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const node = h('svg', {
|
|
146
|
+
...attrs
|
|
147
|
+
}, []);
|
|
148
|
+
return node;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
icon: iconName,
|
|
156
|
+
component: iconSet.component
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
iconData
|
|
161
|
+
};
|
|
162
|
+
}
|
|
2
163
|
//# sourceMappingURL=icon.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.mjs","names":["IconPropOption","String","Function","Object","Array"],"sources":["../../src/composables/icon.ts"],"sourcesContent":["\r\nimport type { Component, PropType } from \"vue\";\r\n\r\nexport type IconValue = string | (string | [path: string, opacity: number])[] | Component;\r\n\r\nexport const IconPropOption = [String, Function, Object, Array] as PropType<IconValue>;\r\n\r\ntype IconProps = {\r\n tag: string;\r\n icon?: IconValue,\r\n disabled?: Boolean,\r\n}\r\n\r\ntype IconComponent = Component<IconProps>;\r\n"],"mappings":"AAKA,OAAO,MAAMA,cAAc,GAAG,CAACC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,KAAK,CAAwB"}
|
|
1
|
+
{"version":3,"file":"icon.mjs","names":["h","computed","defineComponent","inject","mergeProps","unref","builtSet","mergeDeep","propsFactory","IconPropOption","String","Function","Object","Array","IconValue","pressIconPropsOptions","icon","type","tag","required","YComponentIcon","name","props","setup","_ref","slots","Icon","_createVNode","_Fragment","iconProps","component","default","YSvgIcon","inheritAttrs","_ref2","attrs","isArray","map","path","YUYEON_ICON_KEY","Symbol","for","createIconModule","options","defaultSet","sets","svg","aliases","useIcon","iconProp","iconModule","Error","iconData","iconMeta","alias","trim","startsWith","slice","iconValue","iconSetName","keys","find","setName","iconName","length","iconSet","text","DOMParser","parseFromString","svgNode","querySelector","mounted","childNodes","forEach","child","$el","appendChild","render","hasAttributes","i","attributes","attr","item","value","node"],"sources":["../../src/composables/icon.tsx"],"sourcesContent":["import { HTMLAttributes } from '@vue/runtime-dom';\nimport { Component, InjectionKey, PropType, Ref, h } from 'vue';\nimport { computed, defineComponent, inject, mergeProps, unref } from 'vue';\n\nimport { builtSet } from '../components';\nimport { JSXComponent } from '../types';\nimport { mergeDeep, propsFactory } from '../util';\n\ntype IconComponent = JSXComponent<IconProps>;\n\nexport type IconValue =\n | string\n | (string | [path: string, opacity: number])[]\n | IconComponent\n | { component: JSXComponent; props?: any }\n | { alias: string; iconProps?: any };\n\nexport const IconPropOption = [\n String,\n Function,\n Object,\n Array,\n] as PropType<IconValue>;\n\ntype IconProps = {\n tag: string;\n icon?: IconValue;\n disabled?: Boolean;\n};\n\nexport interface IconSet {\n component: IconComponent;\n}\n\nexport const IconValue = [\n String,\n Object,\n Array,\n Function,\n] as PropType<IconValue>;\n\nexport type IconModuleOptions = {\n defaultSet?: string;\n sets?: Record<string, IconSet>;\n aliases?: Partial<Record<string, any>>;\n};\n\nexport const pressIconPropsOptions = propsFactory(\n {\n icon: {\n type: IconValue,\n },\n tag: {\n type: String,\n required: true,\n },\n },\n 'icon',\n);\n\nexport const YComponentIcon = defineComponent({\n name: 'YComponentIcon',\n props: pressIconPropsOptions(),\n setup(props, { slots }) {\n return () => {\n const icon = props.icon as unknown;\n let Icon: JSXComponent = () => <></>;\n let iconProps: any = {};\n if (icon instanceof Object) {\n Icon = icon as JSXComponent;\n if ('component' in icon) {\n Icon = icon.component as JSXComponent;\n iconProps = (icon as any)?.props;\n }\n }\n return (\n <props.tag>\n {props.icon ? <Icon {...mergeProps(iconProps)} /> : slots.default?.()}\n </props.tag>\n );\n };\n },\n});\nexport type YComponentIcon = InstanceType<typeof YComponentIcon>;\n\nexport const YSvgIcon = defineComponent({\n name: 'YSvgIcon',\n inheritAttrs: false,\n props: pressIconPropsOptions(),\n setup(props, { attrs }) {\n return () => {\n return (\n <props.tag {...attrs}>\n <svg\n class=\"y-icon__svg\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n role=\"img\"\n aria-hidden=\"true\"\n >\n {Array.isArray(props.icon) ? (\n props.icon.map((path) =>\n Array.isArray(path) ? (\n <path d={path[0] as string} fill-opacity={path[1]}></path>\n ) : (\n <path d={path as string}></path>\n ),\n )\n ) : (\n <path d={props.icon as string}></path>\n )}\n </svg>\n </props.tag>\n );\n };\n },\n});\nexport type YSvgIcon = InstanceType<typeof YSvgIcon>;\n\nexport const YUYEON_ICON_KEY: InjectionKey<Required<IconModuleOptions>> =\n Symbol.for('yuyeon.icon');\n\nexport function createIconModule(options?: IconModuleOptions) {\n return mergeDeep(\n {\n defaultSet: 'built',\n sets: {\n svg: {\n component: YSvgIcon,\n },\n },\n aliases: {\n ...builtSet,\n },\n },\n options,\n );\n}\n\ntype IconInstance = {\n component: IconComponent;\n icon?: IconValue;\n};\n\nexport function useIcon(iconProp: Ref<IconValue | undefined>) {\n const iconModule = inject(YUYEON_ICON_KEY);\n\n if (!iconModule) throw new Error('Not found provided \"IconModule\"');\n\n const iconData = computed<IconInstance>(() => {\n const iconMeta = unref(iconProp);\n\n if (!iconMeta) return { component: YComponentIcon };\n\n let icon: IconValue | undefined = iconMeta;\n\n if (\n typeof icon === 'object' &&\n 'alias' in icon &&\n typeof icon.alias === 'string'\n ) {\n icon = icon.alias;\n }\n\n if (typeof icon === 'string') {\n icon = icon.trim();\n\n if (icon.startsWith('$')) {\n icon = iconModule.aliases?.[icon.slice(1)];\n }\n }\n\n if (!icon) throw new Error(`Could not find aliased icon \"${iconMeta}\"`);\n\n if (Array.isArray(icon)) {\n return {\n component: YSvgIcon,\n icon,\n };\n } else if (typeof icon !== 'string') {\n const iconValue = unref(iconProp);\n if (\n iconValue &&\n typeof iconValue === 'object' &&\n 'iconProps' in iconValue\n ) {\n icon = {\n component:\n 'component' in icon ? icon.component : (icon as JSXComponent),\n props:\n 'props' in icon\n ? mergeDeep(icon.props, iconValue?.iconProps ?? {})\n : iconValue.iconProps,\n };\n }\n\n return {\n component: YComponentIcon,\n icon,\n };\n }\n\n const iconSetName = Object.keys(iconModule.sets).find(\n (setName) => typeof icon === 'string' && icon.startsWith(`${setName}:`),\n );\n\n const iconName = iconSetName ? icon.slice(iconSetName.length + 1) : icon;\n const iconSet = iconModule.sets[iconSetName ?? iconModule.defaultSet];\n\n if (!iconSet?.component && typeof icon === 'string') {\n const text = new DOMParser().parseFromString(icon, 'text/xml');\n const svgNode = text.querySelector('svg');\n if (svgNode) {\n return {\n component: YComponentIcon,\n icon: {\n mounted() {\n svgNode.childNodes.forEach((child) => {\n this.$el?.appendChild(child);\n });\n },\n render: function () {\n const attrs: any = {};\n if (svgNode.hasAttributes()) {\n for (let i = 0; i < svgNode.attributes.length; i += 1) {\n const attr = svgNode.attributes.item(i);\n if (attr) {\n attrs[`^${attr.name}`] = attr.value;\n }\n }\n }\n\n const node = h('svg', { ...attrs }, []);\n return node;\n },\n } as any,\n };\n }\n }\n\n return {\n icon: iconName,\n component: iconSet.component,\n };\n });\n\n return {\n iconData,\n };\n}\n"],"mappings":";AACA,SAAiDA,CAAC,QAAQ,KAAK;AAC/D,SAASC,QAAQ,EAAEC,eAAe,EAAEC,MAAM,EAAEC,UAAU,EAAEC,KAAK,QAAQ,KAAK;AAAC,SAElEC,QAAQ;AAAA,SAERC,SAAS,EAAEC,YAAY;AAWhC,OAAO,MAAMC,cAAc,GAAG,CAC5BC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,KAAK,CACiB;AAYxB,OAAO,MAAMC,SAAS,GAAG,CACvBJ,MAAM,EACNE,MAAM,EACNC,KAAK,EACLF,QAAQ,CACc;AAQxB,OAAO,MAAMI,qBAAqB,GAAGP,YAAY,CAC/C;EACEQ,IAAI,EAAE;IACJC,IAAI,EAAEH;EACR,CAAC;EACDI,GAAG,EAAE;IACHD,IAAI,EAAEP,MAAM;IACZS,QAAQ,EAAE;EACZ;AACF,CAAC,EACD,MACF,CAAC;AAED,OAAO,MAAMC,cA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ACb;UACF;QACF,CAAC;MACH;IACF;IAEA,OAAO;MACLpE,IAAI,EAAE+C,QAAQ;MACdjC,SAAS,EAAEmC,OAAO,CAACnC;IACrB,CAAC;EACH,CAAC,CAAC;EAEF,OAAO;IACLsB;EACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["computed","effectScope","getCurrentInstance","inject","provide","reactive","readonly","ref","unref","watch","bindThemeClass","propsFactory","createPalette","createThemes","cssClass","cssVariables","configureOptions","Y_THEME_PREFIX","YUYEON_THEME_KEY","Symbol","for","pressThemePropsOptions","theme","String","isDarkMode","window","matchMedia","matches","isSupportAutoScheme","media","createThemeModule","options","appMountedScope","config","scheme","themes","palette","supportedAutoMode","preferColorScheme","darkModeWatcher","mediaQueryList","value","currentColorScheme","currentThemeKey","computedThemes","Array","isArray","computedPalette","styles","lines","push","themeKey","themeDefs","Object","entries","colors","variables","isDark","records","themeScheme","join","install","app","directive","styleEl","document","getElementById","updateStyleEl","immediate","el","createElement","type","id","cspNonce","setAttribute","head","appendChild","innerHTML","bindTheme","yuyeon","mql","addEventListener","neo","lightTheme","darkTheme","root","dataset","init","run","themeClasses","scope","instance","global","useLocalTheme","props","themeModule","Error","newTheme","useTheme"],"sources":["../../../src/composables/theme/index.ts"],"sourcesContent":["import type {App, ComputedRef, PropType, Ref} from 'vue';\nimport {\n computed,\n effectScope,\n getCurrentInstance,\n inject,\n provide,\n reactive,\n readonly,\n ref,\n unref,\n watch,\n} from 'vue';\n\nimport bindThemeClass from '../../directives/theme-class';\nimport { propsFactory } from '../../util/vue-component';\nimport { createPalette, createThemes } from './factory';\nimport { cssClass, cssVariables } from './helper';\nimport { ThemeScheme, configureOptions } from './setting';\nimport type { ThemeOptions } from './types';\n\nexport type { ThemeOptions };\n\nexport const Y_THEME_PREFIX = 'y-theme';\n\nexport interface ThemeModuleInstance {\n scheme: keyof typeof ThemeScheme | 'auto';\n theme: Ref<[string, string?]>;\n // theme values(schemes) for colors & variables\n readonly themes: any;\n readonly global: {\n // currentThemeKeys: [lightThemeKey, darkThemeKey]\n // If used manually, fix the scheme to 'light' and have a [lightThemeKey] value.\n // Use the appropriate default theme scheme if it does not match the themeKey\n scheme: keyof typeof ThemeScheme | 'auto';\n theme: Ref<[string, string?]>;\n };\n /* computed */\n readonly currentThemeKey: Readonly<ComputedRef<string>>;\n readonly themeClasses: Readonly<ComputedRef<string | undefined>>;\n readonly computedThemes: Readonly<ComputedRef<any>>;\n readonly computedPalette: Readonly<ComputedRef<any>>;\n /* */\n readonly supportedAutoMode: Readonly<Ref<boolean>>;\n readonly preferColorScheme: Readonly<Ref<'light' | 'dark'>>;\n}\n\nexport const YUYEON_THEME_KEY = Symbol.for('yuyeon.theme');\n\nexport const pressThemePropsOptions = propsFactory(\n {\n theme: String as PropType<string>,\n },\n 'theme',\n);\n\nexport function isDarkMode() {\n return window.matchMedia('(prefers-color-scheme: dark)').matches;\n}\n\nexport function isSupportAutoScheme() {\n return window.matchMedia('(prefers-color-scheme)').media !== 'not all';\n}\n\nexport function createThemeModule(options: ThemeOptions) {\n const appMountedScope = effectScope();\n const config = reactive(configureOptions(options));\n const scheme = ref<string>(config.scheme);\n const theme = ref<[string, string]>(config.theme);\n const themes = ref(config.themes);\n const palette = ref(config.palette);\n const supportedAutoMode = ref(true);\n const preferColorScheme = ref('');\n\n function darkModeWatcher(\n mediaQueryList: MediaQueryListEvent | MediaQueryList,\n ) {\n preferColorScheme.value = mediaQueryList.matches ? 'dark' : 'light';\n }\n\n const currentColorScheme = computed<'light' | 'dark'>(() => {\n if (scheme.value === 'auto') {\n return preferColorScheme.value as 'light' | 'dark';\n }\n if (scheme.value === 'dark') {\n return 'dark';\n }\n return 'light';\n });\n\n const currentThemeKey = computed(() => {\n if (typeof theme.value === 'string') {\n if (theme.value in computedThemes) {\n return theme.value;\n }\n }\n if (Array.isArray(theme.value)) {\n return currentColorScheme.value === 'dark'\n ? theme.value?.[1] ?? 'dark'\n : theme.value?.[0] ?? 'light';\n }\n return currentColorScheme.value;\n });\n\n const computedPalette = computed(() => {\n return createPalette(palette.value);\n });\n\n const computedThemes = computed(() => {\n return createThemes(themes.value);\n });\n\n const styles = computed(() => {\n const lines = [];\n lines.push(\n ...cssClass(':root', cssVariables(computedPalette.value, 'palette')),\n );\n for (const [themeKey, themeDefs] of Object.entries(computedThemes.value)) {\n const { colors, variables, isDark } = themeDefs;\n const records: Record<string, string> = {\n ...colors,\n ...variables,\n };\n // if (currentThemeKey.value === themeKey) {\n // lines.push(...cssClass(':root', cssVariables(records, 'theme')));\n // }\n const themeScheme = isDark ? 'dark' : 'light';\n if (scheme.value === 'auto') {\n lines.push(\n ...cssClass(\n `@media (prefers-color-scheme: ${themeScheme})`,\n cssClass(\n `[data-theme-scheme='auto'][data-${themeScheme}-theme='${themeKey}']`,\n cssVariables(records, 'theme'),\n ),\n ),\n );\n } else {\n lines.push(\n ...cssClass(\n `[data-theme-scheme='${themeScheme}'][data-${themeScheme}-theme='${themeKey}']`,\n cssVariables(records, 'theme'),\n ),\n );\n }\n\n lines.push(\n ...cssClass(`.y-theme--${themeKey}`, cssVariables(records, 'theme')),\n );\n }\n return lines.join('');\n });\n\n function install(app: App) {\n app.directive('theme', bindThemeClass);\n\n let styleEl = document.getElementById('yuyeon-theme-palette');\n\n watch(styles, updateStyleEl, { immediate: true });\n\n function updateStyleEl() {\n if (typeof document !== 'undefined' && !styleEl) {\n const el = document.createElement('style');\n el.type = 'text/css';\n el.id = 'yuyeon-theme-palette';\n if (options?.cspNonce) el.setAttribute('nonce', options.cspNonce);\n styleEl = el;\n document.head.appendChild(styleEl);\n }\n if (styleEl) {\n styleEl.innerHTML = styles.value;\n }\n }\n }\n\n function bindTheme(yuyeon: any) {\n supportedAutoMode.value = isSupportAutoScheme();\n if (supportedAutoMode.value) {\n const mql = window.matchMedia('(prefers-color-scheme: dark)');\n darkModeWatcher(mql);\n mql.addEventListener('change' as 'change', darkModeWatcher);\n }\n watch(\n theme,\n (neo) => {\n const [lightTheme, darkTheme] = neo;\n yuyeon.root.dataset.lightTheme = lightTheme;\n yuyeon.root.dataset.darkTheme = darkTheme;\n },\n { immediate: true },\n );\n watch(\n scheme,\n (neo) => {\n yuyeon.root.setAttribute(\n 'data-theme-scheme',\n neo === 'auto' ? 'auto' : currentColorScheme.value,\n );\n },\n { immediate: true },\n );\n }\n\n function init(yuyeon: any) {\n appMountedScope.run(() => {\n bindTheme(yuyeon);\n });\n }\n\n const themeClasses = computed(() => `y-theme--${currentThemeKey.value}`);\n\n return {\n install,\n init,\n scope: appMountedScope,\n instance: {\n global: {\n scheme,\n theme,\n },\n themes,\n scheme,\n theme,\n currentThemeKey,\n themeClasses,\n computedThemes,\n computedPalette,\n supportedAutoMode: readonly(supportedAutoMode),\n preferColorScheme: readonly(preferColorScheme),\n },\n };\n}\n\nexport function useLocalTheme(props: { theme?: string }) {\n getCurrentInstance();\n\n const themeModule = inject<ThemeModuleInstance | null>(\n YUYEON_THEME_KEY,\n null,\n );\n\n if (!themeModule) throw new Error('Not found provided \"ThemeModule\"');\n\n const palette = themeModule.computedPalette;\n\n const currentThemeKey = computed<string>(() => {\n if (props.theme) {\n switch (props.theme) {\n case 'light':\n return themeModule.theme.value?.[0] ?? 'light';\n case 'dark':\n return themeModule.theme.value?.[1] ?? 'dark';\n // TODO: props.theme(themeKey) validation in themes\n default:\n return props.theme;\n }\n }\n return unref(themeModule.currentThemeKey);\n });\n\n const themeClasses = computed(() => `y-theme--${currentThemeKey.value}`);\n\n const newTheme: ThemeModuleInstance = {\n ...themeModule,\n currentThemeKey,\n themeClasses,\n };\n\n provide(YUYEON_THEME_KEY, newTheme);\n\n return newTheme;\n}\n\nexport function useTheme() {\n getCurrentInstance();\n\n const theme = inject<ThemeModuleInstance | null>(YUYEON_THEME_KEY, null);\n\n if (!theme) throw new Error('Not found provided \"ThemeModule\"');\n\n return theme;\n}\n"],"mappings":"AACA,SACEA,QAAQ,EACRC,WAAW,EACXC,kBAAkB,EAClB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GAAG,CAAC,CAAC,IAAI,MAAM;QAC/C;QACA;UACE,OAAOqD,KAAK,CAACxE,KAAK;MACtB;IACF;IACA,OAAOd,KAAK,CAACuF,WAAW,CAACpD,eAAe,CAAC;EAC3C,CAAC,CAAC;EAEF,MAAM8C,YAAY,GAAGzF,QAAQ,CAAC,MAAO,YAAW2C,eAAe,CAACF,KAAM,EAAC,CAAC;EAExE,MAAMwD,QAA6B,GAAG;IACpC,GAAGF,WAAW;IACdpD,eAAe;IACf8C;EACF,CAAC;EAEDrF,OAAO,CAACc,gBAAgB,EAAE+E,QAAQ,CAAC;EAEnC,OAAOA,QAAQ;AACjB;AAEA,OAAO,SAASC,QAAQA,CAAA,EAAG;EACzBhG,kBAAkB,CAAC,CAAC;EAEpB,MAAMoB,KAAK,GAAGnB,MAAM,CAA6Be,gBAAgB,EAAE,IAAI,CAAC;EAExE,IAAI,CAACI,KAAK,EAAE,MAAM,IAAI0E,KAAK,CAAC,kCAAkC,CAAC;EAE/D,OAAO1E,KAAK;AACd"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["computed","effectScope","getCurrentInstance","inject","provide","reactive","readonly","ref","unref","watch","bindThemeClass","propsFactory","createPalette","createThemes","cssClass","cssVariables","configureOptions","Y_THEME_PREFIX","YUYEON_THEME_KEY","Symbol","for","pressThemePropsOptions","theme","String","isDarkMode","window","matchMedia","matches","isSupportAutoScheme","media","createThemeModule","options","appMountedScope","config","scheme","themes","palette","supportedAutoMode","preferColorScheme","darkModeWatcher","mediaQueryList","value","currentColorScheme","currentThemeKey","computedThemes","Array","isArray","computedPalette","styles","lines","push","themeKey","themeDefs","Object","entries","colors","variables","isDark","records","themeScheme","join","install","app","directive","styleEl","document","getElementById","updateStyleEl","immediate","el","createElement","type","id","cspNonce","setAttribute","head","appendChild","innerHTML","bindTheme","yuyeon","mql","addEventListener","neo","lightTheme","darkTheme","root","dataset","init","run","themeClasses","scope","instance","global","useLocalTheme","props","themeModule","Error","newTheme","useTheme"],"sources":["../../../src/composables/theme/index.ts"],"sourcesContent":["import type {App, ComputedRef, PropType, Ref} from 'vue';\r\nimport {\r\n computed,\r\n effectScope,\r\n getCurrentInstance,\r\n inject,\r\n provide,\r\n reactive,\r\n readonly,\r\n ref,\r\n unref,\r\n watch,\r\n} from 'vue';\r\n\r\nimport bindThemeClass from '../../directives/theme-class';\r\nimport { propsFactory } from '../../util/vue-component';\r\nimport { createPalette, createThemes } from './factory';\r\nimport { cssClass, cssVariables } from './helper';\r\nimport { ThemeScheme, configureOptions } from './setting';\r\nimport type { ThemeOptions } from './types';\r\n\r\nexport type { ThemeOptions };\r\n\r\nexport const Y_THEME_PREFIX = 'y-theme';\r\n\r\nexport interface ThemeModuleInstance {\r\n scheme: Ref<keyof typeof ThemeScheme | 'auto'>;\r\n theme: Ref<[string, string?]>;\r\n // theme values(schemes) for colors & variables\r\n readonly themes: any;\r\n readonly global: {\r\n // currentThemeKeys: [lightThemeKey, darkThemeKey]\r\n // If used manually, fix the scheme to 'light' and have a [lightThemeKey] value.\r\n // Use the appropriate default theme scheme if it does not match the themeKey\r\n scheme: Ref<keyof typeof ThemeScheme | 'auto'>;\r\n theme: Ref<[string, string?]>;\r\n };\r\n /* computed */\r\n readonly currentThemeKey: Readonly<ComputedRef<string>>;\r\n readonly themeClasses: Readonly<ComputedRef<string | undefined>>;\r\n readonly computedThemes: Readonly<ComputedRef<any>>;\r\n readonly computedPalette: Readonly<ComputedRef<any>>;\r\n /* */\r\n readonly supportedAutoMode: Readonly<Ref<boolean>>;\r\n readonly preferColorScheme: Readonly<Ref<'light' | 'dark'>>;\r\n}\r\n\r\nexport const YUYEON_THEME_KEY = Symbol.for('yuyeon.theme');\r\n\r\nexport const pressThemePropsOptions = propsFactory(\r\n {\r\n theme: String as PropType<string>,\r\n },\r\n 'theme',\r\n);\r\n\r\nexport function isDarkMode() {\r\n return window.matchMedia('(prefers-color-scheme: dark)').matches;\r\n}\r\n\r\nexport function isSupportAutoScheme() {\r\n return window.matchMedia('(prefers-color-scheme)').media !== 'not all';\r\n}\r\n\r\nexport function createThemeModule(options: ThemeOptions) {\r\n const appMountedScope = effectScope();\r\n const config = reactive(configureOptions(options));\r\n const scheme = ref<string>(config.scheme);\r\n const theme = ref<[string, string]>(config.theme);\r\n const themes = ref(config.themes);\r\n const palette = ref(config.palette);\r\n const supportedAutoMode = ref(true);\r\n const preferColorScheme = ref('');\r\n\r\n function darkModeWatcher(\r\n mediaQueryList: MediaQueryListEvent | MediaQueryList,\r\n ) {\r\n preferColorScheme.value = mediaQueryList.matches ? 'dark' : 'light';\r\n }\r\n\r\n const currentColorScheme = computed<'light' | 'dark'>(() => {\r\n if (scheme.value === 'auto') {\r\n return preferColorScheme.value as 'light' | 'dark';\r\n }\r\n if (scheme.value === 'dark') {\r\n return 'dark';\r\n }\r\n return 'light';\r\n });\r\n\r\n const currentThemeKey = computed(() => {\r\n if (typeof theme.value === 'string') {\r\n if (theme.value in computedThemes) {\r\n return theme.value;\r\n }\r\n }\r\n if (Array.isArray(theme.value)) {\r\n return currentColorScheme.value === 'dark'\r\n ? theme.value?.[1] ?? 'dark'\r\n : theme.value?.[0] ?? 'light';\r\n }\r\n return currentColorScheme.value;\r\n });\r\n\r\n const computedPalette = computed(() => {\r\n return createPalette(palette.value);\r\n });\r\n\r\n const computedThemes = computed(() => {\r\n return createThemes(themes.value);\r\n });\r\n\r\n const styles = computed(() => {\r\n const lines = [];\r\n lines.push(\r\n ...cssClass(':root', cssVariables(computedPalette.value, 'palette')),\r\n );\r\n for (const [themeKey, themeDefs] of Object.entries(computedThemes.value)) {\r\n const { colors, variables, isDark } = themeDefs;\r\n const records: Record<string, string> = {\r\n ...colors,\r\n ...variables,\r\n };\r\n // if (currentThemeKey.value === themeKey) {\r\n // lines.push(...cssClass(':root', cssVariables(records, 'theme')));\r\n // }\r\n const themeScheme = isDark ? 'dark' : 'light';\r\n if (scheme.value === 'auto') {\r\n lines.push(\r\n ...cssClass(\r\n `@media (prefers-color-scheme: ${themeScheme})`,\r\n cssClass(\r\n `[data-theme-scheme='auto'][data-${themeScheme}-theme='${themeKey}']`,\r\n cssVariables(records, 'theme'),\r\n ),\r\n ),\r\n );\r\n } else {\r\n lines.push(\r\n ...cssClass(\r\n `[data-theme-scheme='${themeScheme}'][data-${themeScheme}-theme='${themeKey}']`,\r\n cssVariables(records, 'theme'),\r\n ),\r\n );\r\n }\r\n\r\n lines.push(\r\n ...cssClass(`.y-theme--${themeKey}`, cssVariables(records, 'theme')),\r\n );\r\n }\r\n return lines.join('');\r\n });\r\n\r\n function install(app: App) {\r\n app.directive('theme', bindThemeClass);\r\n\r\n let styleEl = document.getElementById('yuyeon-theme-palette');\r\n\r\n watch(styles, updateStyleEl, { immediate: true });\r\n\r\n function updateStyleEl() {\r\n if (typeof document !== 'undefined' && !styleEl) {\r\n const el = document.createElement('style');\r\n el.type = 'text/css';\r\n el.id = 'yuyeon-theme-palette';\r\n if (options?.cspNonce) el.setAttribute('nonce', options.cspNonce);\r\n styleEl = el;\r\n document.head.appendChild(styleEl);\r\n }\r\n if (styleEl) {\r\n styleEl.innerHTML = styles.value;\r\n }\r\n }\r\n }\r\n\r\n function bindTheme(yuyeon: any) {\r\n supportedAutoMode.value = isSupportAutoScheme();\r\n if (supportedAutoMode.value) {\r\n const mql = window.matchMedia('(prefers-color-scheme: dark)');\r\n darkModeWatcher(mql);\r\n mql.addEventListener('change' as 'change', darkModeWatcher);\r\n }\r\n watch(\r\n theme,\r\n (neo) => {\r\n const [lightTheme, darkTheme] = neo;\r\n yuyeon.root.dataset.lightTheme = lightTheme;\r\n yuyeon.root.dataset.darkTheme = darkTheme;\r\n },\r\n { immediate: true },\r\n );\r\n watch(\r\n scheme,\r\n (neo) => {\r\n yuyeon.root.setAttribute(\r\n 'data-theme-scheme',\r\n neo === 'auto' ? 'auto' : currentColorScheme.value,\r\n );\r\n },\r\n { immediate: true },\r\n );\r\n }\r\n\r\n function init(yuyeon: any) {\r\n appMountedScope.run(() => {\r\n bindTheme(yuyeon);\r\n });\r\n }\r\n\r\n const themeClasses = computed(() => `y-theme--${currentThemeKey.value}`);\r\n\r\n return {\r\n install,\r\n init,\r\n scope: appMountedScope,\r\n instance: {\r\n global: {\r\n scheme,\r\n theme,\r\n },\r\n themes,\r\n scheme,\r\n theme,\r\n currentThemeKey,\r\n themeClasses,\r\n computedThemes,\r\n computedPalette,\r\n supportedAutoMode: readonly(supportedAutoMode),\r\n preferColorScheme: readonly(preferColorScheme),\r\n },\r\n };\r\n}\r\n\r\nexport function useLocalTheme(props: { theme?: string }) {\r\n getCurrentInstance();\r\n\r\n const themeModule = inject<ThemeModuleInstance | null>(\r\n YUYEON_THEME_KEY,\r\n null,\r\n );\r\n\r\n if (!themeModule) throw new Error('Not found provided \"ThemeModule\"');\r\n\r\n const palette = themeModule.computedPalette;\r\n\r\n const currentThemeKey = computed<string>(() => {\r\n if (props.theme) {\r\n switch (props.theme) {\r\n case 'light':\r\n return themeModule.theme.value?.[0] ?? 'light';\r\n case 'dark':\r\n return themeModule.theme.value?.[1] ?? 'dark';\r\n // TODO: props.theme(themeKey) validation in themes\r\n default:\r\n return props.theme;\r\n }\r\n }\r\n return unref(themeModule.currentThemeKey);\r\n });\r\n\r\n const themeClasses = computed(() => `y-theme--${currentThemeKey.value}`);\r\n\r\n const newTheme: ThemeModuleInstance = {\r\n ...themeModule,\r\n currentThemeKey,\r\n themeClasses,\r\n };\r\n\r\n provide(YUYEON_THEME_KEY, newTheme);\r\n\r\n return newTheme;\r\n}\r\n\r\nexport function useTheme() {\r\n getCurrentInstance();\r\n\r\n const theme = inject<ThemeModuleInstance | null>(YUYEON_THEME_KEY, null);\r\n\r\n if (!theme) throw new Error('Not found provided \"ThemeModule\"');\r\n\r\n return theme;\r\n}\r\n"],"mappings":"AACA,SACEA,QAAQ,EACRC,WAAW,EACXC,kBAAkB,EAClBC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,KAAK,QACA,KAAK;AA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,KAAK,CAACuF,WAAW,CAACpD,eAAe,CAAC;EAC3C,CAAC,CAAC;EAEF,MAAM8C,YAAY,GAAGzF,QAAQ,CAAC,MAAO,YAAW2C,eAAe,CAACF,KAAM,EAAC,CAAC;EAExE,MAAMwD,QAA6B,GAAG;IACpC,GAAGF,WAAW;IACdpD,eAAe;IACf8C;EACF,CAAC;EAEDrF,OAAO,CAACc,gBAAgB,EAAE+E,QAAQ,CAAC;EAEnC,OAAOA,QAAQ;AACjB;AAEA,OAAO,SAASC,QAAQA,CAAA,EAAG;EACzBhG,kBAAkB,CAAC,CAAC;EAEpB,MAAMoB,KAAK,GAAGnB,MAAM,CAA6Be,gBAAgB,EAAE,IAAI,CAAC;EAExE,IAAI,CAACI,KAAK,EAAE,MAAM,IAAI0E,KAAK,CAAC,kCAAkC,CAAC;EAE/D,OAAO1E,KAAK;AACd"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { computed, ref, watch } from 'vue';
|
|
2
|
+
import { getUid, propsFactory } from "../util/index.mjs";
|
|
3
|
+
import { useModelDuplex } from "./communication.mjs";
|
|
4
|
+
import { useToggleScope } from "./scope.mjs";
|
|
5
|
+
export const pressValidationPropsOptions = propsFactory({
|
|
6
|
+
readonly: Boolean,
|
|
7
|
+
disabled: Boolean,
|
|
8
|
+
status: {
|
|
9
|
+
type: String,
|
|
10
|
+
validator(value) {
|
|
11
|
+
return ['success', 'warning', 'error'].includes(value);
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
helperText: String,
|
|
15
|
+
validators: Array,
|
|
16
|
+
validateOn: {
|
|
17
|
+
type: String
|
|
18
|
+
},
|
|
19
|
+
validationValue: null,
|
|
20
|
+
maxErrors: {
|
|
21
|
+
type: [Number, String],
|
|
22
|
+
default: 1
|
|
23
|
+
}
|
|
24
|
+
}, 'validation');
|
|
25
|
+
export function useValidation(props, name) {
|
|
26
|
+
let uid = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getUid();
|
|
27
|
+
const model = useModelDuplex(props, 'modelValue');
|
|
28
|
+
const validationModel = computed(() => props.validationValue === undefined ? model.value : props.validationValue);
|
|
29
|
+
const validating = ref(false);
|
|
30
|
+
const validateOn = computed(() => {
|
|
31
|
+
let value = props.validateOn || 'input';
|
|
32
|
+
if (value === 'lazy') value = 'input,lazy';
|
|
33
|
+
const onSet = new Set(value?.split(',') ?? []);
|
|
34
|
+
return {
|
|
35
|
+
blur: onSet.has('blur') || onSet.has('input'),
|
|
36
|
+
input: onSet.has('input'),
|
|
37
|
+
lazy: onSet.has('lazy'),
|
|
38
|
+
submit: onSet.has('submit')
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const errorResult = ref();
|
|
42
|
+
const errors = ref([]);
|
|
43
|
+
const isError = computed(() => {
|
|
44
|
+
return props.status === 'error' || errors.value.length > 0;
|
|
45
|
+
});
|
|
46
|
+
const isSuccess = computed(() => {
|
|
47
|
+
return !isError.value && props.status === 'success';
|
|
48
|
+
});
|
|
49
|
+
useToggleScope(() => validateOn.value.input, () => {
|
|
50
|
+
watch(validationModel, () => {
|
|
51
|
+
if (validationModel.value != null) {
|
|
52
|
+
invokeValidators();
|
|
53
|
+
} else if (props.focused) {
|
|
54
|
+
const unwatch = watch(() => props.focused, val => {
|
|
55
|
+
if (!val) invokeValidators();
|
|
56
|
+
unwatch();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
async function invokeValidators() {
|
|
62
|
+
const results = [];
|
|
63
|
+
validating.value = true;
|
|
64
|
+
if (Array.isArray(props.validators)) {
|
|
65
|
+
for (const validator of props.validators) {
|
|
66
|
+
if (results.length >= +(props.maxErrors ?? 1)) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
const handler = typeof validator === 'function' ? validator : () => validator;
|
|
70
|
+
const result = await handler(validationModel.value);
|
|
71
|
+
if (result === true) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (result !== false && typeof result !== 'string') {
|
|
75
|
+
console.warn('Wrong validator return type');
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
results.push(result || '');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
validating.value = false;
|
|
82
|
+
errors.value = results;
|
|
83
|
+
errorResult.value = results?.[0];
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
function resetError() {
|
|
87
|
+
errors.value = [];
|
|
88
|
+
errorResult.value = undefined;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
invokeValidators,
|
|
92
|
+
resetError,
|
|
93
|
+
validating,
|
|
94
|
+
validateOn,
|
|
95
|
+
errorResult,
|
|
96
|
+
errors,
|
|
97
|
+
isError,
|
|
98
|
+
isSuccess
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=validation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.mjs","names":["computed","ref","watch","getUid","propsFactory","useModelDuplex","useToggleScope","pressValidationPropsOptions","readonly","Boolean","disabled","status","type","String","validator","value","includes","helperText","validators","Array","validateOn","validationValue","maxErrors","Number","default","useValidation","props","name","uid","arguments","length","undefined","model","validationModel","validating","onSet","Set","split","blur","has","input","lazy","submit","errorResult","errors","isError","isSuccess","invokeValidators","focused","unwatch","val","results","isArray","handler","result","console","warn","push","resetError"],"sources":["../../src/composables/validation.ts"],"sourcesContent":["import { PropType, computed, ref, watch } from 'vue';\n\nimport { getUid, propsFactory } from '../util';\nimport { useModelDuplex } from './communication';\nimport { useToggleScope } from './scope';\n\nexport const pressValidationPropsOptions = propsFactory(\n {\n readonly: Boolean as PropType<boolean>,\n disabled: Boolean as PropType<boolean>,\n status: {\n type: String as PropType<'success' | 'warning' | 'error' | undefined>,\n validator(value: string) {\n return ['success', 'warning', 'error'].includes(value);\n },\n },\n helperText: String,\n validators: Array as PropType<((v: any) => boolean | string)[] | string[]>,\n validateOn: {\n type: String as PropType<string>,\n },\n validationValue: null,\n maxErrors: {\n type: [Number, String] as PropType<number | string>,\n default: 1,\n },\n },\n 'validation',\n);\n\nexport function useValidation(props: any, name: string, uid = getUid()) {\n const model = useModelDuplex(props, 'modelValue');\n const validationModel = computed(() =>\n props.validationValue === undefined ? model.value : props.validationValue,\n );\n\n const validating = ref(false);\n const validateOn = computed(() => {\n let value = props.validateOn || 'input';\n if (value === 'lazy') value = 'input,lazy';\n const onSet = new Set(value?.split(',') ?? []);\n\n return {\n blur: onSet.has('blur') || onSet.has('input'),\n input: onSet.has('input'),\n lazy: onSet.has('lazy'),\n submit: onSet.has('submit'),\n };\n });\n\n const errorResult = ref();\n const errors = ref<any[]>([]);\n\n const isError = computed(() => {\n return props.status === 'error' || errors.value.length > 0;\n });\n\n const isSuccess = computed(() => {\n return !isError.value && props.status === 'success';\n });\n\n useToggleScope(\n () => validateOn.value.input,\n () => {\n watch(validationModel, () => {\n if (validationModel.value != null) {\n invokeValidators();\n } else if (props.focused) {\n const unwatch = watch(\n () => props.focused,\n (val) => {\n if (!val) invokeValidators();\n\n unwatch();\n },\n );\n }\n });\n },\n );\n\n async function invokeValidators() {\n const results: any[] = [];\n validating.value = true;\n\n if (Array.isArray(props.validators)) {\n for (const validator of props.validators) {\n if (results.length >= +(props.maxErrors ?? 1)) {\n break;\n }\n\n const handler =\n typeof validator === 'function' ? validator : () => validator;\n const result = await handler(validationModel.value);\n\n if (result === true) {\n continue;\n }\n\n if (result !== false && typeof result !== 'string') {\n console.warn('Wrong validator return type');\n continue;\n }\n results.push(result || '');\n }\n }\n validating.value = false;\n errors.value = results;\n errorResult.value = results?.[0];\n\n return results;\n }\n\n function resetError() {\n errors.value = [];\n errorResult.value = undefined;\n }\n\n return {\n invokeValidators,\n resetError,\n validating,\n validateOn,\n errorResult,\n errors,\n isError,\n isSuccess,\n };\n}\n"],"mappings":"AAAA,SAAmBA,QAAQ,EAAEC,GAAG,EAAEC,KAAK,QAAQ,KAAK;AAAC,SAE5CC,MAAM,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./composables/the
|
|
|
7
7
|
import PlateWave from "./directives/plate-wave/index.mjs";
|
|
8
8
|
import { YUYEON_LOGO } from "./etc/index.mjs"; //
|
|
9
9
|
import "./styles/base.scss";
|
|
10
|
+
import { createIconModule, YUYEON_ICON_KEY } from "./composables/icon.mjs";
|
|
10
11
|
const defaultOptions = {
|
|
11
12
|
credit: true
|
|
12
13
|
};
|
|
@@ -15,6 +16,7 @@ export function init() {
|
|
|
15
16
|
const themeModule = createThemeModule(options?.theme);
|
|
16
17
|
const i18nModule = createI18nModule(options?.i18n);
|
|
17
18
|
const dateModule = createDateModule(options?.date, i18nModule.localeModule);
|
|
19
|
+
const iconModule = createIconModule(options?.icon);
|
|
18
20
|
const install = app => {
|
|
19
21
|
themeModule.install(app);
|
|
20
22
|
const yuyeon = reactive({
|
|
@@ -33,6 +35,7 @@ export function init() {
|
|
|
33
35
|
});
|
|
34
36
|
app.directive('plate-wave', PlateWave);
|
|
35
37
|
app.provide(YUYEON_THEME_KEY, themeModule.instance);
|
|
38
|
+
app.provide(YUYEON_ICON_KEY, iconModule);
|
|
36
39
|
app.provide(YUYEON_I18N_KEY, {
|
|
37
40
|
...i18nModule.localeModule,
|
|
38
41
|
...i18nModule.rtlModule
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["nextTick","reactive","components","YUYEON_DATE_KEY","YUYEON_DATE_OPTIONS_KEY","createDateModule","createI18nModule","YUYEON_I18N_KEY","YUYEON_THEME_KEY","createThemeModule","useTheme","PlateWave","YUYEON_LOGO","defaultOptions","credit","init","options","arguments","length","undefined","themeModule","theme","i18nModule","i18n","dateModule","date","localeModule","install","app","yuyeon","root","instance","rtlModule","Object","keys","forEach","componentName","comp","component","directive","provide","config","globalProperties","$yuyeon","_instance","_container","Error","$el","classList","add","setAttribute","console","log","unmount","scope","stop"],"sources":["../src/index.ts"],"sourcesContent":["import { Component, ComponentInternalInstance } from '@vue/runtime-core';\r\nimport type { App } from 'vue';\r\nimport { nextTick, reactive } from 'vue';\r\n\r\nimport * as components from './components';\r\nimport {\r\n YUYEON_DATE_KEY,\r\n YUYEON_DATE_OPTIONS_KEY,\r\n createDateModule,\r\n} from './composables/date';\r\nimport { createI18nModule } from './composables/i18n';\r\nimport { YUYEON_I18N_KEY } from './composables/i18n/share';\r\nimport {\r\n YUYEON_THEME_KEY,\r\n createThemeModule,\r\n useTheme,\r\n} from './composables/theme';\r\nimport PlateWave from './directives/plate-wave';\r\nimport { YUYEON_LOGO } from './etc';\r\n\r\n//\r\nimport './styles/base.scss';\r\n\r\nconst defaultOptions = {\r\n credit: true,\r\n};\r\n\r\ndeclare module 'vue' {\r\n interface ComponentCustomProperties {\r\n $yuyeon: any;\r\n }\r\n}\r\n\r\nexport function init(options: any = defaultOptions) {\r\n const themeModule = createThemeModule(options?.theme);\r\n const i18nModule = createI18nModule(options?.i18n);\r\n const dateModule = createDateModule(options?.date, i18nModule.localeModule);\r\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["nextTick","reactive","components","YUYEON_DATE_KEY","YUYEON_DATE_OPTIONS_KEY","createDateModule","createI18nModule","YUYEON_I18N_KEY","YUYEON_THEME_KEY","createThemeModule","useTheme","PlateWave","YUYEON_LOGO","createIconModule","YUYEON_ICON_KEY","defaultOptions","credit","init","options","arguments","length","undefined","themeModule","theme","i18nModule","i18n","dateModule","date","localeModule","iconModule","icon","install","app","yuyeon","root","instance","rtlModule","Object","keys","forEach","componentName","comp","component","directive","provide","config","globalProperties","$yuyeon","_instance","_container","Error","$el","classList","add","setAttribute","console","log","unmount","scope","stop"],"sources":["../src/index.ts"],"sourcesContent":["import { Component, ComponentInternalInstance } from '@vue/runtime-core';\r\nimport type { App } from 'vue';\r\nimport { nextTick, reactive } from 'vue';\r\n\r\nimport * as components from './components';\r\nimport {\r\n YUYEON_DATE_KEY,\r\n YUYEON_DATE_OPTIONS_KEY,\r\n createDateModule,\r\n} from './composables/date';\r\nimport { createI18nModule } from './composables/i18n';\r\nimport { YUYEON_I18N_KEY } from './composables/i18n/share';\r\nimport {\r\n YUYEON_THEME_KEY,\r\n createThemeModule,\r\n useTheme,\r\n} from './composables/theme';\r\nimport PlateWave from './directives/plate-wave';\r\nimport { YUYEON_LOGO } from './etc';\r\n\r\n//\r\nimport './styles/base.scss';\r\nimport {createIconModule, YUYEON_ICON_KEY} from \"./composables/icon\";\r\n\r\nconst defaultOptions = {\r\n credit: true,\r\n};\r\n\r\ndeclare module 'vue' {\r\n interface ComponentCustomProperties {\r\n $yuyeon: any;\r\n }\r\n}\r\n\r\nexport function init(options: any = defaultOptions) {\r\n const themeModule = createThemeModule(options?.theme);\r\n const i18nModule = createI18nModule(options?.i18n);\r\n const dateModule = createDateModule(options?.date, i18nModule.localeModule);\r\n const iconModule = createIconModule(options?.icon);\r\n const install = (app: App): any => {\r\n themeModule.install(app);\r\n\r\n const yuyeon = reactive({\r\n app: null as ComponentInternalInstance | null,\r\n root: null as HTMLElement | null,\r\n theme: themeModule.instance,\r\n i18n: {\r\n ...i18nModule.localeModule,\r\n ...i18nModule.rtlModule,\r\n },\r\n date: dateModule,\r\n });\r\n\r\n Object.keys(components).forEach((componentName) => {\r\n const comp = components[componentName as keyof typeof components];\r\n app.component(componentName, comp as Component);\r\n });\r\n\r\n app.directive('plate-wave', PlateWave);\r\n\r\n app.provide(YUYEON_THEME_KEY, themeModule.instance);\r\n app.provide(YUYEON_ICON_KEY, iconModule);\r\n app.provide(YUYEON_I18N_KEY, {\r\n ...i18nModule.localeModule,\r\n ...i18nModule.rtlModule,\r\n });\r\n app.provide(YUYEON_DATE_OPTIONS_KEY, dateModule.options);\r\n app.provide(YUYEON_DATE_KEY, dateModule.instance);\r\n\r\n app.config.globalProperties.$yuyeon = yuyeon;\r\n\r\n nextTick(() => {\r\n yuyeon.app = app._instance as any;\r\n yuyeon.root = app._container;\r\n if (!yuyeon.root) {\r\n throw new Error(`yuyeon: Can't found instance`);\r\n }\r\n const $el = yuyeon.root;\r\n $el.classList.add('y-root');\r\n $el.setAttribute('data-y-root', '');\r\n themeModule.init(yuyeon);\r\n });\r\n if (options?.credit) {\r\n console.log(YUYEON_LOGO);\r\n }\r\n const { unmount } = app;\r\n app.unmount = () => {\r\n unmount();\r\n themeModule.scope.stop();\r\n app.unmount = unmount;\r\n };\r\n };\r\n\r\n return {\r\n install,\r\n };\r\n}\r\n\r\nexport { useTheme };\r\n"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,QAAQ,QAAQ,KAAK;AAAC,OAElC,KAAKC,UAAU;AAAA,SAEpBC,eAAe,EACfC,uBAAuB,EACvBC,gBAAgB;AAAA,SAETC,gBAAgB;AAAA,SAChBC,eAAe;AAAA,SAEtBC,gBAAgB,EAChBC,iBAAiB,EACjBC,QAAQ;AAAA,OAEHC,SAAS;AAAA,SACPC,WAAW,2BAEpB;AACA;AAA4B,SACpBC,gBAAgB,EAAEC,eAAe;AAEzC,MAAMC,cAAc,GAAG;EACrBC,MAAM,EAAE;AACV,CAAC;AAQD,OAAO,SAASC,IAAIA,CAAA,EAAgC;EAAA,IAA/BC,OAAY,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGJ,cAAc;EAChD,MAAMO,WAAW,GAAGb,iBAAiB,CAACS,OAAO,EAAEK,KAAK,CAAC;EACrD,MAAMC,UAAU,GAAGlB,gBAAgB,CAACY,OAAO,EAAEO,IAAI,CAAC;EAClD,MAAMC,UAAU,GAAGrB,gBAAgB,CAACa,OAAO,EAAES,IAAI,EAAEH,UAAU,CAACI,YAAY,CAAC;EAC3E,MAAMC,UAAU,GAAGhB,gBAAgB,CAACK,OAAO,EAAEY,IAAI,CAAC;EAClD,MAAMC,OAAO,GAAIC,GAAQ,IAAU;IACjCV,WAAW,CAACS,OAAO,CAACC,GAAG,CAAC;IAExB,MAAMC,MAAM,GAAGhC,QAAQ,CAAC;MACtB+B,GAAG,EAAE,IAAwC;MAC7CE,IAAI,EAAE,I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CAAC;MAC3BF,GAAG,CAACG,YAAY,CAAC,aAAa,EAAE,EAAE,CAAC;MACnChC,WAAW,CAACL,IAAI,CAACgB,MAAM,CAAC;IAC1B,CAAC,CAAC;IACF,IAAIf,OAAO,EAAEF,MAAM,EAAE;MACnBuC,OAAO,CAACC,GAAG,CAAC5C,WAAW,CAAC;IAC1B;IACA,MAAM;MAAE6C;IAAQ,CAAC,GAAGzB,GAAG;IACvBA,GAAG,CAACyB,OAAO,GAAG,MAAM;MAClBA,OAAO,CAAC,CAAC;MACTnC,WAAW,CAACoC,KAAK,CAACC,IAAI,CAAC,CAAC;MACxB3B,GAAG,CAACyB,OAAO,GAAGA,OAAO;IACvB,CAAC;EACH,CAAC;EAED,OAAO;IACL1B;EACF,CAAC;AACH;AAEA,SAASrB,QAAQ"}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
@use 'sass:map';
|
|
2
|
-
|
|
3
|
-
$border-radius: (
|
|
4
|
-
'top': (
|
|
5
|
-
'top-left',
|
|
6
|
-
'top-right',
|
|
7
|
-
),
|
|
8
|
-
'bottom': (
|
|
9
|
-
'bottom-left',
|
|
10
|
-
'bottom-right',
|
|
11
|
-
),
|
|
12
|
-
'left': (
|
|
13
|
-
'top-left',
|
|
14
|
-
'bottom-left',
|
|
15
|
-
),
|
|
16
|
-
'right': (
|
|
17
|
-
'top-right',
|
|
18
|
-
'bottom-right',
|
|
19
|
-
),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
@mixin borderRadius($round, $side) {
|
|
23
|
-
@if ($side == null) {
|
|
24
|
-
border-radius: $round;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@if (map.has-key($border-radius, $side)) {
|
|
28
|
-
$props: map.get($border-radius, $side);
|
|
29
|
-
@each $prop in $props {
|
|
30
|
-
@debug $prop;
|
|
31
|
-
border-#{$prop}-radius: $round;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
@use 'sass:map';
|
|
2
|
+
|
|
3
|
+
$border-radius: (
|
|
4
|
+
'top': (
|
|
5
|
+
'top-left',
|
|
6
|
+
'top-right',
|
|
7
|
+
),
|
|
8
|
+
'bottom': (
|
|
9
|
+
'bottom-left',
|
|
10
|
+
'bottom-right',
|
|
11
|
+
),
|
|
12
|
+
'left': (
|
|
13
|
+
'top-left',
|
|
14
|
+
'bottom-left',
|
|
15
|
+
),
|
|
16
|
+
'right': (
|
|
17
|
+
'top-right',
|
|
18
|
+
'bottom-right',
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
@mixin borderRadius($round, $side) {
|
|
23
|
+
@if ($side == null) {
|
|
24
|
+
border-radius: $round;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@if (map.has-key($border-radius, $side)) {
|
|
28
|
+
$props: map.get($border-radius, $side);
|
|
29
|
+
@each $prop in $props {
|
|
30
|
+
@debug $prop;
|
|
31
|
+
border-#{$prop}-radius: $round;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/lib/types/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["import { HTMLAttributes } from '@vue/runtime-dom';\nimport type { ComponentPublicInstance, FunctionalComponent } from 'vue';\n\nexport type CandidateKey = string | number;\nexport type JSXComponent<Props = any> =\n | FunctionalComponent<Props | Props & HTMLAttributes>\n | { new (): ComponentPublicInstance<Props | Props & HTMLAttributes> };\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yuyeon-date-adapter.mjs","names":["DateUtil","YuyeonDateAdapter","constructor","options","_defineProperty","locale","formats","getWeekArray","date","startOfMonth","endOfMonth","addDays","amount","addMonths","value","endOfDay","endOfYear","format","formatString","getDiff","comparing","unit","getYear","getMonth","getDay","getNextMonth","getWeekdays","isAfter","isBefore","isEqual","isSameDay","isSameMonth","isValid","isWithinRange","range","parseISO","setMonth","month","setYear","year","startOfDay","startOfYear","toISO","toJsDate"],"sources":["../../../../src/util/date/adapters/yuyeon-date-adapter.ts"],"sourcesContent":["import { DateUtil } from '../built-in';\r\nimport { DateAdapter, DateFormatOptions } from '../types';\r\n\r\nexport class YuyeonDateAdapter implements DateAdapter<Date> {\r\n public locale = 'ko-kr';\r\n\r\n public formats?: Record<string, DateFormatOptions>;\r\n\r\n constructor(options: {\r\n locale: string;\r\n formats?: Record<string, DateFormatOptions>;\r\n }) {\r\n this.locale = options.locale;\r\n this.formats = options.formats;\r\n }\r\n\r\n public getWeekArray(date: Date) {\r\n return DateUtil.getWeekArray(date, this.locale);\r\n }\r\n\r\n public startOfMonth(date: Date) {\r\n return DateUtil.startOfMonth(date);\r\n }\r\n\r\n public endOfMonth(date: Date) {\r\n return DateUtil.endOfMonth(date);\r\n }\r\n\r\n public addDays(date: Date, amount: number): Date {\r\n return DateUtil.addDays(date, amount);\r\n }\r\n\r\n public addMonths(date: Date, amount: number): Date {\r\n return DateUtil.addMonths(date, amount);\r\n }\r\n\r\n public date(value?: any): Date | null {\r\n return DateUtil.date(value);\r\n }\r\n\r\n public endOfDay(date: Date): Date {\r\n return DateUtil.endOfDay(date);\r\n }\r\n\r\n public endOfYear(date: Date): Date {\r\n return DateUtil.endOfYear(date);\r\n }\r\n\r\n public format(date: Date, formatString: string): string {\r\n return DateUtil.format(date, formatString, this.locale, this.formats);\r\n }\r\n\r\n public getDiff(date: Date, comparing: string | Date, unit?: string): number {\r\n return DateUtil.getDiff(date, comparing, unit);\r\n }\r\n\r\n public getYear(date: Date): number {\r\n return DateUtil.getYear(date);\r\n }\r\n\r\n public getMonth(date: Date): number {\r\n return DateUtil.getMonth(date);\r\n }\r\n\r\n public getDay(date: Date): number {\r\n return DateUtil.getDay(date);\r\n }\r\n\r\n public getNextMonth(date: Date): Date {\r\n return DateUtil.getNextMonth(date);\r\n }\r\n\r\n public getWeekdays(): string[] {\r\n return DateUtil.getWeekdays(this.locale);\r\n }\r\n\r\n public isAfter(date: Date, comparing: Date): boolean {\r\n return DateUtil.isAfter(date, comparing);\r\n }\r\n\r\n public isBefore(date: Date, comparing: Date): boolean {\r\n return DateUtil.isBefore(date, comparing);\r\n }\r\n\r\n public isEqual(date: Date, comparing: Date): boolean {\r\n return DateUtil.isEqual(date, comparing);\r\n }\r\n\r\n public isSameDay(date: Date, comparing: Date): boolean {\r\n return DateUtil.isSameDay(date, comparing);\r\n }\r\n\r\n public isSameMonth(date: Date, comparing: Date): boolean {\r\n return DateUtil.isSameMonth(date, comparing);\r\n }\r\n\r\n public isValid(date: any): boolean {\r\n return DateUtil.isValid(date);\r\n }\r\n\r\n public isWithinRange(date: Date, range: [Date, Date]): boolean {\r\n return DateUtil.isWithinRange(date, range);\r\n }\r\n\r\n public parseISO(date: string): Date {\r\n return DateUtil.parseISO(date);\r\n }\r\n\r\n public setMonth(date: Date, month: number): Date {\r\n return DateUtil.setMonth(date, month);\r\n }\r\n\r\n public setYear(date: Date, year: number): Date {\r\n return DateUtil.setYear(date, year);\r\n }\r\n\r\n public startOfDay(date: Date): Date {\r\n return DateUtil.startOfDay(date);\r\n }\r\n\r\n public startOfYear(date: Date): Date {\r\n return DateUtil.startOfYear(date);\r\n }\r\n\r\n public toISO(date: Date): string {\r\n return DateUtil.toISO(date);\r\n }\r\n\r\n public toJsDate(date: Date): Date {\r\n return date;\r\n }\r\n}\r\n"],"mappings":";;;SAASA,QAAQ;AAGjB,OAAO,MAAMC,iBAAiB,CAA8B;EAKxDC,WAAWA,CAACC,OAGX,EAAE;IAAAC,eAAA,iBAPa,OAAO;IAQnB,IAAI,CAACC,MAAM,GAAGF,OAAO,CAACE,MAAM;IAC5B,IAAI,CAACC,OAAO,GAAGH,OAAO,CAACG,OAAO;EAClC;EAEOC,YAAYA,CAACC,IAAU,EAAE;IAC5B,OAAOR,QAAQ,CAACO,YAAY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AClC;EAEO4B,QAAQA,CAAC5B,IAAU,EAAE6B,KAAa,EAAQ;IAC7C,OAAOrC,QAAQ,CAACoC,QAAQ,CAAC5B,IAAI,EAAE6B,KAAK,CAAC;EACzC;EAEOC,OAAOA,CAAC9B,IAAU,EAAE+B,IAAY,EAAQ;IAC3C,OAAOvC,QAAQ,CAACsC,OAAO,CAAC9B,IAAI,EAAE+B,IAAI,CAAC;EACvC;EAEOC,UAAUA,CAAChC,IAAU,EAAQ;IAChC,OAAOR,QAAQ,CAACwC,UAAU,CAAChC,IAAI,CAAC;EACpC;EAEOiC,WAAWA,CAACjC,IAAU,EAAQ;IACjC,OAAOR,QAAQ,CAACyC,WAAW,CAACjC,IAAI,CAAC;EACrC;EAEOkC,KAAKA,CAAClC,IAAU,EAAU;IAC7B,OAAOR,QAAQ,CAAC0C,KAAK,
|
|
1
|
+
{"version":3,"file":"yuyeon-date-adapter.mjs","names":["DateUtil","YuyeonDateAdapter","constructor","options","_defineProperty","locale","formats","getWeekArray","date","startOfMonth","endOfMonth","addDays","amount","addMonths","value","endOfDay","endOfYear","format","formatString","getDiff","comparing","unit","getYear","getMonth","getDay","getNextMonth","getWeekdays","isAfter","isBefore","isEqual","isSameDay","isSameMonth","isValid","isWithinRange","range","parseISO","setMonth","month","setYear","year","startOfDay","startOfYear","toISO","toJsDate"],"sources":["../../../../src/util/date/adapters/yuyeon-date-adapter.ts"],"sourcesContent":["import { DateUtil } from '../built-in';\r\nimport { DateAdapter, DateFormatOptions } from '../types';\r\n\r\nexport class YuyeonDateAdapter implements DateAdapter<Date> {\r\n public locale = 'ko-kr';\r\n\r\n public formats?: Record<string, DateFormatOptions>;\r\n\r\n constructor(options: {\r\n locale: string;\r\n formats?: Record<string, DateFormatOptions>;\r\n }) {\r\n this.locale = options.locale;\r\n this.formats = options.formats;\r\n }\r\n\r\n public getWeekArray(date: Date) {\r\n return DateUtil.getWeekArray(date, this.locale);\r\n }\r\n\r\n public startOfMonth(date: Date) {\r\n return DateUtil.startOfMonth(date);\r\n }\r\n\r\n public endOfMonth(date: Date) {\r\n return DateUtil.endOfMonth(date);\r\n }\r\n\r\n public addDays(date: Date, amount: number): Date {\r\n return DateUtil.addDays(date, amount);\r\n }\r\n\r\n public addMonths(date: Date, amount: number): Date {\r\n return DateUtil.addMonths(date, amount);\r\n }\r\n\r\n public date(value?: any): Date | null {\r\n return DateUtil.date(value);\r\n }\r\n\r\n public endOfDay(date: Date): Date {\r\n return DateUtil.endOfDay(date);\r\n }\r\n\r\n public endOfYear(date: Date): Date {\r\n return DateUtil.endOfYear(date);\r\n }\r\n\r\n public format(date: Date, formatString: string): string {\r\n return DateUtil.format(date, formatString, this.locale, this.formats);\r\n }\r\n\r\n public getDiff(date: Date, comparing: string | Date, unit?: string): number {\r\n return DateUtil.getDiff(date, comparing, unit);\r\n }\r\n\r\n public getYear(date: Date): number {\r\n return DateUtil.getYear(date);\r\n }\r\n\r\n public getMonth(date: Date): number {\r\n return DateUtil.getMonth(date);\r\n }\r\n\r\n public getDay(date: Date): number {\r\n return DateUtil.getDay(date);\r\n }\r\n\r\n public getNextMonth(date: Date): Date {\r\n return DateUtil.getNextMonth(date);\r\n }\r\n\r\n public getWeekdays(): string[] {\r\n return DateUtil.getWeekdays(this.locale);\r\n }\r\n\r\n public isAfter(date: Date, comparing: Date): boolean {\r\n return DateUtil.isAfter(date, comparing);\r\n }\r\n\r\n public isBefore(date: Date, comparing: Date): boolean {\r\n return DateUtil.isBefore(date, comparing);\r\n }\r\n\r\n public isEqual(date: Date, comparing: Date): boolean {\r\n return DateUtil.isEqual(date, comparing);\r\n }\r\n\r\n public isSameDay(date: Date, comparing: Date): boolean {\r\n return DateUtil.isSameDay(date, comparing);\r\n }\r\n\r\n public isSameMonth(date: Date, comparing: Date): boolean {\r\n return DateUtil.isSameMonth(date, comparing);\r\n }\r\n\r\n public isValid(date: any): boolean {\r\n return DateUtil.isValid(date);\r\n }\r\n\r\n public isWithinRange(date: Date, range: [Date, Date]): boolean {\r\n return DateUtil.isWithinRange(date, range);\r\n }\r\n\r\n public parseISO(date: string): Date {\r\n return DateUtil.parseISO(date);\r\n }\r\n\r\n public setMonth(date: Date, month: number): Date {\r\n return DateUtil.setMonth(date, month);\r\n }\r\n\r\n public setYear(date: Date, year: number): Date {\r\n return DateUtil.setYear(date, year);\r\n }\r\n\r\n public startOfDay(date: Date): Date {\r\n return DateUtil.startOfDay(date);\r\n }\r\n\r\n public startOfYear(date: Date): Date {\r\n return DateUtil.startOfYear(date);\r\n }\r\n\r\n public toISO(date: Date): string {\r\n return DateUtil.toISO(this, date);\r\n }\r\n\r\n public toJsDate(date: Date): Date {\r\n return date;\r\n }\r\n}\r\n"],"mappings":";;;SAASA,QAAQ;AAGjB,OAAO,MAAMC,iBAAiB,CAA8B;EAKxDC,WAAWA,CAACC,OAGX,EAAE;IAAAC,eAAA,iBAPa,OAAO;IAQnB,IAAI,CAACC,MAAM,GAAGF,OAAO,CAACE,MAAM;IAC5B,IAAI,CAACC,OAAO,GAAGH,OAAO,CAACG,OAAO;EAClC;EAEOC,YAAYA,CAACC,IAAU,EAAE;IAC5B,OAAOR,QAAQ,CAACO,YAAY,CAACC,IAAI,EAAE,IAAI,CAACH,MAAM,CAAC;EACnD;EAEOI,YAAYA,CAACD,IAAU,EAAE;IAC5B,OAAOR,QAAQ,CAACS,YAAY,CAACD,IAAI,CAAC;EACtC;EAEOE,UAAUA,CAACF,IAAU,EAAE;IAC1B,OAAOR,QAAQ,CAACU,UAAU,CAACF,IAAI,CAAC;EACpC;EAEOG,OAAOA,CAACH,IAAU,EAAEI,MAAc,EAAQ;IAC7C,OAAOZ,QAAQ,CAACW,OAAO,CAACH,IAAI,EAAEI,MAAM,CAAC;EACzC;EAEOC,SAASA,CAACL,IAAU,EAAEI,MAAc,EAAQ;IAC/C,OAAOZ,QAAQ,CAACa,SAAS,CAACL,IAAI,EAAEI,MAAM,CAAC;EAC3C;EAEOJ,IAAIA,CAACM,KAAW,EAAe;IAClC,OAAOd,QAA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AK,CAAC,IAAI,EAAElC,IAAI,CAAC;EACrC;EAEOmC,QAAQA,CAACnC,IAAU,EAAQ;IAC9B,OAAOA,IAAI;EACf;AACJ"}
|
|
@@ -256,8 +256,12 @@ export class DateUtil {
|
|
|
256
256
|
const [year, month, day] = value.split('-').map(Number);
|
|
257
257
|
return new Date(year, month - 1, day);
|
|
258
258
|
}
|
|
259
|
-
static toISO(
|
|
260
|
-
|
|
259
|
+
static toISO(adapter, value) {
|
|
260
|
+
const date = adapter.toJsDate(value);
|
|
261
|
+
const year = date.getFullYear();
|
|
262
|
+
const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : `${date.getMonth() + 1}`;
|
|
263
|
+
const day = date.getDate() < 10 ? `0${date.getDate()}` : `${date.getDate()}`;
|
|
264
|
+
return `${year}-${month}-${day}`;
|
|
261
265
|
}
|
|
262
266
|
static getWeekArray(date, locale) {
|
|
263
267
|
const weeks = [];
|