rb-document-form-constructor 0.1.2 → 0.1.6

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.
@@ -0,0 +1,27 @@
1
+ $rb-field-rule-btn-toolbar-bg: rgba(0, 0, 0, 0.03) !default;
2
+
3
+ .rb-field-rule-form-modal {
4
+ .modal-body {
5
+ padding: 0;
6
+
7
+ & > .card {
8
+ border: none;
9
+ border-radius: 0;
10
+ }
11
+ }
12
+
13
+ .btn-toolbar {
14
+ border-top-left-radius: $border-radius;
15
+ border-top-right-radius: $border-radius;
16
+ background-color: $rb-field-rule-btn-toolbar-bg;
17
+ padding: 10px 10px;
18
+ border-top: 1px solid $border-color;
19
+ border-left: 1px solid $border-color;
20
+ border-right: 1px solid $border-color;
21
+ }
22
+
23
+ textarea.form-control {
24
+ border-top-left-radius: 0;
25
+ border-top-right-radius: 0;
26
+ }
27
+ }
@@ -4,3 +4,4 @@
4
4
  @import 'components/doc-template-field-sidebar';
5
5
  @import 'components/doc-template-constructor';
6
6
  @import 'components/doc-form';
7
+ @import 'components/field-rule-form-modal';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rb-document-form-constructor",
3
- "version": "0.1.2",
3
+ "version": "0.1.6",
4
4
  "description": "",
5
5
  "main": "dist/rb-document-form-constructor.ssr.js",
6
6
  "browser": "dist/rb-document-form-constructor.esm.js",
@@ -17,7 +17,7 @@
17
17
  "build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js",
18
18
  "build:ssr": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format cjs",
19
19
  "build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
20
- "build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife"
20
+ "build:unpkg": "cross-env kNODE_ENV=production rollup --config build/rollup.config.js --format iife"
21
21
  },
22
22
  "dependencies": {
23
23
  "bootstrap": "^4.5.0",
@@ -26,6 +26,7 @@
26
26
  "jquery": "^3.6.0",
27
27
  "sass": "^1.32.0",
28
28
  "sass-loader": "^10.1.0",
29
+ "uuid": "^8.3.2",
29
30
  "vuedraggable": "^2.24.3"
30
31
  },
31
32
  "devDependencies": {
@@ -40,15 +41,16 @@
40
41
  "@vue/cli-service": "^4.5.13",
41
42
  "cross-env": "^7.0.3",
42
43
  "minimist": "^1.2.5",
44
+ "rb-bv-components": "^1.4.1",
43
45
  "rimraf": "^3.0.2",
44
46
  "rollup": "^2.52.8",
45
47
  "rollup-plugin-copy-assets": "^2.0.3",
46
48
  "rollup-plugin-sass": "^1.2.6",
47
49
  "rollup-plugin-terser": "^7.0.2",
48
50
  "rollup-plugin-vue": "^5.1.9",
51
+ "rubles": "^0.2.0",
49
52
  "vue": "^2.6.14",
50
- "vue-template-compiler": "^2.6.14",
51
- "rb-bv-components": "^1.4.1"
53
+ "vue-template-compiler": "^2.6.14"
52
54
  },
53
55
  "peerDependencies": {
54
56
  "vue": "^2.6.14"
@@ -0,0 +1,75 @@
1
+ This webfont is generated by https://fontello.com open source project.
2
+
3
+
4
+ ================================================================================
5
+ Please, note, that you should obey original font licenses, used to make this
6
+ webfont pack. Details available in LICENSE.txt file.
7
+
8
+ - Usually, it's enough to publish content of LICENSE.txt file somewhere on your
9
+ site in "About" section.
10
+
11
+ - If your project is open-source, usually, it will be ok to make LICENSE.txt
12
+ file publicly available in your repository.
13
+
14
+ - Fonts, used in Fontello, don't require a clickable link on your site.
15
+ But any kind of additional authors crediting is welcome.
16
+ ================================================================================
17
+
18
+
19
+ Comments on archive content
20
+ ---------------------------
21
+
22
+ - /font/* - fonts in different formats
23
+
24
+ - /css/* - different kinds of css, for all situations. Should be ok with
25
+ twitter bootstrap. Also, you can skip <i> style and assign icon classes
26
+ directly to text elements, if you don't mind about IE7.
27
+
28
+ - demo.html - demo file, to show your webfont content
29
+
30
+ - LICENSE.txt - license info about source fonts, used to build your one.
31
+
32
+ - config.json - keeps your settings. You can import it back into fontello
33
+ anytime, to continue your work
34
+
35
+
36
+ Why so many CSS files ?
37
+ -----------------------
38
+
39
+ Because we like to fit all your needs :)
40
+
41
+ - basic file, <your_font_name>.css - is usually enough, it contains @font-face
42
+ and character code definitions
43
+
44
+ - *-ie7.css - if you need IE7 support, but still don't wish to put char codes
45
+ directly into html
46
+
47
+ - *-codes.css and *-ie7-codes.css - if you like to use your own @font-face
48
+ rules, but still wish to benefit from css generation. That can be very
49
+ convenient for automated asset build systems. When you need to update font -
50
+ no need to manually edit files, just override old version with archive
51
+ content. See fontello source code for examples.
52
+
53
+ - *-embedded.css - basic css file, but with embedded WOFF font, to avoid
54
+ CORS issues in Firefox and IE9+, when fonts are hosted on the separate domain.
55
+ We strongly recommend to resolve this issue by `Access-Control-Allow-Origin`
56
+ server headers. But if you ok with dirty hack - this file is for you. Note,
57
+ that data url moved to separate @font-face to avoid problems with <IE9, when
58
+ string is too long.
59
+
60
+ - animate.css - use it to get ideas about spinner rotation animation.
61
+
62
+
63
+ Attention for server setup
64
+ --------------------------
65
+
66
+ You MUST setup server to reply with proper `mime-types` for font files -
67
+ otherwise some browsers will fail to show fonts.
68
+
69
+ Usually, `apache` already has necessary settings, but `nginx` and other
70
+ webservers should be tuned. Here is list of mime types for our file extensions:
71
+
72
+ - `application/vnd.ms-fontobject` - eot
73
+ - `application/x-font-woff` - woff
74
+ - `application/x-font-ttf` - ttf
75
+ - `image/svg+xml` - svg
@@ -5,18 +5,24 @@
5
5
  <h4>{{section.labelRu}}</h4>
6
6
 
7
7
  <div class="d-flex flex-row">
8
- <div class="rb-form-column" v-for="column in section.columns"
9
- :key="column.index" :class="{'rb-single-column': section.columnCount === 1}">
10
- <b-form-row v-for="field in column.fields" :key="field.name"
11
- class="cursor-pointer">
12
- <b-col lg="12">
13
- <b-form-group :label="field.labelRu" ref="inputContainer">
14
- <component v-bind:is="field.input.type"
15
- v-model="doc[field.name]"
16
- v-bind="field.input.propsData"></component>
17
- </b-form-group>
18
- </b-col>
19
- </b-form-row>
8
+ <div class="rb-form-column" v-for="column in section.columns" :key="column.index">
9
+ <template v-for="field in column.fields">
10
+ <b-form-row :key="field.name" v-if="field.visible">
11
+ <b-col lg="12">
12
+ <b-form-group :label="field.labelRu" ref="inputContainer">
13
+ <component v-bind:is="field.input.type"
14
+ v-model="doc[field.name]"
15
+ :disabled="!field.editable"
16
+ :state="validationState[field.name]"
17
+ :ref="field.name"
18
+ @input="onEventFired('input', $event, field)"
19
+ @change="onEventFired('change', $event, field)"
20
+ @click="onEventFired('click', $event, field)"
21
+ v-bind="field.input.propsData"></component>
22
+ </b-form-group>
23
+ </b-col>
24
+ </b-form-row>
25
+ </template>
20
26
  </div>
21
27
  </div>
22
28
  </div>
@@ -24,20 +30,45 @@
24
30
  </template>
25
31
 
26
32
  <script>
33
+ import {UtFormConstructor} from "../utils/UtFormConstructor";
34
+
27
35
  export default {
28
36
  name: 'DocForm',
29
37
  props: {
30
38
  formConfig: Object,
31
- doc: {type: Object, default: () => ({})}
39
+ applyDefaultValues: {type: Boolean, default: true},
40
+ doc: {type: Object, default: () => ({})},
41
+ validationState: {type: Object, default: () => ({})}
32
42
  },
33
- created() {
34
- this.formConfig.sections.forEach(r => {
35
- r.columns.forEach(c => {
36
- c.fields.forEach(f => {
37
- this.doc[f.name] = f.defaultValue;
43
+ methods: {
44
+ onEventFired(eventName, event, field) {
45
+ if (field.rules) {
46
+ field.rules.forEach(rule => {
47
+ if (rule.event === eventName && rule.script) {
48
+ let ruleContext = UtFormConstructor.getRuleContext();
49
+ ruleContext.form = this;
50
+ ruleContext.event = event;
51
+ ruleContext.eventName = eventName;
52
+ UtFormConstructor.runRule(ruleContext, rule.script);
53
+ }
38
54
  })
55
+ }
56
+ }
57
+ },
58
+ created() {
59
+ if (this.applyDefaultValues) {
60
+ this.formConfig.sections.forEach(r => {
61
+ r.columns.forEach(c => {
62
+ c.fields.forEach(f => {
63
+ this.$set(
64
+ this.doc,
65
+ f.name,
66
+ f.defaultValue == null ? null : f.defaultValue
67
+ );
68
+ })
69
+ });
39
70
  });
40
- });
71
+ }
41
72
  }
42
73
  }
43
74
  </script>
@@ -4,18 +4,18 @@
4
4
 
5
5
  <div class="rb-form-constructor flex-fill">
6
6
  <div class="rb-constructor-toolbar d-flex flex-row">
7
- <h4>Верстка документа</h4>
7
+ <h4>Добавить секцию: </h4>
8
8
  <div class="rb-layout-buttons">
9
9
  <b-button pill variant="outline-gray" @click="addSection(1)">
10
- <rb-text>1 колонка</rb-text>
10
+ <rb-text>Секция с 1 колонкой</rb-text>
11
11
  <rb-icon :icon="iconAdd"></rb-icon>
12
12
  </b-button>
13
13
  <b-button pill variant="outline-gray" @click="addSection(2)">
14
- <rb-text>2 колонки</rb-text>
14
+ <rb-text>Секция с 2 колонками</rb-text>
15
15
  <rb-icon :icon="iconAdd"></rb-icon>
16
16
  </b-button>
17
17
  <b-button pill variant="outline-gray" @click="addSection(3)">
18
- <rb-text>3 колонки</rb-text>
18
+ <rb-text>Секция с 3 колонками</rb-text>
19
19
  <rb-icon :icon="iconAdd"></rb-icon>
20
20
  </b-button>
21
21
  </div>
@@ -56,13 +56,13 @@
56
56
  ghost-class="rb-moving-item"
57
57
  handle=".rb-field-drag-handle">
58
58
  <b-form-row v-for="field in column.fields" :key="field.name"
59
- class="cursor-pointer" @click="showProperties(field)">
59
+ class="cursor-pointer" @click="showProperties(field, $event)">
60
60
  <b-col lg="12">
61
61
  <b-form-group :label="field.labelRu">
62
62
  <template #label>
63
63
  <rb-icon :icon="iconDrag" class="rb-field-drag-handle"></rb-icon>
64
64
  <rb-text>{{field.labelRu}}</rb-text>
65
- <rb-icon :icon="iconDelete"
65
+ <rb-icon :icon="iconDelete" class="rb-remove-field"
66
66
  @click.prevent="onRemoveField($event, field, column)">
67
67
  </rb-icon>
68
68
  </template>
@@ -81,13 +81,16 @@
81
81
  </draggable>
82
82
  </div>
83
83
 
84
- <doc-template-field-sidebar v-model="sidebarField" :visible="sidebarVisible"
84
+ <doc-template-field-sidebar v-model="sidebarField"
85
+ :visible="sidebarVisible"
86
+ :form-config="formConfig"
85
87
  @hide="sidebarVisible=false">
86
88
  </doc-template-field-sidebar>
87
89
 
88
90
  <doc-template-section-modal :mode="sectionModalCfg.mode"
89
91
  :section="sectionModalCfg.section"
90
- :on-after-ok="sectionModalCfg.onAfterOk"></doc-template-section-modal>
92
+ :on-after-ok="sectionModalCfg.onAfterOk">
93
+ </doc-template-section-modal>
91
94
  </div>
92
95
  </div>
93
96
  </template>
@@ -98,6 +101,7 @@
98
101
  import DocTemplateSectionModal from "@/components/DocTemplateSectionModal";
99
102
  import draggable from 'vuedraggable';
100
103
  import {UtFormConfig} from "../utils/UtFormConfig";
104
+ import {UtFormConstructor} from "../utils/UtFormConstructor";
101
105
 
102
106
  export default {
103
107
  name: 'DocTemplateConstructor',
@@ -127,20 +131,25 @@
127
131
  },
128
132
  computed: {
129
133
  iconAdd() {
130
- return UtFormConfig.config.icons.iconAdd;
134
+ return UtFormConstructor.config.icons.iconAdd;
131
135
  },
132
136
  iconEdit() {
133
- return UtFormConfig.config.icons.iconEdit;
137
+ return UtFormConstructor.config.icons.iconEdit;
134
138
  },
135
139
  iconDelete() {
136
- return UtFormConfig.config.icons.iconDelete;
140
+ return UtFormConstructor.config.icons.iconDelete;
137
141
  },
138
142
  iconDrag() {
139
- return UtFormConfig.config.icons.iconDrag;
143
+ return UtFormConstructor.config.icons.iconDrag;
140
144
  }
141
145
  },
142
146
  methods: {
143
- showProperties(field) {
147
+ showProperties(field, event) {
148
+ if (event.target.classList
149
+ && event.target.classList.contains('rb-remove-field')) {
150
+ return;
151
+ }
152
+
144
153
  this.sidebarVisible = true;
145
154
  this.sidebarField = field;
146
155
  },
@@ -164,7 +173,8 @@
164
173
  editSection(section) {
165
174
  this.sectionModalCfg.mode = 'update';
166
175
  this.sectionModalCfg.section = section;
167
- this.sectionModalCfg.onAfterOk = () => {}
176
+ this.sectionModalCfg.onAfterOk = () => {
177
+ }
168
178
  this.$bvModal.show(this.sectionModalCfg.id);
169
179
  },
170
180
  removeSection(section, index) {
@@ -200,12 +210,7 @@
200
210
  let index = newIndex != null ? newIndex : -1;
201
211
 
202
212
  if (index < 0) {
203
- column.fields.every((f, i) => {
204
- if (field.name === f.name) {
205
- index = i;
206
- return false;
207
- }
208
- });
213
+ index = column.fields.findIndex(f => field.name === f.name);
209
214
  }
210
215
 
211
216
  if (index >= 0) {
@@ -13,10 +13,9 @@
13
13
  </b-form>
14
14
  <div class="rb-facet-list">
15
15
  <div class="rb-facet" v-for="facet in innerFacets" :key="facet.name">
16
- <h6 class="rb-facet-label d-flex">
16
+ <h6 class="rb-facet-label d-flex cursor-pointer" @click="facet.expanded = !facet.expanded">
17
17
  <rb-text class="flex-fill">{{facet.labelRu}}</rb-text>
18
- <rb-icon :icon="facet.expanded? iconCollapseFacet: iconExpandFacet" class="cursor-pointer"
19
- @click="facet.expanded = !facet.expanded"></rb-icon>
18
+ <rb-icon :icon="facet.expanded? iconCollapseFacet: iconExpandFacet"></rb-icon>
20
19
  </h6>
21
20
 
22
21
  <b-list-group v-if="facet.expanded">
@@ -40,6 +39,7 @@
40
39
  <script>
41
40
  import draggable from "vuedraggable";
42
41
  import {UtFormConfig} from "@/utils/UtFormConfig";
42
+ import {UtFormConstructor} from "../utils/UtFormConstructor";
43
43
 
44
44
  export default {
45
45
  name: 'DocTemplateFacetList',
@@ -56,10 +56,10 @@
56
56
  },
57
57
  computed: {
58
58
  iconExpandFacet() {
59
- return UtFormConfig.config.icons.iconExpandFacet;
59
+ return UtFormConstructor.config.icons.iconExpandFacet;
60
60
  },
61
61
  iconCollapseFacet() {
62
- return UtFormConfig.config.icons.iconCollapseFacet;
62
+ return UtFormConstructor.config.icons.iconCollapseFacet;
63
63
  },
64
64
  },
65
65
  watch: {
@@ -73,7 +73,7 @@
73
73
  methods: {
74
74
  onFieldCloned(cloneField) {
75
75
  let field = JSON.parse(JSON.stringify(cloneField));
76
- field.input = UtFormConfig.getDefaultInput(field);
76
+ field.input = UtFormConstructor.getDefaultInput(field);
77
77
  return field;
78
78
  },
79
79
  onFieldMoveEnd(event) {
@@ -82,15 +82,12 @@
82
82
  v-bind="getPropInputPropData(prop, propName)"></component>
83
83
  </b-form-group>
84
84
  </template>
85
-
86
85
  </b-col>
87
86
  </b-form-row>
88
87
  </div>
89
88
 
90
89
  <div class="rb-form-section" v-if="field.input">
91
- <div class="rb-title">
92
- Значение по-умолчанию
93
- </div>
90
+ <div class="rb-title">Значение по-умолчанию</div>
94
91
 
95
92
  <b-form-row>
96
93
  <b-col lg="12">
@@ -102,15 +99,45 @@
102
99
  </b-col>
103
100
  </b-form-row>
104
101
  </div>
102
+
103
+ <div class="rb-form-section">
104
+ <div class="rb-title">Правила</div>
105
+
106
+ <b-list-group :data-hash="rulesHash">
107
+ <b-list-group-item v-for="rule in field.rules"
108
+ @click="editRule(rule, $event)"
109
+ :key="rule.id"
110
+ :data-hash="rulesHash"
111
+ class="cursor-pointer d-flex justify-content-between align-items-center">
112
+ <rb-text>{{rule.name}}</rb-text>
113
+ <rb-icon icon="icon-close" class="rb-remove-rule" @click="removeRule(rule)"></rb-icon>
114
+ </b-list-group-item>
115
+ <b-list-group-item @click="addRule" class="cursor-pointer">
116
+ <rb-icon :icon="iconAdd"></rb-icon>
117
+ <rb-text>Добавить правило ...</rb-text>
118
+ </b-list-group-item>
119
+ </b-list-group>
120
+ </div>
105
121
  </b-form>
122
+
123
+ <field-rule-form-modal :rule="ruleModalCfg.rule"
124
+ :form-config="formConfig"
125
+ :field="field"
126
+ :mode="ruleModalCfg.mode"
127
+ :on-after-ok="ruleModalCfg.onAfterOk"
128
+ ></field-rule-form-modal>
106
129
  </b-sidebar>
107
130
  </template>
108
131
 
109
132
  <script>
110
133
  import {UtFormConfig} from "@/utils/UtFormConfig";
134
+ import FieldRuleFormModal from "./FieldRuleFormModal";
135
+ import {v4 as uuidv4} from 'uuid';
136
+ import {UtFormConstructor} from "../utils/UtFormConstructor";
111
137
 
112
138
  export default {
113
139
  name: 'DocTemplateFieldSidebar',
140
+ components: {FieldRuleFormModal},
114
141
  props: {
115
142
  value: {
116
143
  type: Object,
@@ -119,25 +146,38 @@
119
146
  visible: {
120
147
  type: Boolean,
121
148
  default: null,
122
- }
149
+ },
150
+ formConfig: Object,
123
151
  },
124
152
  data() {
125
153
  return {
126
154
  innerVisible: null,
127
155
  field: null,
128
156
  currentInputName: null,
157
+ modalId: 'rb-field-rule-form-modal',
158
+ ruleModalCfg: {
159
+ rule: {},
160
+ mode: 'ins',
161
+ },
162
+ rulesHash: uuidv4(),
129
163
  }
130
164
  },
131
165
  computed: {
132
166
  inputOptions() {
133
- return this.field ? UtFormConfig.getInputTypes(this.field) : [];
167
+ return this.field ? UtFormConstructor.getInputTypes(this.field) : [];
134
168
  },
135
169
  iconCloseSidebar() {
136
- return UtFormConfig.config.icons.iconCloseFieldSidebar;
170
+ return UtFormConstructor.config.icons.iconCloseFieldSidebar;
137
171
  },
138
172
  iconOpenSidebar() {
139
- return UtFormConfig.config.icons.iconOpenFieldSidebar;
173
+ return UtFormConstructor.config.icons.iconOpenFieldSidebar;
174
+ },
175
+ iconAdd() {
176
+ return UtFormConstructor.config.icons.iconAdd;
140
177
  },
178
+ rules() {
179
+ return UtFormConstructor.getAvailableFieldRules(this.field);
180
+ }
141
181
  },
142
182
  watch: {
143
183
  visible() {
@@ -154,7 +194,7 @@
154
194
  this.$emit('change', this.field);
155
195
  },
156
196
  currentInputName() {
157
- this.field.input = UtFormConfig.getInputTypeByName(this.currentInputName, this.field);
197
+ this.field.input = UtFormConstructor.getInputTypeByName(this.currentInputName, this.field);
158
198
  },
159
199
  },
160
200
  methods: {
@@ -177,6 +217,45 @@
177
217
  } else {
178
218
  return {}
179
219
  }
220
+ },
221
+ addRule() {
222
+ this.ruleModalCfg = {
223
+ mode: 'ins',
224
+ rule: {
225
+ name: null,
226
+ script: null,
227
+ },
228
+ onAfterOk: (rule) => {
229
+ this.field.rules = this.field.rules ? this.field.rules : [];
230
+ this.field.rules.push({
231
+ ...rule
232
+ });
233
+ this.rulesHash = uuidv4();
234
+ }
235
+ }
236
+ this.$bvModal.show(this.modalId);
237
+ },
238
+ editRule(rule, event) {
239
+ if (event.target.classList
240
+ && event.target.classList.contains('rb-remove-rule')) {
241
+ return;
242
+ }
243
+
244
+ this.ruleModalCfg = {
245
+ mode: 'upd',
246
+ rule: {...rule},
247
+ onAfterOk: (modalRule) => {
248
+ Object.assign(rule, modalRule)
249
+ }
250
+ }
251
+ this.$bvModal.show(this.modalId);
252
+ },
253
+ removeRule(rule) {
254
+ let index = this.field.rules.findIndex(r => r.id === rule.id);
255
+ if (index >= 0) {
256
+ this.field.rules.splice(index, 1);
257
+ }
258
+ this.rulesHash = uuidv4();
180
259
  }
181
260
  },
182
261
  created() {