ep_data_tables 0.0.95 → 0.0.97

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.
@@ -4,88 +4,62 @@
4
4
  const settings = require('ep_etherpad-lite/node/utils/Settings');
5
5
  if (!settings.toolbar) settings.toolbar = {};
6
6
 
7
- // Using console.log for server-side logging, similar to other Etherpad server-side files.
8
7
  const log = (...m) => console.log('[ep_data_tables:collectContentPre_SERVER]', ...m);
9
8
 
10
- // Base64 decoding function (copied from tableImport.js / client_hooks.js for server-side use)
11
- // Ensure it can handle the URL-safe variant if that's what tableImport.js produces.
9
+ // Base64 decoding function for URL-safe variant
12
10
  const dec = (s) => {
13
- const str = s.replace(/-/g, '+').replace(/_/g, '/');
14
- try {
15
- // Assuming Buffer is available in the Node.js environment where this server hook runs
16
- return Buffer.from(str, 'base64').toString('utf8');
17
- } catch (e) {
18
- log('ERROR decoding base64 string in server-side collectContentPre:', s, e);
19
- return null;
20
- }
11
+ const str = s.replace(/-/g, '+').replace(/_/g, '/');
12
+ try {
13
+ return Buffer.from(str, 'base64').toString('utf8');
14
+ } catch (e) {
15
+ log('ERROR decoding base64:', s, e);
16
+ return null;
17
+ }
21
18
  };
22
19
 
20
+ /**
21
+ * Server-side collectContentPre hook for import/export operations.
22
+ * Processes tbljson-* CSS classes to reapply table metadata attributes.
23
+ *
24
+ * Context parameters provided by Etherpad:
25
+ * - cc: Content collector object with doAttrib() method
26
+ * - state: Current collection state
27
+ * - tname: Tag name (may be undefined)
28
+ * - styl: Style attribute
29
+ * - cls: Class attribute string
30
+ *
31
+ * Note: context.node is NOT provided by Etherpad's collectContentPre hook.
32
+ */
23
33
  exports.collectContentPre = (hookName, context) => {
24
-
25
- const node = context.node;
26
- const tname = node?.tagName?.toLowerCase(); // Keep for logging, but don't rely on it for main logic
27
34
  const cls = context.cls;
28
35
  const state = context.state;
29
36
 
30
- // Detailed logging for every node encountered by this hook
31
- let nodeRepresentation = '';
32
- if (node) {
33
- if (node.nodeType === 1 /* Node.ELEMENT_NODE */) {
34
- nodeRepresentation = node.outerHTML ? node.outerHTML.substring(0, 300) : `ElementType: ${tname}`;
35
- } else if (node.nodeType === 3 /* Node.TEXT_NODE */) {
36
- nodeRepresentation = `TextNode: "${(node.nodeValue || '').substring(0, 100)}"`;
37
- }
38
- }
39
- log(`PROCESSING Node: ${nodeRepresentation}, TagName: ${tname}, Classes: "${cls || ''}", Current state.attribString: "${state.attribString || ''}"`);
40
-
41
- // MODIFIED CONDITION: Rely primarily on context.cls to find our target class,
42
- // as context.node and context.tname seem unreliable for our spans.
43
- if (!cls) {
44
- // log('No classes, returning.');
45
- return;
46
- }
37
+ if (!cls) return;
47
38
 
39
+ // Find tbljson-* class
48
40
  const classes = cls.split(' ');
49
41
  let encodedJsonMetadata = null;
50
- let isTblJsonSpan = false;
51
42
 
52
43
  for (const c of classes) {
53
44
  if (c.startsWith('tbljson-')) {
54
45
  encodedJsonMetadata = c.substring(8);
55
- isTblJsonSpan = true;
56
46
  break;
57
47
  }
58
48
  }
59
49
 
60
- if (isTblJsonSpan && encodedJsonMetadata) {
61
- // Added a check for tname === 'span' here for sanity, though cls is primary trigger
62
- log(`FOUND potential tbljson span based on class. Actual tname: ${tname}. Encoded: ${encodedJsonMetadata.substring(0, 20)}...`);
63
- let decodedJsonString;
64
- try {
65
- decodedJsonString = dec(encodedJsonMetadata);
66
- if (!decodedJsonString) {
67
- throw new Error('Decoded JSON string is null or empty.');
68
- }
69
- log(`DECODED metadata: ${decodedJsonString.substring(0, 50)}...`);
70
- } catch (e) {
71
- log('ERROR decoding/validating metadata from class:', encodedJsonMetadata, e);
50
+ if (!encodedJsonMetadata) return;
51
+
52
+ // Decode and apply the table metadata attribute
53
+ try {
54
+ const decodedJsonString = dec(encodedJsonMetadata);
55
+ if (!decodedJsonString) {
56
+ log('ERROR: Decoded JSON string is null or empty');
72
57
  return;
73
58
  }
74
59
 
75
60
  const attribToApply = `tbljson::${decodedJsonString}`;
76
- log(`PREPARED attribToApply: "${attribToApply.substring(0, 70)}..."`);
77
-
78
- log('BEFORE cc.doAttrib - state.attribs:', JSON.stringify(state.attribs));
79
- log('BEFORE cc.doAttrib - state.attribString:', state.attribString);
80
- try {
81
- context.cc.doAttrib(state, attribToApply);
82
- log('AFTER cc.doAttrib - state.attribs:', JSON.stringify(state.attribs));
83
- log('AFTER cc.doAttrib - state.attribString:', state.attribString);
84
- log('SUCCESSFULLY CALLED cc.doAttrib.');
85
- } catch (e) {
86
- log('ERROR calling cc.doAttrib:', e);
87
- }
88
- } else if (cls.includes('tbljson-')) {
89
- log(`WARN: A class string "${cls}" includes 'tbljson-' but didn't parse as expected, or encodedJsonMetadata was null.`);
61
+ context.cc.doAttrib(state, attribToApply);
62
+ } catch (e) {
63
+ log('ERROR applying tbljson attribute:', e);
90
64
  }
91
- };
65
+ };
package/ep.json CHANGED
@@ -6,19 +6,17 @@
6
6
  "eejsBlock_styles" : "ep_data_tables/static/js/index:eejsBlock_styles",
7
7
  "eejsBlock_scripts" : "ep_data_tables/static/js/index:eejsBlock_scripts",
8
8
  "eejsBlock_editbarMenuLeft" : "ep_data_tables/static/js/index:eejsBlock_editbarMenuLeft",
9
- "collectContentPre" : "ep_data_tables/collectContentPre:collectContentPre"
9
+ "collectContentPre" : "ep_data_tables/collectContentPre:collectContentPre"
10
10
  },
11
11
  "client_hooks": {
12
- "collectContentPre" : "ep_data_tables/static/js/client_hooks:collectContentPre",
12
+ "collectContentPre" : "ep_data_tables/static/js/client_hooks:collectContentPre",
13
+ "collectContentLineText" : "ep_data_tables/static/js/client_hooks:collectContentLineText",
13
14
  "aceKeyEvent" : "ep_data_tables/static/js/client_hooks:aceKeyEvent",
14
- "aceStartLineAndCharForPoint" : "ep_data_tables/static/js/client_hooks:aceStartLineAndCharForPoint",
15
- "aceEndLineAndCharForPoint" : "ep_data_tables/static/js/client_hooks:aceEndLineAndCharForPoint",
16
15
  "aceAttribsToClasses" : "ep_data_tables/static/js/client_hooks:aceAttribsToClasses",
17
- "acePostWriteDomLineHTML" : "ep_data_tables/static/js/client_hooks:acePostWriteDomLineHTML",
16
+ "acePostWriteDomLineHTML" : "ep_data_tables/static/js/client_hooks:acePostWriteDomLineHTML",
18
17
  "aceInitialized" : "ep_data_tables/static/js/client_hooks:aceInitialized",
19
- "aceSetAuthorStyle" : "ep_data_tables/static/js/client_hooks:aceSetAuthorStyle",
20
18
  "aceEditorCSS" : "ep_data_tables/static/js/client_hooks:aceEditorCSS",
21
- "postAceInit" : "ep_data_tables/static/js/initialisation:postAceInit"
19
+ "postAceInit" : "ep_data_tables/static/js/initialisation:postAceInit"
22
20
  }
23
21
  }
24
22
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ep_data_tables",
3
- "version": "0.0.95",
3
+ "version": "0.0.97",
4
4
  "description": "BETA - etherpad tables plugin, compatible with other character/line based styling and other features",
5
5
  "author": {
6
6
  "name": "DCastelone",