tpmkms_4wp 9.3.0-beta.24 → 9.3.0-beta.26

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.
@@ -13,9 +13,7 @@ const helpers = require('./helpers')
13
13
  make it friday instead
14
14
  2 sundays from now
15
15
  the sunday after july 1st
16
- remind greg to go to regina
17
16
  remind every truck driver to whatever tomorrow at 8 am
18
- remind greg and bob to go to bolivia and see the xyz corporation
19
17
  */
20
18
 
21
19
  class API {
@@ -23,6 +21,7 @@ class API {
23
21
  this._objects = objects
24
22
  this._objects.reminders = []
25
23
  this._objects.id = 0
24
+ this._objects.current = null
26
25
  }
27
26
 
28
27
  async add(reminder) {
@@ -31,13 +30,36 @@ class API {
31
30
  reminder.id = id
32
31
  this._objects.reminders.push(reminder)
33
32
  this.args.mentioned({ context: reminder })
33
+ this._objects.current = id
34
+ }
35
+
36
+ getCurrent() {
37
+ return this._objects.current
38
+ }
39
+
40
+ // addUser to current
41
+ addUser(user) {
42
+ const reminder = this._objects.reminders.find((r) => r.id == this._objects.current)
43
+ if (reminder) {
44
+ if (Array.isArray(reminder.who)) {
45
+ reminder.who = [...reminder.who, user]
46
+ } else {
47
+ reminder.who = [reminder.who, user]
48
+ }
49
+ }
50
+ }
51
+
52
+ removeUser(user) {
53
+ const reminder = this._objects.reminders.find((r) => r.id == this._objects.current)
54
+ if (reminder) {
55
+ reminder.who = reminder.who.filter((who) => who.remindee_id != user.remindee_id)
56
+ }
34
57
  }
35
58
 
36
59
  addRemindable(id, text) {
37
60
  if (!text) {
38
61
  text = id
39
62
  }
40
- debugger
41
63
  this.args.makeObject({ ...this.args, context: { word: text, value: id, number: 'one', remindee_id: id }, initial: `remindee_id: "${id}"`, types: ['remindable'] })
42
64
  }
43
65
 
@@ -46,6 +68,18 @@ class API {
46
68
  reminder.nextISODate = value?.evalue
47
69
  }
48
70
 
71
+ contextToWho(who) {
72
+ if (who.isList) {
73
+ const whos = []
74
+ for (const element of this.args.values(who)) {
75
+ whos.push(this.contextToWho(element))
76
+ }
77
+ return whos
78
+ } else {
79
+ return { id: who.value || who.text, text: who.text, remindee_id: who.remindee_id }
80
+ }
81
+ }
82
+
49
83
  // the user of the KM can override this. this can be used to sync the GUI and the LUI
50
84
  getCurrent() {
51
85
  }
@@ -89,7 +123,6 @@ class API {
89
123
  return
90
124
  }
91
125
  }
92
-
93
126
  }
94
127
  }
95
128
 
@@ -102,13 +135,38 @@ const template = {
102
135
  operators: [
103
136
  "([remindable])",
104
137
  { pattern: "([addRemindable] (word)*)", development: true },
105
- "([remind] (remindable/*) (!@<= 'dateTimeSelector')*)",
106
- "([remind:withDateBridge] (remindable/*) (!@<= 'dateTimeSelector')* (dateTimeSelector))",
107
- "([remind:withDateAndTimeBridge] (remindable/*) (!@<= 'dateTimeSelector')* (dateTimeSelector) (atTime))",
138
+ "([remind:justWhoBridge] (remindable/*))",
139
+ "([remind] (remindable/*) (!@<= 'dateTimeSelector' && !@<= 'inAddition')*)",
140
+ "([remind:withDateBridge] (remindable/*) (!@<= 'dateTimeSelector' && !@<= 'inAddition')* (dateTimeSelector))",
141
+ "([remind:withDateAndTimeBridge] (remindable/*) (!@<= 'dateTimeSelector' && !@<= 'inAddition')* (dateTimeSelector) (atTime))",
108
142
  "([show] ([reminders]))",
109
143
  "([delete_reminders|delete,cancel] (number/*))",
144
+ "([add] (remindable/*))",
145
+ "([remove] (remindable/*))",
146
+ "((verb/*) [inAddition|also,too])",
110
147
  ],
111
148
  bridges: [
149
+ {
150
+ id: 'inAddition',
151
+ after: ['verb'],
152
+ bridge: "{ ...before[0], inAddition: true, verb: before[0], operator: operator, interpolate: '${verb} ${operator}' }",
153
+ },
154
+ {
155
+ id: 'add',
156
+ isA: ['verb'],
157
+ bridge: "{ ...next(operator), arg: after[0], operator: operator, interpolate: '${operator} ${arg}' }",
158
+ semantic: ({api, context}) => {
159
+ api.addUser(api.contextToWho(context.arg))
160
+ }
161
+ },
162
+ {
163
+ id: 'remove',
164
+ isA: ['verb'],
165
+ bridge: "{ ...next(operator), arg: after[0], operator: operator, interpolate: '${operator} ${arg}' }",
166
+ semantic: ({api, context}) => {
167
+ api.removeUser(api.contextToWho(context.arg))
168
+ }
169
+ },
112
170
  {
113
171
  id: 'addRemindable',
114
172
  isA: ['verb'],
@@ -121,17 +179,27 @@ const template = {
121
179
  },
122
180
  {
123
181
  id: 'remindable',
182
+ isA: ['listable'],
124
183
  },
125
184
  {
126
185
  id: 'remind',
127
186
  isA: ['verb'],
128
187
  localHierarchy: [['self', 'remindable']],
129
188
  bridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], interpolate: '${operator} ${who} ${reminder}' }",
189
+ justWhoBridge: "{ ...next(operator), operator: operator, who: after[0], interpolate: '${operator} ${who}' }",
130
190
  withDateBridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], date: after[2], interpolate: '${operator} ${who} ${reminder} ${date}' }",
131
191
  withDateAndTimeBridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], date: after[2], time: after[3], interpolate: '${operator} ${who} ${reminder} ${date} ${time}' }",
192
+ semantics: [
193
+ {
194
+ match: ({context}) => context.marker == 'remind' && context.inAddition,
195
+ apply: ({context, api}) => {
196
+ api.addUser(api.contextToWho(context.who))
197
+ }
198
+ },
199
+ ],
132
200
  semantic: async ({api, gsp, gp, context}) => {
133
201
  const text = await gsp(context.reminder.slice(1));
134
- const who = { id: context.who.value || context.who.text, text: context.who.text, remindee_id: context.who.remindee_id }
202
+ const who = api.contextToWho(context.who)
135
203
  const reminder = { text, dateTimeSelector: context.date, who }
136
204
  if (context.date) {
137
205
  reminder.dateTimeSelector = context.date