@stonecrop/aform 0.11.0 → 0.11.1

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.
@@ -1,104 +0,0 @@
1
- /**
2
- * Extracts a mask function from a stringified function
3
- * @param mask - Mask string
4
- * @returns Mask function
5
- */
6
- function extractMaskFn(mask) {
7
- try {
8
- // eslint-disable-next-line @typescript-eslint/no-implied-eval, @typescript-eslint/no-unsafe-call
9
- return Function(`"use strict";return (${mask})`)();
10
- }
11
- catch (error) {
12
- if (error instanceof ReferenceError) {
13
- // assume mask is a string
14
- }
15
- }
16
- }
17
- /**
18
- * Gets the mask for a given directive binding
19
- * @param binding - Binding object from directive hook
20
- * @returns Mask string
21
- */
22
- function getMask(binding) {
23
- const mask = binding.value;
24
- if (!mask)
25
- return undefined;
26
- const maskFn = extractMaskFn(mask);
27
- if (maskFn) {
28
- // TODO: (state) replace with state management;
29
- // pass the entire form/table data to the function
30
- const instance = binding.instance;
31
- const locale = instance?.locale;
32
- return maskFn(locale);
33
- }
34
- return mask;
35
- }
36
- /**
37
- * Unmasks the input string
38
- * @param input - Input string
39
- * @param maskToken - Mask token character
40
- * @returns Unmasked input string
41
- */
42
- function unmaskInput(input, maskToken) {
43
- if (!maskToken) {
44
- maskToken = '#';
45
- }
46
- let unmaskedInput = input;
47
- const maskChars = [maskToken, '/', '-', '(', ')', ' '];
48
- for (const char of maskChars) {
49
- unmaskedInput = unmaskedInput.replaceAll(char, '');
50
- }
51
- return unmaskedInput;
52
- }
53
- /**
54
- * Fills the mask with the input string
55
- * @param input - Input string
56
- * @param mask - Mask string
57
- * @param maskToken - Mask token character
58
- * @returns Masked input string
59
- */
60
- function fillMask(input, mask, maskToken) {
61
- if (!maskToken) {
62
- maskToken = '#';
63
- }
64
- let replacement = mask;
65
- for (const inputChar of input) {
66
- const replaceIndex = replacement.indexOf(maskToken);
67
- if (replaceIndex !== -1) {
68
- const prefix = replacement.substring(0, replaceIndex);
69
- const suffix = replacement.substring(replaceIndex + 1);
70
- replacement = prefix + inputChar + suffix;
71
- }
72
- }
73
- return replacement.slice(0, mask.length);
74
- }
75
- /**
76
- * Applies a mask to an input element
77
- * @param el - Input element
78
- * @param binding - Binding object from directive hook
79
- * @returns void
80
- * @public
81
- */
82
- export function useStringMask(el, binding) {
83
- const mask = getMask(binding);
84
- if (!mask)
85
- return;
86
- const maskToken = '#';
87
- const inputText = el.value;
88
- // process input value with mask
89
- const unmaskedInput = unmaskInput(inputText, maskToken);
90
- if (unmaskedInput) {
91
- const replacement = fillMask(unmaskedInput, mask, maskToken);
92
- // TODO: (state) this is very opinionated;
93
- // most likely fixed with state management;
94
- // a better way could be to emit back to instance;
95
- const instance = binding.instance;
96
- if (instance?.maskFilled !== undefined) {
97
- instance.maskFilled = !replacement.includes(maskToken);
98
- }
99
- el.value = replacement;
100
- }
101
- else {
102
- el.value = mask;
103
- }
104
- }
package/dist/src/index.js DELETED
@@ -1,32 +0,0 @@
1
- import { install as installATable } from '@stonecrop/atable';
2
- import ACheckbox from './components/form/ACheckbox.vue';
3
- import AComboBox from './components/form/AComboBox.vue';
4
- import ADate from './components/form/ADate.vue';
5
- import ADropdown from './components/form/ADropdown.vue';
6
- import ADatePicker from './components/form/ADatePicker.vue';
7
- import AFieldset from './components/form/AFieldset.vue';
8
- import AFileAttach from './components/form/AFileAttach.vue';
9
- import AForm from './components/AForm.vue';
10
- import ANumericInput from './components/form/ANumericInput.vue';
11
- import ATextInput from './components/form/ATextInput.vue';
12
- import Login from './components/utilities/Login.vue';
13
- export { isDoctypeMany } from './utils/doctype';
14
- /**
15
- * Install all AForm components
16
- * @param app - Vue app instance
17
- * @public
18
- */
19
- function install(app /* options */) {
20
- app.use(installATable); // Install ATable components for use within AForm
21
- app.component('ACheckbox', ACheckbox);
22
- app.component('AComboBox', AComboBox);
23
- app.component('ADate', ADate);
24
- app.component('ADropdown', ADropdown);
25
- app.component('ADatePicker', ADatePicker);
26
- app.component('AFieldset', AFieldset);
27
- app.component('AFileAttach', AFileAttach);
28
- app.component('AForm', AForm);
29
- app.component('ANumericInput', ANumericInput);
30
- app.component('ATextInput', ATextInput);
31
- }
32
- export { ACheckbox, AComboBox, ADate, ADropdown, ADatePicker, AFieldset, AFileAttach, AForm, ANumericInput, ATextInput, Login, install, };
@@ -1,11 +0,0 @@
1
- // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
- // It should be published with your NPM package. It should not be tracked by Git.
3
- {
4
- "tsdocVersion": "0.12",
5
- "toolPackages": [
6
- {
7
- "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.57.0"
9
- }
10
- ]
11
- }
File without changes
@@ -1,10 +0,0 @@
1
- import type { DoctypeSchema, DoctypeManySchema } from '../types';
2
- /**
3
- * Type guard that checks whether a Doctype schema field has `cardinality: 'many'`
4
- *
5
- * @param field - A DoctypeSchema field to check
6
- * @returns `true` if the field has `cardinality: 'many'`
7
- * @public
8
- */
9
- export declare function isDoctypeMany(field: DoctypeSchema): field is DoctypeManySchema;
10
- //# sourceMappingURL=doctype.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../../src/utils/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEhE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,iBAAiB,CAE9E"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Type guard that checks whether a Doctype schema field has `cardinality: 'many'`
3
- *
4
- * @param field - A DoctypeSchema field to check
5
- * @returns `true` if the field has `cardinality: 'many'`
6
- * @public
7
- */
8
- export function isDoctypeMany(field) {
9
- return field.cardinality === 'many';
10
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Type guard that checks whether a Doctype schema field has `cardinality: 'many'`
3
- *
4
- * @param field - A DoctypeSchema field to check
5
- * @returns `true` if the field has `cardinality: 'many'`
6
- * @public
7
- */
8
- export function isDoctypeMany(field) {
9
- return field.cardinality === 'many';
10
- }