ekms 8.9.0-beta.1 → 8.9.0-beta.11

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/common/wp.js CHANGED
@@ -3,28 +3,95 @@ const { defaultContextCheck } = require('./helpers')
3
3
  const helpers = require("./helpers")
4
4
  const ui = require("./ui")
5
5
  const countable = require("./countable")
6
+ const colors = require("./colors")
7
+ const errors = require("./errors")
6
8
  const wp_tests = require('./wp.test.json')
7
9
  const instance = require('./wp.instance.json')
8
10
 
11
+ /*
12
+ start inserting text until I say banana
13
+ ...
14
+ or
15
+ stop inserting text
16
+
17
+ make the text of the 1st to 3rd paragraphs blue
18
+
19
+
20
+ make every word bold and underlines and blue -> weirdly "bold underlined and blue" works
21
+ */
22
+
23
+ class API {
24
+ initialize({ objects }) {
25
+ this._objects = objects
26
+ }
27
+
28
+ changeState(value) {
29
+ this._objects.changeState = value
30
+ }
31
+ }
32
+
33
+ const api = new API()
34
+
9
35
  let config = {
10
36
  name: 'wp',
11
- operators: [
12
- ],
13
- bridges: [
14
- ]
15
37
  };
16
38
 
17
39
  template = {
18
40
  configs: [
19
- 'words are countable',
41
+ 'setidsuffix _wp',
42
+ 'words are countable and statefulElements',
20
43
  'characters are countable',
21
44
  'paragraphs are countable',
22
- ],
45
+ 'bold, italic and underlined are styles',
46
+ "resetIdSuffix",
47
+ {
48
+ operators: [
49
+ // TODO write a parser for this so I can use statefulElement as the id
50
+ "([changeState_wp|make] ([statefulElement_wp]) ([stateValue_wp|]))",
51
+ ],
52
+ bridges: [
53
+ {
54
+ id: 'changeState_wp',
55
+ parents: ['verb'],
56
+ bridge: "{ ...next(operator), element: after[0], state: after[1], operator: operator, generate: ['operator', 'element', 'state'] }",
57
+ localHierarchy: [
58
+ ['thisitthat', 'statefulElement'],
59
+ ],
60
+ semantic: ({api, isA, context, toArray}) => {
61
+ const unit = context.element.marker
62
+ const scope = context.element.quantity.quantity
63
+ let color;
64
+ const styles = []
65
+ const update = { unit, scope }
66
+ for (const state of toArray(context.state)) {
67
+ if (isA(state, 'style_wp')) {
68
+ if (!update.styles) {
69
+ update.styles = []
70
+ }
71
+ update.styles.push(state.value.split('_')[0])
72
+ } else {
73
+ update.color = state.value.split('_')[0]
74
+ }
75
+ }
76
+ api.changeState(update)
77
+ }
78
+ },
79
+ {
80
+ id: 'stateValue_wp',
81
+ children: ['color_colors', 'style_wp'],
82
+ },
83
+ ],
84
+ priorities: [
85
+ { "context": [['changeState_wp',0], ['statefulElement_wp', 0], ['list', 0]], ordered: true, choose: [0] },
86
+ ],
87
+ },
88
+ ]
23
89
  }
24
90
 
25
91
  knowledgeModule({
26
92
  config,
27
- includes: [ui, countable],
93
+ includes: [ui, countable, colors, errors],
94
+ api: () => new API(),
28
95
 
29
96
  module,
30
97
  description: 'Word processor',
@@ -35,7 +102,10 @@ knowledgeModule({
35
102
  context: [
36
103
  ...defaultContextCheck(),
37
104
  ],
38
- objects: [{ km: 'ui' }],
105
+ objects: [
106
+ 'changeState',
107
+ { km: 'ui' },
108
+ ],
39
109
  },
40
110
  },
41
111
  template: {